首先声明,这是本人亲自搭建成功的经历,亲测有效,****(此处和谐)网上好多在云服务器上搭建javaweb的教程,好多都是各种抄的或者若干年之前的,真的是被坑惨了!废话不多说,下面直接上干货!步骤很详细,不出意外的话,应该能完美搭建成功!我真的痛恨假教程!!!
首先,为了保险起见,直接在腾讯云官网上登录云服务器管理网页,重装系统(如有什么需要保存的重要文件请提前备份)在此,本人重装的是最新的centos7.3,如图
若干秒之后,重装完毕,即可开始搭建环境!
去官网下载jdk和tomcat的压缩包,本着团结友爱奉献的精神……咳咳,在此贴上下载页面的链接,毕竟下载链接很快就会过时
jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
我下载的是tar包,Linux x64 jdk-8u131-linux-x64.tar.gz
Tomcat: http://tomcat.apache.org/download-90.cgi
我下载的是apache-tomcat-8.5.16.tar.gz
恩,下载好之后,
用户可以使用putty,mac用户可以使用ssh连接到服务器
使用root用户输入密码之后即可登录服务器
依次执行:
[root@VM_77_172_centos usr]# cd /usr
[root@VM_77_172_centos usr]# mkdir java
本人使用的是filezilla软件分别将下载好的jdk和Tomcat包上传到服务器中的/usr/java目录下和/usr目录下。(注意)
先安装java:
[root@VM_77_172_centos usr]# cd java
[root@VM_77_172_centos java]# tar -xvzf jdk-8u131-linux-x64.tar.gz
[root@VM_77_172_centos java]# ls
jdk1.8.0_131 jdk-8u131-linux-x64.tar.gz
[root@VM_77_172_centos java]# vim /etc/profile
单击i可进行插入,在文末插入如下三行语句:
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=/$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
单击esc之后输入:x保存并退出
[root@VM_77_172_centos java]# source /etc/profile
此时,java安装完毕,可输入java -version查看:
[root@VM_77_172_centos java]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
下面开始Tomcat安装:
[root@VM_77_172_centos java]# cd ..
(注意,之前已经将tomcat包上传到/usr目录下)
[root@VM_77_172_centos usr]# tar -xvzf apache-tomcat-8.5.16.tar.gz
[root@VM_77_172_centos usr]# rm -r apache-tomcat-8.5.16.tar.gz
rm: remove regular file ’apache-tomcat-8.5.16.tar.gz'? y
[root@VM_77_172_centos usr]#mv apache-tomcat-8.5.16 tomcat
[root@VM_77_172_centos usr]# ls
bin games java lib64 local share tmp
etc include lib libexec sbin src tomcat
[root@VM_77_172_centos tomcat]# /usr/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/tomcat
Using CATALINA_HOME: /usr/tomcat
Using CATALINA_TMPDIR: /usr/tomcat/temp
Using JRE_HOME: //usr/java/jdk1.8.0_131/jre
Using CLASSPATH: /usr/tomcat/bin/bootstrap.jar:/usr/tomcat/bin/tomcat-juli.jar
Tomcat started.
此时,tomcat安装完毕,接下来打开端口:
[root@VM_77_172_centos tomcat]# systemctl stop firewalld.service
[root@VM_77_172_centos tomcat]# systemctl disable firewalld.service
[root@VM_77_172_centos tomcat]# systemctl mask firewalld.service
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@VM_77_172_centos tomcat]# cd ~
[root@VM_77_172_centos ~]# yum install iptables-services -y
[root@VM_77_172_centos ~]# systemctl enable iptables
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@VM_77_172_centos ~]# systemctl start iptables
[root@VM_77_172_centos ~]# systemctl status iptables
[root@VM_77_172_centos usr]# systemctl unmask firewalld
Removed symlink /etc/systemd/system/firewalld.service.
[root@VM_77_172_centos usr]# systemctl start firewalld
[root@VM_77_172_centos usr]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@VM_77_172_centos usr]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@VM_77_172_centos usr]# firewall-cmd --zone=public --add-port=22/tcp --permanent
success
[root@VM_77_172_centos usr]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@VM_77_172_centos usr]# firewall-cmd --reload
success
至此,不出意外的话,就可以外网访问服务器ip:8080看到Tomcat初始界面了!
接下来,安装mysql:
[root@VM_77_172_centos usr]# cd ~
[root@VM_77_172_centos ~]# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
[root@VM_77_172_centos ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm
[root@VM_77_172_centos ~]# yum install mysql-server
中间输入若干次y
[root@VM_77_172_centos ~]# yum install mysql-devel
中间输入若干次y
[root@VM_77_172_centos ~]# yum install mysql
检查一下MySQL:
[root@VM_77_172_centos ~]# rpm -qa|grep -i mysql
mysql-community-libs-5.7.18-1.el7.x86_64
mysql-community-libs-compat-5.7.18-1.el7.x86_64
mysql57-community-release-el7-7.noarch
mysql-community-common-5.7.18-1.el7.x86_64
mysql-community-client-5.7.18-1.el7.x86_64
mysql-community-server-5.7.18-1.el7.x86_64
mysql-community-devel-5.7.18-1.el7.x86_64
[root@VM_77_172_centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@VM_77_172_centos ~]# vim /etc/my.cnf
添加一条语句:skip-grant-tables
保存退出
[root@VM_77_172_centos ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@VM_77_172_centos ~]# mysql -u root
即可进入mysql
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
[root@VM_77_172_centos ~]# vim /etc/my.cnf
删除掉刚才添加的那条语句,保存退出。
[root@VM_77_172_centos ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@VM_77_172_centos ~]# mysql -uroot -p
输入密码登录MySQL
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
mysql> set PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
至此,MySQL也安装完毕!
享受没有配置错误的流程吧!