腾讯云centos7搭建javaweb服务器(本人亲自经历,详细)
首先聲明,這是本人親自搭建成功的經歷,親測有效,****(此處和諧)網上好多在云服務器上搭建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初始界面了!
也可以將tomcat修改為默認的80端口,即只需要:
[root@VM_77_172_centos ~]# cd /usr/tomcat/conf/
[root@VM_77_172_centos conf]# vim server.xml
將<Connector port="8080" protocol="HTTP/1.1"
? ? ? ? ? ? ? ?connectionTimeout="20000"
? ? ? ? ? ? ? ?redirectPort="8443" />
修改為:<Connector port="80" protocol="HTTP/1.1"
? ? ? ? ? ? ? ?connectionTimeout="20000"
? ? ? ? ? ? ? ?redirectPort="8443" />
保存即可。
重啟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也安裝完畢!
享受沒有配置錯誤的流程吧!
總結
以上是生活随笔為你收集整理的腾讯云centos7搭建javaweb服务器(本人亲自经历,详细)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有关子数组最大累加和的算法小结
- 下一篇: 有关子矩阵最大累加和的总结