Centos7搭建javaweb服务器,centos7搭建javaweb
Centos7搭建javaweb服务器,centos7搭建javaweb
转载自:https://www.2cto.com/kf/201707/654874.html
先安装java:
[root@VM_77_172_centos usr]# cd java
[root@VM_77_172_centos java]# tar -xvzfjdk-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 -xvzfapache-tomcat-8.5.16.tar.gz
[root@VM_77_172_centos usr]# rm -rapache-tomcat-8.5.16.tar.gz
rm: remove regular file ’apache-tomcat-8.5.16.tar.gz'? y
[root@VM_77_172_centos usr]#mvapache-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 https://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也安装完毕!
相关文章
- 暂无相关文章
用户点评