Centos 7關於rc.local指令碼命令開機不執行及指定使用者啟動的解決方案

來源:互聯網
上載者:User

標籤:啟動命令   system   higher   程式   使用者   rc.local   


  1. 開機不啟動

在實際生產情境中,我們喜歡在安裝了一些軟體服務後,將軟體佈建為開機自啟動,設定為開機自啟動有兩種方法:

1)  設定為chkconfig,可以編寫指令碼,查看設定開機自啟動的命令 –add表示添加程式自啟動, --list表示查看。

以後的程式如果需要使用chkconfig開機自啟動,那麼需要在啟動程式中加入三行:

# chkconfig:2345 20 80

#description: Saves and restores system entropy pool for \

#              higher quality random numbergeneration.

                 第一行中的20,80是啟動層級,不能與其他程式一樣,因此,需自訂設定。

2)  配置在/etc/rc.local檔案中。直接將軟體服務的啟動命令寫在rc.local檔案

注意:編輯完rc.local檔案後,一定要給rc.local檔案執行許可權,否則開機時不會執行rc.local檔案中指令碼命令

chmod+x /etc/rc.local

  1. 關於在rc.local檔案中指定使用者執行指令碼命令

使用su命令即可,命令格式:

su - username -c “your-cammand” ,如:

[[email protected] ~]$ 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"

 

注意:指定使用者執行的指令碼(程式)目錄,該使用者必須有管理該指令碼(程式)目錄(檔案)的許可權。

最好將該指令碼(程式)目錄的所有權給該使用者:

chown -R xiaoyao.xiaoyao /mnt/mongodb


Centos 7關於rc.local指令碼命令開機不執行及指定使用者啟動的解決方案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.