赞
踩
声明:本文章默认未装过jdk,Tomcat以及环境变量的配置
Tomcat支持jdk版本图(注意不要混淆着其他版本使用)
1.下载jdk8安装包 wget --no-check-certificate --no-cookies --header "Cookie:oraclelicense=accept-securebackup-cookie" 避免用户验证
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz
2.解压安装包
tar -zvxf jdk-8u191-linux-x64.tar.gz
3.将解压文件放到 usr/local/webserver/下
mv jdk1.8.0_191/ /usr/local/webserver/
4.编辑配置文件,添加环境变量
vi /etc/profile
在文本最后一行添加以下内容并保存退出:
注意:/usr/local/webserver/jdk1.8.0_191为jdk解压包所在位置
#java environment
export JAVA_HOME=/usr/local/webserver/jdk1.8.0_191
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
5.让刚刚设置的环境变量生效
source /etc/profile
6.检查配置是否成功
java -version
以下提示说明配置成功:
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
1.下载Tomcat9安装包
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.14/bin/apache-tomcat-9.0.14.tar.gz
2.解压安装包
tar -zvxf apache-tomcat-9.0.14.tar.gz
3.将解压文件放到 usr/local/webserver/下
mv apache-tomcat-9.0.14 /usr/local/webserver/
4.编辑配置文件,添加环境变量
vi /etc/profile
在行尾添加以下内容并保存退出:
# tomcat9 config start - 2019-01-15
CATALINA_HOME=/usr/local/webserver/apache-tomcat-9.0.14
CATALINA_BASE=/usr/local/webserver/apache-tomcat-9.0.14
PATH=$PATH:$CATALINA_BASE/bin
export PATH CATALINA_BASE
# tomcat9 config end - 2019-01-15
5.配置端口号及编码格式
a.进入Tomcat的conf目录
cd /usr/local/webserver/apache-tomcat-9.0.14/conf/
b.打开server.xml
vi server.xml
c.端口号范围在1-65535,可以根据自己需要修改端口号
找到:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
这里我修改port为:10001;编码格式:URIEncoding="UTF-8"
<Connector port="10001" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
保存退出。
d.防火墙开启10001端口号访问
firewall-cmd --zone=public --add-port=10001/tcp --permanent
e.更新防火墙规则
firewall-cmd --reload
f.查看防火墙开启的端口号:
firewall-cmd --list-ports
6.增加manager-gui图形化管理界面权限
vi tomcat-users.xml
在 </tomcat-users> 标签前加入如下代码,这里设置了用户名root,密码root:
<user username="root" password="root" roles="manager-gui"/>
7.配置Tomcat9所需要jdk
a.进入tomcat bin目录
cd /usr/local/webserver/apache-tomcat-9.0.14/bin/
b.打开catalina.sh
vi catalina.sh
c.添加jdk路径
在 # OS specific support. 前面加入如下代码并保存退出:
JAVA_HOME=/usr/local/webserver/jdk1.8.0_191
JRE_HOME=$JAVA_HOME/jre
8.启动Tomcat9服务
./startup.sh
如下提示启动成功:
Using CATALINA_BASE: /usr/local/webserver/apache-tomcat-9.0.14
Using CATALINA_HOME: /usr/local/webserver/apache-tomcat-9.0.14
Using CATALINA_TMPDIR: /usr/local/webserver/apache-tomcat-9.0.14/temp
Using JRE_HOME: /usr/local/webserver/jdk1.8.0_191/jre
Using CLASSPATH: /usr/local/webserver/apache-tomcat-9.0.14/bin/bootstrap.jar:/usr/local/webserver/apache-tomcat-9.0.14/bin/tomcat-juli.jar
Tomcat started.
9.关闭Tomcat9
./shutdown.sh
如下提示表名关闭成功:
Using CATALINA_BASE: /usr/local/webserver/apache-tomcat-9.0.14
Using CATALINA_HOME: /usr/local/webserver/apache-tomcat-9.0.14
Using CATALINA_TMPDIR: /usr/local/webserver/apache-tomcat-9.0.14/temp
Using JRE_HOME: /usr/local/webserver/jdk1.8.0_191/jre
Using CLASSPATH: /usr/local/webserver/apache-tomcat-9.0.14/bin/bootstrap.jar:/usr/local/webserver/apache-tomcat-9.0.14/bin/tomcat-juli.jar
注意:多次使用 ./shutdown.sh 会有如下错误
一月 15, 2019 3:12:14 下午 org.apache.catalina.startup.Catalina stopServer
严重: Could not contact [localhost:8005] (base port [8005] and offset [0]). Tomcat may not be running.
一月 15, 2019 3:12:15 下午 org.apache.catalina.startup.Catalina stopServer
严重: Error stopping Catalina
java.net.ConnectException: 拒绝连接 (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
10.将Tomcat9加入到服务器列表
a.进入 init.d 目录
cd /etc/init.d
b.创建Tomcat9服务配置文件
touch tomcat9
c.打开tomcat9配置文件
vi tomcat9
添加以下内容保存退出:
#tomcat config start - 2019-01-15
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat9
# chkconfig: 2345 20 80
JAVA_HOME=/usr/local/webserver/jdk1.8.0_191/
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/local/webserver/apache-tomcat-9.0.14/
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
#chmod 755 tomcat
#chkconfig --add tomcat
#chkconfig --level 2345 tomcat on
#chkconfig --list tomcat
# tomcat config end - 2019-01-15
d.给tomcat9添加可执行权限
chmod +x tomcat9
e.将 tomcat9 纳入到系统的服务列表中,即添加 tomcat9 为系统服务:
chkconfig --add tomcat9
d.查看服务列表是否有tomcat9
chkconfig --list
如下说明添加成功:tomcat9 0:关 1:关 2:开 3:开 4:开 5:开 6:关
f.tomcat开机自启:
1.进入/lib/systemd/system/
cd /lib/systemd/system/
2.创建tomcat.service
touch tomcat.service
3.打开tomcat.service
vi /lib/systemd/system/tomcat.service
添加以下内容并保存退出:
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/webserver/apache-tomcat-9.0.14/bin/startup.sh
ExecStop=/usr/local/webserver/apache-tomcat-9.0.14/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
4.将tomcat.service添加到开机自启
systemctl enable tomcat.service
e.浏览器访问 http://localhost:10001 (localhost为服务器IP地址)
tomcat启停命令
关闭tomcat9: service tomcat9 stop
开启tomcat9: service tomcat9 start
重启tomcat9:service tomcat9 restart
获得更多java开发相关免费百度云学习视频请关注微信公众号 JavaFreeStudy:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。