安裝了一晚上的阿里云服務(wù)器慷嗜,錯誤滿滿淀弹,最終還是搭建成功了。
搭建服務(wù)器庆械,要先購買一個服務(wù)器薇溃,可以買阿里云、騰訊云等服務(wù)器供應(yīng)商缭乘。我是阿里云做活動沐序,99塊錢買的,感覺很值了堕绩。
首先安裝Jdk和Tomcat策幼,直接去官網(wǎng)下載需要的版本,也可以點擊鏈接下載逛尚。 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 鏈接: https://pan.baidu.com/s/1IazjVB5c_HAy2Quowy-HHA 密碼: kr69
鏈接里有SSHSecureShellClient-3.2.9客戶端垄惧,我是用這個的,自己可以選擇其他的遠程連接工具绰寞。
安裝完SSHSecureShellClient-3.2.9到逊,可以看到
創(chuàng)建soft文件夾,把軟件包拖拽滤钱,直接上傳到linus的soft文件夾中
1.安裝JDK
查看當(dāng)前Linux系統(tǒng)是否已經(jīng)安裝java
(1)[root@CentOS?~]# rpm -qa | grep java
(2)[root@CentOS?~]# rpm -e --nodeps 要卸載的軟件名
新買的服務(wù)器前兩步基本不用執(zhí)行
(3)解壓jdk到/usr/local下
[root@CentOS?soft]#?tar –xvf jdk-7u71-linux-i586.tar.gz –C /usr/local
(4)配置jdk環(huán)境變量觉壶,打開/etc/profile配置文件,將下面配置拷貝進去
#set java environment
JAVA_HOME=/usr/local/jdk1.7.0_71
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH?
(5)重新加載/etc/profile配置文件source /etc/profile
(6)[root@CentOS?local]# java -version ? ?可以查看java的版本
2.安裝tomcat
(1)直接解壓tomcat
[root@CentOS?~]# tar -xvf apache-tomcat-7.0.57.tar -C /usr/local
[root@CentOS?~]# cd /usr/local/
[root@CentOS?local]# mv?apache-tomcat-7.0.57 tomcat(改文件夾名字)
[root@CentOS?local]# tomcat/
[root@CentOS?tomcat]# bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.7.0_71
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
(2)此時件缸,tomcat安裝完畢铜靶,接下來打開端口:
[root@CentOS tomcat]# systemctl stop firewalld.service(關(guān)閉firewalld服務(wù))
[root@CentOS tomcat]# systemctl disable firewalld.service(在開機時禁用firewalld服務(wù))
[root@CentOS tomcat]# systemctl mask firewalld.service(屏蔽服務(wù)(讓它不能啟動))
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@CentOS tomcat]# cd ~
[root@CentOS ~]# yum install iptables-services -y(安裝 iptables-services?)
[root@CentOS ~]# systemctl enable iptables(在開機時啟用firewalld服務(wù))
Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
[root@CentOS ~]# systemctl start iptables(啟動?iptables服務(wù))
[root@CentOS ~]# systemctl status iptables(顯示?iptables的狀態(tài))
[root@CentOS usr]# systemctl unmask firewalld
Removed symlink /etc/systemd/system/firewalld.service.
[root@CentOS usr]# systemctl start firewalld
[root@CentOS usr]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@CentOS usr]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@CentOS usr]# firewall-cmd --zone=public --add-port=22/tcp --permanent
success
[root@CentOS usr]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
(打開需要的端口)
[root@CentOS usr]# firewall-cmd --reload ? ? ? ? ?(重新載入)
success
現(xiàn)在應(yīng)該可以外網(wǎng)訪問服務(wù)器ip:8080看到Tomcat初始界面了!
3.安裝mysql
(1)CentOS7的yum源沒有mysql,要先下載mysql的repo源
[root@CentOS ~]# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
(2)安裝mysql rpm包
[root@CentOS ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm
(我安裝時提示需要依賴包他炊,如libncurses.so.5 is needed by MySQL-client-5.6.22-1.el6.i686
[root@CentOS?~]#yum install ?libncurses.so.5?
缺什么依賴包争剿,安裝就行)
(3)安裝mysql
[root@CentOS ~]# yum install mysql-server?
中間輸入若干次y
[root@CentOS ~]# yum install mysql-devel
中間輸入若干次y
[root@CentOS ~]# yum install mysql
(4)檢查一下MySQL:
[root@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
(5)[root@CentOS ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
(6)[root@CentOS ~]# vim /etc/my.cnf ? ? ? ?(mysql的啟動參數(shù))
添加一條語句:skip-grant-tables ? ? ? ? (不使用mysql數(shù)據(jù)庫里的信息來進行訪問控制)
保存退出
(7)[root@CentOS ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
(8)[root@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'; ? ? ? ? ? (更改mysql密碼)
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
(9)[root@CentOS ~]# vim /etc/my.cnf
刪除掉剛才添加的那條語句,保存退出痊末。
[root@CentOS ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@CentOS ~]# mysql -uroot -p
輸入密碼登錄MySQL
mysql> set global validate_password_policy=0;(修改對應(yīng)的密碼策略)
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=6;(但是密碼也至少為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;(mysql 新設(shè)置用戶或更改密碼后需用flush privileges刷新MySQL的系統(tǒng)權(quán)限相關(guān)表蚕苇,否則會出現(xiàn)拒絕訪問,還有一種方法凿叠,就是重新啟動mysql服務(wù)器涩笤,來使新設(shè)置生效。-)
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'; (把已存在的用戶(例如root)修改成允許遠程主機訪問(不增加記錄)盒件,需要指定訪問主機蹬碧,可以把%替換為主機的IP或者主機名)
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
4.修改tomcat的默認(rèn)端口
[root@CentOS?~]# cd /usr/local/tomcat/conf
[root@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" />
可以從文件底部開始找這個標(biāo)簽<Host></Host>,在該標(biāo)簽內(nèi)添加 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?<Context path="" docBase="/Gulang" /> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??docBase屬性填寫你的項目位置炒刁,一般項目路徑為 .../webapps/Gulang恩沽。
重啟tomcat
現(xiàn)在你可以統(tǒng)過外網(wǎng)IP直接訪問了。