編寫腳本autostart.sh(這裏以開機啓動redis服務爲例),腳本內容以下:redis
`
#!/bin/sh
#chkconfig: 2345 80 90
#description:開機自啓動腳本 power by https://www.shangmayuan.comshell
# redis
cd /data1/redis
redis-server /data1/redis/redis.confcentos
`server
腳本第一行 「#!/bin/sh」 告訴系統使用的shell;
腳本第二行 「#chkconfig: 2345 80 90」 表示在2/3/4/5運行級別啓動,啓動序號(S80),關閉序號(K90);
腳本第三行 表示的是服務的描述信息
注意: 第二行和第三行必寫,負責會出現如「服務 autostart.sh 不支持 chkconfig」這樣的錯誤。ip
將寫好的autostart.sh腳本移動到/etc/rc.d/init.d/目錄下,並給腳本賦可執行權限it
`
chmod +x autostart.sh
`io
添加腳本到開機自動啓動項目中
`
chkconfig --add autostart.sh
chkconfig autostart.sh on
`權限