Server version: Apache Tomcat/8.5.16
CentOS Linux release 7.3.1611 (Core) x86-64
1.Apache Tomcat/8.5.16依赖jre7及以上版本,不过jdk高版本已经包含jre,关于jdk&jre的安装请查看《Linux JAVA JDK JRE 环境变量安装与配置》
2.创建tomcat专有用户
# groupadd tomcat # useradd -g tomcat -s /bin/false tomcat 或 # useradd -g tomcat -s /sbin/nologin tomcat注意:
-g tomcat用户隶属于tomcat组
-s /bin/false 禁用shell访问
3.Apache Tomcat 8.5下载安装与配置&设置用户组权限并创建软连接
# cd /tmp # wget # tar zxvf apache-tomcat-8.5.16.tar.gz # mv apache-tomcat-8.5.16 /usr/local/ # cd /usr/local/ # chown -hR tomcat:tomcat apache-tomcat-8.5.16 # ln -s apache-tomcat-8.5.16 tomcat4.添加tomcat自启动systemd服务单元文件
# vim /lib/systemd/system/tomcat.service [Unit] Description=Apache Tomcat 8 After=syslog.target network.target [Service] Type=forking User=tomcat Group=tomcat Environment=Java_HOME=/usr/local/jdk/jre Environment=CATALINA_PID=/usr/local/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/usr/local/tomcat Environment=CATALINA_BASE=/usr/local/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx4096M -server -XX:+UseParallelGC' Environment='CATALINA_OPTS=-Dfile.encoding=UTF-8 -server -Xms2048m -Xmx2048m -Xmn1024m -XX:SurvivorRatio=10 -XX:MaxTenuringThreshold=15 -XX:NewRatio=2 -XX:+DisableExplicitGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/usr/local/tomcat/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target5.重载systemd服务单元,给予软连接目录权限,启动Apache Tomcat服务并设置Tomcat为开机自启动
# systemctl daemon-reload # cd /usr/local/ # chown -hR tomcat:tomcat tomcat # systemctl start tomcat # systemctl enable tomcat6.配置Apache Tomcat用户实现远程登录
在tomcat-users.xml文件<tomcat-users></tomcat-users>中间添加;
# vim /usr/local/tomcat/conf/tomcat-users.xml <role rolename="manager-gui"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>tomcat8.5之后的版本,已经增强远程登录安全过滤规则,默认不支持远程登录,需要修改配置文件。
修改文件:
/host-manager/META-INF/context.xml
/manager/META-INF/context.xml
默认值:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />修改为:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" addConnectorPort="true" allow="127\.\d+\.\d+\.\d+;\d*|::1;\d*|0:0:0:0:0:0:0:1;\d*|.*;8080"/>详情可查看 文档
7.配置Firewalld防火墙
如果不放行8080端口,就无法在外部使用8080进行访问,现在将端口放行并重载firewall服务
# firewall-cmd --zone=public --add-port=8080/tcp --permanent # firewall-cmd --reload # firewall-cmd --list-ports # firewall-cmd --list-services目前为止Apache Tomcat 8.5.16已经成功安装。现在您可以使用IP:port进行测试访问。
更多Tomcat相关教程见以下内容:
RedHat Linux 5.5安装JDK+Tomcat并部署Java项目
Linux下使用Xshell查看Tomcat实时日志中文乱码解决方案
CentOS 64-bit下安装JDK和Tomcat并设置Tomcat开机启动操作步骤
Ubuntu 16.04下安装Tomcat 8.5.9