CentOS 7安装配置Tomcat 8.5并设置开机自启

1.系统版本及环境

1.CentOS 7.5  64bit    查看系统版本及位数命令

2.jdk 1.8 已安装配置   JDK1.8安装

2.Tomcat 8.5 安装

1.下载地址

http://tomcat.apache.org/

CentOS 7安装配置Tomcat 8.5并设置开机自启_第1张图片

下载完后用ftp工具上传到linux服务器或者直接复制进linux虚拟机(图形界面,安装了VMware-tool) 

2.解压以及新建文件

tar -zxvf apache-tomcat-8.5.32.tar.gz 

复制或者移动到 /usr/local/tomcat

先创建 /usr/local/tomcat

mkdir /usr/local/tomcat

移动

mv apache-tomcat-8.5.32 /usr/local/tomcat/

3.配置tomcat server.xml

server.xml可以配置端口,编码以及配置项目等等,配置端口把默认的8080,修改成80,修改字符集为utf-8

 vim /usr/local/tomcat/apache-tomcat-8.5.32/conf/server.xml 

CentOS 7安装配置Tomcat 8.5并设置开机自启_第2张图片

 

4.配置防火墙,开放80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

5.启动tomcat(启动bin目录下的startup.sh)

/usr/local/tomcat/apache-tomcat-8.5.32/bin/startup.sh

Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-8.5.32
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-8.5.32
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.5.32/temp
Using JRE_HOME:        /usr/local/java/jdk1.8.0_181
Using CLASSPATH:       /usr/local/tomcat/apache-tomcat-8.5.32/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.32/bin/tomcat-juli.jar
Tomcat started.

以上内容说明启动成功

关闭:/usr/local/tomcat/apache-tomcat-8.5.32/bin/shutdown.sh

6.浏览器测试

地址栏输入虚拟机ip地址:192.168.0.104     默认端口80

CentOS 7安装配置Tomcat 8.5并设置开机自启_第3张图片

说明配置成功 

 

设置开机自启(待补充)

1.编辑tomcat.service

vim /usr/lib/systemd/system/tomcat.service

编辑内容,保存 

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
Environment='JAVA_HOME=/usr/local/java/jdk1.8.0_181/'
Environment='CATALINA_PID=/usr/local/tomcat/apache-tomcat-8.5.32/tomcat.pid'
Environment='CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.32/'
Environment='CATALINA_BASE=/usr/local/tomcat/apache-tomcat-8.5.32/'
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'

PIDFile=/usr/local/tomcat/apache-tomcat-8.5.32/tomcat.pid
ExecStart=/usr/local/tomcat/apache-tomcat-8.5.32/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[unit]配置了服务的描述,规定了在network启动之后执行。

[service]配置了环境变量,JAVA_HOME,服务的pid,服务的启动,停止,重启,内存参数。

[install]配置了使用用户。

当需要启动多个tomcat时,复制多个tomcat安装文件在/usr/local/tomcat/下如/tomcat/tomcat2,并配置多个tomcat.service 如tomcat2.service,tomcat3.service 在配置中修改对应的路径即可

2.设置开机自启

systemctl enable tomcat.service

3.启动tomcat

systemctl start tomcat.service

4.在浏览器测试(略)

常用命令

查看全部服务命令:
systemctl list-unit-files --type service
查看服务
systemctl status name.service

增加开机启动
systemctl enable name.service
启动服务
systemctl start name.service
停止服务
systemctl stop name.service
重启服务
systemctl restart name.service
删除开机启动
systemctl disable name.service
其中.service 可以省略。

你可能感兴趣的:(CentOS,Linux,Tomcat)