1.權限設置(/etc/rc.local和/etc/rc.d/rc.local都須要賦予執行權限)redis
chmod +x /etc/rc.d chmod +x /etc/rc.d/rc.local
2.設置服務啓動腳本。
1)進入路徑centos
cd /usr/lib/systemd/system
2)編輯服務腳本服務器
vi rc-local.service
刪除以前的全部數據,導入如下數據。ide
##This file is part of systemd. #systemd is free software; you can redistribute it and/or modify it #under the terms of the GNU Lesser General Public License as published by #the Free Software Foundation; either version 2.1 of the License, or #(at your option) any later version. #This unit gets pulled automatically into multi-user.target by #systemd-rc-local-generator if /etc/rc.d/rc.local is executable. [Unit] Description=/etc/rc.d/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.d/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.d/rc.local start TimeoutSec=0 RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
3.使用命令啓動服務(確認服務可用)3d
systemctl start rc-local
code
使用systemctl -t service查看服務器全部服務的狀態,確認服務rc-local.service是否運行正常.
4.執行systemctl enable rc-localblog
systemctl enable rc-local
出現如下提示表示成功添加開機自啓動:Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /usr/lib/systemd/system/rc-local.service.
ip
以下圖:
get
完成以上步驟就能夠將開機自動執行的命令寫入/etc/rc.d/rc.local中,實現開機自動執行。generator