需要Java环境
https://www.cnblogs.com/sea-stream/p/10404360.html
官网下载安装包
wget http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.0.M18/bin/apache-tomcat-9.0.0.M18.tar.gz
解压
tar -zxvf apache-tomcat-9.0..M18.tar.gz
移动目录
sudo mv ~/apache-tomcat-9.0..M18 /usr/local/tomcat
配置自启动,切换至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"
添加权限
sudo chmod +x setenv.sh
配置service
sudo vi /usr/lib/systemd/system/tomcat.service
加入如下内容
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat/tomcat.pid
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置环境变量
sudo vi /etc/profile
加入如下代码
export CATALINA_HOME=/usr/local/tomcat
export PATH=$TOMCAT_HOME/bin:$PATH
使其生效
source /etc/profile
关闭防火墙
systemctl stop firewalld.service
修改端口
sudo vi /usr/local/tomcat/conf/server.xml
将8080改为你想要的端口即可
<Connector port="" protocol="HTTP/1.1"
connectionTimeout=""
redirectPort="" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="" protocol="HTTP/1.1"
connectionTimeout=""
redirectPort="" />
-->
配置gui-manager项目部署方式
sudo vi /usr/local/tomcat/conf/tomcat-users.xml
拷贝以下代码放置</tomcat-users>标签之间(注意将password和username换成你自己的)
<role rolename="manager"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="king" password="kingpass" roles="admin-gui,manager-gui"/>
注释标签
sudo vi /usr/local/tomcat/webapps/manager/META-INF/context.xml
将Value标签的内容注释
<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>
启动
service tomcat start
如果报错:启动tomcat 报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
关闭
service tomcat stop
访问如下连接即可看到tomcat首页,记得换IP
http://192.168.199.196:8080/
参考:
http://blog.****.net/zzpzheng/article/details/48864129
http://blog.****.net/guochunyang/article/details/51820066
http://*.com/questions/10268583/downloading-java-jdk-on-linux-via-wget-is-shown-license-page-instead
//配置开机启动
systemctl enable tomcat
//启动tomcat
systemctl start tomcat
//停止tomcat
systemctl stop tomcat
//重启tomcat
systemctl restart tomcat