常用命令
描述 旧命令 新命令
使服务自动启动 chkconfig --level 3 http on systemctl enable 服务名.service systemctl enable httpd.service
使服务不自动启动 chkconfig --level 3httpd off systemctl disable 服务名.sevice
查看服务章台 service httpd status systemctl status httpd.service systemctl is-active httpd.service
查看所有已启动的服务 chkconfig --list systemctl list-units --type=service
启动服务 service httpd start systemctl start httpd.service
停止服务 service httpd stop systemctl stop httpd.service
重启服务 service httpd restart systemctl restart httpd.service
1 、把服务设置成系统服务
a、找到系统服务目录、systemd/system(假如有多个此目录,可通过目录下是否有.service文件来判断是否)
b、新建文件,假如需要把tomcat加入到服务中,则新建tomcat.service #touch tomcat.service
c、文件中输入必要信息,vi tomcat.service,如下:
[Unit]
Description=nginx #描述
After=network.target #服务类别
[Service]
Type=forking #运行形式
ExecStart=/xx/xx start #注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
ExecReload=/xx/xx restart 注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
ExecStop=/xx/xx stop 注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
PrivateTmp=true #表示给服务分配独立的临时空间
[Install]
WantedBy=multi-user.target #服务安装的相关设置,可设置为多用户
d、设置后保存
e、设置成开机自启动(systemctl enable tomcat.service)后每次开启此服务自动启动,无需人工启动