Tomcat
Tomcat是由Apache组织开发的一个servlet容器
- 实现对servlet、JSP、Java Socket等支持
- 包含HTTP服务器
- 作为中间件使用
- 可与Nginx结合使用
官方库安装
1 2 3 4
| sudo apt install tomcat8 sudo apt install tomcat8-docs sudo apt install tomcat8-admin sudo apt install tomcat8-examples
|
启动服务之后,浏览器地址栏输入地址:http://172.16.247.128:8080
手动安装
1 2 3
| sudo apt install default-jdk
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
|
下载安装包:
1 2 3 4 5
| wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.zip
unzip apache-tomcat-8.5.50.zip
sudo mv apache-tomcat-8.5.50 /opt/tomcat/
|
安装:
1 2 3 4 5 6 7 8 9 10 11
| sudo chown -R tomcat: /opt/tomcat/
cd /opt/tomcat/apache-tomcat-8.5.50 sudo chmod +x /opt/tomcat/apache-tomcat-8.5.50/bin/*.sh
sudo ln -s /opt/tomcat/apache-tomcat-8.5.50/ /opt/tomcat/latest
sudo chown -R tomcat: /opt/tomcat/latest
|
创建tomcat服务管理脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| sudo vim /etc/systemd/system/tomcat.service
[Unit] After=network.target
[Service] Type=forking User=tomcat Group=tomcat Environment="Java_HOME=/usr/lib/jvm/default-java" Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom" Environment="CATALINA_BASE=/opt/tomcat/latest" Environment="CATALINA_HOME=/opt/tomcat/latest" Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/tomcat/latest/bin/startup.sh ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install] WantedBy=multi-user.target
|
启动服务
1 2 3 4
| sudo systemctl daemon-reload sudo systemctl start tomcat sudo systemctl status tomcat sudo systemctl enable tomcat
|
web管理接口配置
1 2 3 4 5 6 7 8 9 10 11
| sudo vim /opt/tomcat/latest/conf/tomcat-users.xml
<tomcat-users>
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="admin" password="123" roles="admin-gui, manager-gui"/>
</tomcat-users>
|
指定登录主机
1
| sudo vim /opt/tomcat/latest/webapps/manager/META-INF/context.xml
|
访问:http://192.168.1.104:8080/manager/html
这时会有弹出的对话框,输入账号密码进入管理页面:
1 2 3
| sudo vim /opt/tomcat/latest/webapps/host-manager/META-INF/context.xml
|
访问:http://192.168.1.104:8080/host-manager/html