linux自啟動服務(wù)的幾種方式

RedHat4 自啟動方式

一 通過服務(wù)的方式自啟動

1.在/etc/init.d 下建立相關(guān)程序的啟動腳本

ln -s /etc/init.d/服務(wù)名 /etc/rc.d/rc3.d/S100服務(wù)名 //S:開機自啟動 100:啟動順序

2.chkconfig --add 服務(wù)名

3.chkconfig 服務(wù)名 on 開機自啟動

chkconfig 服務(wù)名 off 關(guān)閉自啟動

4.service 服務(wù)名 start 手動啟動服務(wù)

5.service 服務(wù)名 stop 手動關(guān)閉服務(wù)?

二 自定義開機程序

1.vi /etc/rc.d/rc.local?

2.末尾添加啟動命令

3 /usr/src/tomcat/bin/startup.sh /*自動啟動tomcat*/

三 定時啟動腳本

1. /root下寫好啟動的shell文件

#! /bin/sh

A=`netstat?-anp |?grep?":8080"?|?grep?"LISTEN"?|?wc?-l`

echo?$A

if?[ $A -eq?0 ]

then

/etc/init.d/tomcat?start

echo?"tomcat重啟中"

else

echo?"tomcat正在運行中"

fi

2. crontab -e?

3. 設(shè)置好定時時間?

4. 設(shè)置為每分鐘檢查一次 //*/1 * * * * 腳本目錄

**********************************************************************

Centos7 自啟動方式?

一 通過(init.d)服務(wù)的方式自啟動

1.在/etc/init.d 下建立相關(guān)程序的啟動腳本

ln -s /etc/init.d/服務(wù)名 /etc/rc.d/rc3.d/S100服務(wù)名 //S:開機自啟動 100:啟動順序

2.chkconfig --add 服務(wù)名

3.chkconfig 服務(wù)名 on 開機自啟動

chkconfig 服務(wù)名 off 關(guān)閉自啟動

4.service 服務(wù)名 start 手動啟動服務(wù)

5.service 服務(wù)名 stop 手動關(guān)閉服務(wù)?

二 通過systemctl 服務(wù)的方式自啟動

1.cd /usr/lib/systemd/system/

2.vi 服務(wù)名.service

# Systemd unit file for default tomcat

#

# To create clones of this service:

# DO NOTHING, use tomcat@.service instead.


[Unit]

Description=Apache Tomcat Web Application Container

After=syslog.target network.target


[Service]

Type=simple

EnvironmentFile=/etc/tomcat/tomcat.conf

Environment="NAME="

EnvironmentFile=-/etc/sysconfig/tomcat

ExecStart=/usr/libexec/tomcat/server?start

SuccessExitStatus=143

User=tomcat


[Install]

WantedBy=multi-user.target

3.systemctl enable 服務(wù)名.service //設(shè)置自啟動服務(wù)

4.systemctl start 服務(wù)名.service //啟動服務(wù)

5.systemctl stop 服務(wù)名.service //停止服務(wù)?

6.service 服務(wù)名 start //啟動服務(wù)

7.service 服務(wù)名 stop //停止服務(wù)

任務(wù)          ??? 舊指令             新指令

使某服務(wù)自動啟動???   chkconfig httpd on    ?? systemctl?enable?httpd.service

使服務(wù)不自動啟動  ? chkconfig httpd off     systemctl disable httpd.service

檢查服務(wù)狀態(tài)??? service httpd status    ? systemctl status httpd.service (服務(wù)詳細信息) systemctl is-active httpd.service (僅顯示是否 Active)

已啟動的服務(wù)   ?? chkconfig --list???     systemctl list-units?--type=service

啟動某服務(wù)??   service httpd start??    ? systemctl start httpd.service

停止某服務(wù)    ????? service httpd stop??    ? systemctl stop httpd.service

重啟某服務(wù)???  service httpd restart??????? systemctl restart httpd.service <br><br>



三 自定義開機程序

1.vi /etc/rc.d/rc.local?

2.末尾添加啟動命令

3 /usr/src/tomcat/bin/startup.sh /*自動啟動tomcat*/


四 定時啟動腳本

1. /root下寫好啟動的shell文件

2. crontab -e?

3. 設(shè)置好定時時間?

4. 設(shè)置為每分鐘檢查一次 // */1 * * * * 腳本目錄

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容