一、創建啟動腳本
$cd {your path}
內容參考:
# cd /root/clouddevice
# touch start.sh
# vi start.sh
start.sh內容參考:
#!/bin/bash echo '准備啟動 frp...' cd /root/clouddevice/frp/ && nohup /root/clouddevice/frp/frps -c /root/clouddevice/frp/frps.ini > frps.log & && echo 'frp啟動完畢!' echo '准備啟動 rethinkdb及stf...' cd /root/clouddevice/stf
rethinkdb &
nohup stf local --public-ip 192.168.137.100 --bind-dev-pull tcp://0.0.0.0:7114 --bind-dev-pub tcp://0.0.0.0:7116 -R > stf.log & echo 'rethinkdb及stf 啟動完畢!'
注意點:
1、.sh的腳本開頭有#!/bin/bash
2、很多啟動腳本都涉及日志輸出,建議配置的命令最好進入對應目錄, 然后再執行腳本
二、在開機自啟動文件中加入啟動執行目錄
# sudo vim /etc/rc.d/rc.local
/etc/rc.d/rc.local內容參考:
#!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # 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 su - developer -c 'cd /root/clouddevice/ && sh start.sh'
在centos7中,/etc/rc.d/rc.local文件的權限被降低了,沒有執行權限,需要給它添加可執行權限,賦予自啟動文件執行權限:
# sudo chmod +x /etc/rc.d/rc.local
注意點:
1、啟動的用戶如果都以root啟動, 其他用戶不方便操作root留下的進程以及生成的文件, 建議切換到對應權限的用戶執行啟動文件。
2、切換用戶命令:
# su - username -c //username:系統登錄用戶名