日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

開機自啟動設(shè)置 開機自啟動

很多時候,我們需要將一些服務(wù)在Linux系統(tǒng)啟動時即自動運行,省得每次都要去手動啟動一遍,如Redis,MySQL,Nginx等 。本文對CentOS與Ubuntu下開機自啟動的配置方法進(jìn)行整理,供參考查閱 。
CentOS7的開機自啟動配置一. rc.local方式
rc.local是CentOS以前版本的方式,在CentOS7中仍然以兼容的形式存在,雖仍可用,但不推薦(推薦使用systemd service) 。
1、編寫需要開機自啟動的腳本,并添加執(zhí)行權(quán)限
[root@dev-server-1 ~]# vim test_rclocal.sh
#!/bin/bash
time=`date +%F_%T`
echo $time' from rc.local' >> /tmp/test.log
[root@dev-server-1 ~]# chmod +x test_rclocal.sh復(fù)制代碼
作為測試,上述腳本打印一個時間到/tmp/test.log文件中
2、在/etc/rc.d/rc.local配置文件中添加腳本運行命令(使用絕對路徑)
[root@dev-server-1 ~]# vim /etc/rc.d/rc.local
#!/bin/bash
# …注釋部分
touch /var/lock/subsys/local
/root/test_rclocal.sh >/dev/null 2>/dev/null
復(fù)制代碼
3、添加/etc/rc.d/rc.local文件的執(zhí)行權(quán)限
在centos7中,/etc/rc.d/rc.local沒有執(zhí)行權(quán)限,需要手動授權(quán)
[root@dev-server-1 ~]# chmod +x /etc/rc.d/rc.local復(fù)制代碼
以上三步,即可使/root/test_rclocal.sh >/dev/null 2>/dev/null 命令在服務(wù)器系統(tǒng)啟動時自動運行 。
二. chkconfig方式
1、編寫需要開機自啟動的測試腳本,并添加執(zhí)行權(quán)限
[root@dev-server-1 ~]# vim test_chkconfig.sh
#!/bin/bash
time=`date +%F_%T`
echo $time' from chkconfig' >> /tmp/test.log
[root@dev-server-1 ~]# chmod +x test_chkconfig.sh復(fù)制代碼
2、在/etc/rc.d/init.d/目錄下添加一個可執(zhí)行腳本testchkconfig
[root@dev-server-1 ~]# vim /etc/rc.d/init.d/testchkconfig
#!/bin/bash
# chkconfig: 2345 90 10
# description: test chkconfig
/root/test_chkconfig.sh >/dev/null 2>/dev/null
[root@dev-server-1 ~]# chmod 755 /etc/rc.d/init.d/testchkconfig復(fù)制代碼
上述testchkconfig腳本的頭部必須遵循一定的格式 # chkconfig: 2345 90 10,其中2345指定服務(wù)在哪些執(zhí)行等級中開啟或關(guān)閉,90表示啟動的優(yōu)先級(0-100,越大優(yōu)先級越低),10表示關(guān)閉的優(yōu)先級 。執(zhí)行等級包括
0:表示關(guān)機1:單用戶模式2:無網(wǎng)絡(luò)連接的多用戶命令行模式3:有網(wǎng)絡(luò)連接的多用戶命令行模式4:保留未使用5:帶圖形界面的多用戶模式6:重新啟動
3、加入開機啟動服務(wù)列表
[root@dev-server-1 ~]# chkconfig –add testchkconfig
[root@dev-server-1 ~]# chkconfig –list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole0:off1:off2:off3:off4:off5:off6:off
network0:off1:off2:on3:on4:on5:on6:off
testchkconfig0:off1:off2:on3:on4:on5:on6:off復(fù)制代碼
使用 chkconfig –list 可查看當(dāng)前加入開機自啟動的服務(wù)列表,但如Note部分所述,該命令只顯示SysV服務(wù),不包含原生的systemd服務(wù),查看systemd服務(wù)可使用systemctl list-unit-files命令 。
以上三步,即可使/root/test_chkconfig.sh >/dev/null 2>/dev/null 命令在服務(wù)器系統(tǒng)啟動時自動運行 。
chkconfig的其它命令參考
$chkconfig –list # 表示查看所有服務(wù)在各個運行級別下的狀態(tài) 。
$chkconfig testchkconfig on # 表示指定服務(wù)在所有的運行級別下都是開啟狀態(tài) 。
$chkconfig testchkconfig off # 表示指定服務(wù)在所有的運行級別下都是關(guān)閉狀態(tài) 。

推薦閱讀