1.開機(jī)不啟動(dòng)
在實(shí)際生產(chǎn)場(chǎng)景中,我們喜歡在安裝了一些軟件服務(wù)后胸竞,將軟件設(shè)置為開機(jī)自啟動(dòng)碎连,設(shè)置為開機(jī)自啟動(dòng)有兩種方法:
1)? 設(shè)置為chkconfig,可以編寫腳本汽摹,查看設(shè)置開機(jī)自啟動(dòng)的命令 –add表示添加程序自啟動(dòng), --list表示查看惭蟋。
以后的程序如果需要使用chkconfig開機(jī)自啟動(dòng)苗桂,那么需要在啟動(dòng)程序中加入三行:
# chkconfig:2345 20 80
#description: Saves and restores system entropy pool for \
#? ? ? ? ? ? ? higher quality random numbergeneration.
? ? ? ? ? ? ? ? 第一行中的20,80是啟動(dòng)級(jí)別,不能與其他程序一樣告组,因此煤伟,需自定義設(shè)置。
2)? 配置在/etc/rc.local文件中木缝。直接將軟件服務(wù)的啟動(dòng)命令寫在rc.local文件
注意:編輯完rc.local文件后便锨,一定要給rc.local文件執(zhí)行權(quán)限,否則開機(jī)時(shí)不會(huì)執(zhí)行rc.local文件中腳本命令
chmod+x /etc/rc.d/rc.local
注意此處我碟,是/etc/rc.d/rc.local鸿秆,而不是/etc/rc.local,如果給/etc/rc.local執(zhí)行權(quán)限是無效的怎囚,因?yàn)?etc/rc.local是軟鏈接卿叽,真正的文件是/etc/rc.d/rc.local
2.關(guān)于在rc.local文件中指定用戶執(zhí)行腳本命令
使用su命令即可,命令格式:
su - username -c “your-cammand” ,如:
[jiakeke@mongodb ~]$ cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemdservices or udev rules
# to run scripts during boot instead of using thisfile.
#
# In constrast to previous versions due to parallelexecution during boot
# this script will NOT be run after all otherservices.
#
# Please note that you must run 'chmod +x/etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/bin/systemctl start iptables.service
#startup mongodb
/bin/su - xiaoyao -c? "/mnt/mongodb/bin/mongod --config/mnt/mongodb/bin/mongodb.conf"
注意:指定用戶執(zhí)行的腳本(程序)目錄恳守,該用戶必須有管理該腳本(程序)目錄(文件)的權(quán)限考婴。
最好將該腳本(程序)目錄的所有權(quán)給該用戶:
chown -R xiaoyao.xiaoyao /mnt/mongodb