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 * * * * 腳本目錄