- 下载tomcat tgz文件
- 解压缩到某目录,例如 /web/tomcats/tomcat1
- 进入/lib/systemd/system 目录
- 创建一个 tomcat-1.service文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| [Unit] Description=Apache Tomcat Web Application Container [tomcat """"""""1] After=network.target
[Service] Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-8-oracle Environment=CATALINA_PID=/web/tomcats/tomcat1/temp/tomcat.pid Environment=CATALINA_HOME=/web/tomcats/tomcat1 Environment=CATALINA_BASE=/web/tomcats/tomcat1 Environment” =’CATALINA_OPTS=-Xms512M -Xmx2048M -server -XX:+UseParallelGC’ Environment=’JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom’
ExecStart=/web/tomcats/tomcat1/bin/startup.sh ExecStop=/web/tomcats/tomcat1/bin/shutdown.sh
User=www-data Group=www-data UMask=0007 RestartSec=10 Restart=always
[Install] WantedBy=multi-user.target Alias=xxx #【注意,如果有这行,不要和其他的服务重复】
|
创建服务
执行下面的命令
1
| suduo systemctl link /lib/systemd/system/tomcat-1.service
|
上面这句会在/etc/systemd/system下给前面编辑的文件创建一个连接
1
| sudo systemctl enable tomcat1
|
上面这句设置此服务自动随机器启动而启动
重启systemd
1
| sudo systemctl daemon-reload
|
启动tomcat
1
| sudo systemctl start tomcat1
|
设置自动启动
1
| sudo systemctl enable tomcat1
|
注意目录权限,注意server.xml配置端口不要重复
重启可以用如下命令
1
| sudo systemctl restart tomcat1
|