Centos 7 JDK、Tomcat9 安裝並配置
2017年04月17日 22:44:36 我是一座離島 閱讀數:5707更多
版權聲明:博主原創文章,轉載請註明出處。 https://blog.csdn.net/ngl272/article/details/70217100
一、JDK 安裝
1.安裝wget
yum -y install wget
- 1
2.下載,輸入指令
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm
- 1
3.執行npm安裝包,等待安裝完成
rpm -ivh jdk-8u112-linux-x64.rpm
- 1
4.驗證安裝是否成功
-
//輸入指令
-
java -version
-
//輸出版本
-
java version "1.8.0_112"
-
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
-
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
- 1
- 2
- 3
- 4
- 5
- 6
二、Tomcat 安裝
1.下載,切換至任意目錄執行
wget http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M18/bin/apache-tomcat-9.0.0.M18.tar.gz
- 1
2.解壓 ,執行以下命令
tar -zxvf apache-tomcat-9.0.0.M18.tar.gz
- 1
3.移動至想放置的目錄
mv apache-tomcat-9.0.0.M18 /usr/local/
- 1
4.配置自啓動,切換至Tomcat的bin目錄執行vi setenv.sh,並按i進入編輯模式,拷貝以下代碼粘貼
-
#add tomcat pid
-
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
-
#add java opts
-
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
- 1
- 2
- 3
- 4
之後按esc鍵,在按shift+:(左下角出現會出現“:”),然後輸入wq保存退出,最後執行 chmod +x setenv.sh,確保文件setenv.sh可執行。
5.配置service 執行cd /usr/lib/systemd/system切換至目錄 並執行vi tomcat.service(也可以直接vi /usr/lib/systemd/system/tomcat.service),拷貝以下代碼粘貼(注意將第6和7行的Tomcat路徑/usr/local/apache-tomcat-9.0.0.M18 換成你自己的Tomcat的絕對路徑)
-
[Unit]
-
Description=Tomcat
-
After=syslog.target network.target remote-fs.target nss-lookup.target
-
[Service]
-
Type=forking
-
PIDFile=/usr/local/apache-tomcat-9.0.0.M18/tomcat.pid
-
ExecStart=/usr/local/apache-tomcat-9.0.0.M18/bin/startup.sh
-
ExecReload=/bin/kill -s HUP $MAINPID
-
ExecStop=/bin/kill -s QUIT $MAINPID
-
PrivateTmp=true
-
[Install]
-
WantedBy=multi-user.target
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
之後按esc鍵,在按shift+:(左下角出現會出現“:”),然後輸入wq保存退出。執行以下指令將tomcat.service添加開機至開機啓動
-
//配置開機啓動
-
systemctl enable tomcat
-
//啓動tomcat
-
systemctl start tomcat
-
//停止tomcat
-
systemctl stop tomcat
-
//重啓tomcat
-
systemctl restart tomcat
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
配置完成,建議重啓服務器,即輸入命令 reboot(或者sudo reboot)即可在瀏覽器裏輸入你的服務器地址+8080端口(例如:192.168.1.161:8080),如果看到小貓咪表示成功,否則請檢查以上所有步驟是否全都執行正確了。
6.修改端口,切換至Tomcat conf目錄
-
cd /usr/local/apache-tomcat-9.0.0.M18/conf
-
//輸入指令打開文件
-
vi server.xml
-
//輸入 /8080 並回車搜索8080 字符串,找到如下兩處地方
-
<<Connector port="8080" protocol="HTTP/1.1"
-
connectionTimeout="20000"
-
redirectPort="8443" />
-
<!-- A "Connector" using the shared thread pool-->
-
<!--
-
<Connector executor="tomcatThreadPool"
-
port="8080" protocol="HTTP/1.1"
-
connectionTimeout="20000"
-
redirectPort="8443" />
-
//按“i”進入編輯模式,將port="8080"改成port="80"
-
<Connector port="80" protocol="HTTP/1.1"
-
connectionTimeout="20000"
-
redirectPort="8443" />
-
<!-- A "Connector" using the shared thread pool-->
-
<!--
-
<Connector executor="tomcatThreadPool"
-
port="80" protocol="HTTP/1.1"
-
connectionTimeout="20000"
-
redirectPort="8443" />
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
之後按esc鍵,在按shift+:(左下角出現會出現“:”),然後輸入wq保存退出。
7.配置gui-manager項目部署方式,切換至Tomcat conf目錄,輸入vi tomcat-users.xml打開文件,按“i”進入編輯模式,拷貝以下代碼放置</tomcat-users>標籤之間(注意將password和username換成你自己的)
-
<role rolename="manager"/>
-
<role rolename="admin"/>
-
<role rolename="admin-gui"/>
-
<role rolename="manager-gui"/>
-
<user username="xxx" password="***" roles="admin-gui,manager-gui"/>
- 1
- 2
- 3
- 4
- 5
之後按esc鍵,在按shift+:(左下角出現會出現“:”),然後輸入wq保存退出。
輸入 cd webapps/manager/META-INF/ 切換至目錄,輸入vi context.xml打開文件,按i進入編輯模式,將</Context> 標籤下的<Valve> 標籤註釋掉
-
<Context antiResourceLocking="false" privileged="true" >
-
<!--註釋掉此標籤
-
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
-
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-
-->
-
</Context>
- 1
- 2
- 3
- 4
- 5
- 6
之後按esc鍵,在按shift+:(左下角出現會出現“:”),然後輸入wq保存退出。
8.重啓Tomcat
systemctl restart tomcat
- 1
瀏覽器中直接輸入你的服務器地址,例如192.168.1.161(不用輸端口號了),看見小貓咪,點擊manager 輸入賬號密碼即可部署你的項目了。
參考:
http://blog.csdn.net/zzpzheng/article/details/48864129
http://blog.csdn.net/guochunyang/article/details/51820066
http://stackoverflow.com/questions/10268583/downloading-java-jdk-on-linux-via-wget-is-shown-license-page-instead