常用命令
描述 舊命令 新命令
使服務自動啟動 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)后每次開啟此服務自動啟動,無需人工啟動