Centos 7關(guān)于rc.local腳本命令開機不執(zhí)行及指定用戶啟動的解決方法
1.開機不啟動
在實際生產(chǎn)場景中,我們喜歡在安裝了一些軟件服務后,將軟件設(shè)置為開機自啟動,設(shè)置為開機自啟動有兩種方法:
1) 設(shè)置為chkconfig,可以編寫腳本,查看設(shè)置開機自啟動的命令 –add表示添加程序自啟動, --list表示查看。
以后的程序如果需要使用chkconfig開機自啟動,那么需要在啟動程序中加入三行:
# chkconfig:2345 20 80
#description: Saves and restores system entropy pool for \
# higher quality random numbergeneration.
第一行中的20,80是啟動級別,不能與其他程序一樣,因此,需自定義設(shè)置。
2) 配置在/etc/rc.local文件中。直接將軟件服務的啟動命令寫在rc.local文件
注意:編輯完rc.local文件后,一定要給rc.local文件執(zhí)行權(quán)限,否則開機時不會執(zhí)行rc.local文件中腳本命令
chmod+x /etc/rc.d/rc.local
注意此處,是/etc/rc.d/rc.local,而不是/etc/rc.local,如果給/etc/rc.local執(zhí)行權(quá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
耿炒18729941466: centos 7 開機網(wǎng)絡(luò)啟動腳本在什么位置? -
贛榆縣磨損: ______ /etc/rc.d/rc.local
耿炒18729941466: 小白求教docker centos7里面的service命令 -
贛榆縣磨損: ______ CentOS 7 中 Docker 的安裝 Docker 軟件包已經(jīng)包括在默認的 CentOS-Extras 軟件源里.因此想要安裝 docker,只需要運行下面的 yum 命令:[root@localhost ~]# yum install docker 啟動 Docker 服務 安裝完成后,使用下面的命令來啟動 docker ...
耿炒18729941466: 如何運行自己寫的腳本 centos7 -
贛榆縣磨損: ______ 把腳本寫到一個文件中進行保存,如文件名為:test.sh 然后運行:sh ./test.sh
耿炒18729941466: 如何在CentOS7上改變網(wǎng)絡(luò)接口名的方法與步驟 -
贛榆縣磨損: ______ 首先,讓我們來禁用該可預測命名規(guī)則.對于這一點,你可以在啟動時傳遞“net.ifnames=0”的內(nèi)核參數(shù).這是通過編輯/etc/default/grub并加入“net.ifnames=0”到GRUBCMDLINELINUX變量來實現(xiàn)的.然后運行這條命令來重新生成GRUB配...
耿炒18729941466: centos 7 shell 腳本怎樣運行 -
贛榆縣磨損: ______ 一、root權(quán)限編輯/etc/rc.d/rc.local Shell代碼 su cd /etc/rc.d/ vi rc.local 二、在這個文件加上你要執(zhí)行的腳本,全部內(nèi)容如下:Shell代碼 #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff ...
耿炒18729941466: centos7關(guān)網(wǎng)關(guān)的命令行 -
贛榆縣磨損: ______ 是要刪除掉網(wǎng)關(guān)嗎?# ip route del default
耿炒18729941466: 如何在centos7上通過yum安裝docker -
贛榆縣磨損: ______ 在centos7上我們可以通過yum來安裝docker1.確保你擁有管理員權(quán)限,需要可以使用sudo或者root的命令的權(quán)限.2.需要將你的yum的包升級到最新的狀態(tài).sudo yum update3.為你的yum添加一個repo文件.在centos7下面您可以直接運行下面的...
耿炒18729941466: 如何在CentOS 7上修改主機名 -
贛榆縣磨損: ______ 在CentOS/RHEL 7中,有個叫hostnamectl的命令行工具,它允許你查看或修改與主機名相關(guān)的配置.要查看主機名相關(guān)的設(shè)置:$ hostnamectl status 只查看靜態(tài)、瞬態(tài)或靈活主機名,分別使用“--static”,“--transient”或“--pretty”選項.$ ...
在實際生產(chǎn)場景中,我們喜歡在安裝了一些軟件服務后,將軟件設(shè)置為開機自啟動,設(shè)置為開機自啟動有兩種方法:
1) 設(shè)置為chkconfig,可以編寫腳本,查看設(shè)置開機自啟動的命令 –add表示添加程序自啟動, --list表示查看。
以后的程序如果需要使用chkconfig開機自啟動,那么需要在啟動程序中加入三行:
# chkconfig:2345 20 80
#description: Saves and restores system entropy pool for \
# higher quality random numbergeneration.
第一行中的20,80是啟動級別,不能與其他程序一樣,因此,需自定義設(shè)置。
2) 配置在/etc/rc.local文件中。直接將軟件服務的啟動命令寫在rc.local文件
注意:編輯完rc.local文件后,一定要給rc.local文件執(zhí)行權(quán)限,否則開機時不會執(zhí)行rc.local文件中腳本命令
chmod+x /etc/rc.d/rc.local
注意此處,是/etc/rc.d/rc.local,而不是/etc/rc.local,如果給/etc/rc.local執(zhí)行權(quá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
相關(guān)評說:
贛榆縣磨損: ______ /etc/rc.d/rc.local
贛榆縣磨損: ______ CentOS 7 中 Docker 的安裝 Docker 軟件包已經(jīng)包括在默認的 CentOS-Extras 軟件源里.因此想要安裝 docker,只需要運行下面的 yum 命令:[root@localhost ~]# yum install docker 啟動 Docker 服務 安裝完成后,使用下面的命令來啟動 docker ...
贛榆縣磨損: ______ 把腳本寫到一個文件中進行保存,如文件名為:test.sh 然后運行:sh ./test.sh
贛榆縣磨損: ______ 首先,讓我們來禁用該可預測命名規(guī)則.對于這一點,你可以在啟動時傳遞“net.ifnames=0”的內(nèi)核參數(shù).這是通過編輯/etc/default/grub并加入“net.ifnames=0”到GRUBCMDLINELINUX變量來實現(xiàn)的.然后運行這條命令來重新生成GRUB配...
贛榆縣磨損: ______ 一、root權(quán)限編輯/etc/rc.d/rc.local Shell代碼 su cd /etc/rc.d/ vi rc.local 二、在這個文件加上你要執(zhí)行的腳本,全部內(nèi)容如下:Shell代碼 #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff ...
贛榆縣磨損: ______ 是要刪除掉網(wǎng)關(guān)嗎?# ip route del default
贛榆縣磨損: ______ 在centos7上我們可以通過yum來安裝docker1.確保你擁有管理員權(quán)限,需要可以使用sudo或者root的命令的權(quán)限.2.需要將你的yum的包升級到最新的狀態(tài).sudo yum update3.為你的yum添加一個repo文件.在centos7下面您可以直接運行下面的...
贛榆縣磨損: ______ 在CentOS/RHEL 7中,有個叫hostnamectl的命令行工具,它允許你查看或修改與主機名相關(guān)的配置.要查看主機名相關(guān)的設(shè)置:$ hostnamectl status 只查看靜態(tài)、瞬態(tài)或靈活主機名,分別使用“--static”,“--transient”或“--pretty”選項.$ ...