wordpress資源博客優(yōu)化師助理
方式一、 1:rc.local 文件
1、執(zhí)行命令:編輯 “/etc/rc.local”
vi /ect/rc.local
2、然后在文件最后一行添加要執(zhí)行程序的全路徑。
例如,每次開機(jī)時(shí)要執(zhí)行一個(gè) hello.sh,這個(gè)腳本放在 / usr 下面,那就可以在 “/etc/rc.local” 中加一行 “/usr/./hello.sh”,或者 "cd /usr/ && ./hello.sh
注意,你的命令應(yīng)該添加在:exit 0 之前
3、添加完保存后設(shè)置 rc.local 可執(zhí)行權(quán)限
chmod +x /etc/rc.local
方式二 :在 / etc/init.d 目錄下添加自啟動(dòng)腳本
linux 在 “/etc/rc.d/init.d” 下有很多的文件,每個(gè)文件都是可以看到內(nèi)容的,其實(shí)都是一些 shell 腳本或者可執(zhí)行二進(jìn)制文件
Linux 開機(jī)的時(shí)候,會(huì)加載運(yùn)行 / etc/init.d 目錄下的程序,因此我們可以把想要自動(dòng)運(yùn)行的腳本放到這個(gè)目錄下即可。系統(tǒng)服務(wù)的啟動(dòng)就是通過(guò)這種方式實(shí)現(xiàn)的。
PS:添加完后務(wù)必設(shè)置文件的可執(zhí)行權(quán)限 chmod +x filename
方式三:制作 Linux 服務(wù)并設(shè)置開機(jī)自啟動(dòng)
1.在這個(gè)目錄下創(chuàng)建服務(wù):
/etc/systemd/system
文件名為 XXXX.service
2.對(duì)應(yīng)XXXX.service內(nèi)容:
[Unit]
Description=XXXX(你程序的名字)
After=network.target(在哪個(gè)服務(wù)之后)[Service]
Type=simple
ExecStart=/root/xxx/xxx/XXXX #啟動(dòng)程序 對(duì)應(yīng)路徑或絕對(duì)路徑
WorkingDirectory=/root/xxx/xxx #程序工作目錄(這個(gè)和上面這一項(xiàng)可自由搭配)
StandardOutput=null #日志相關(guān)
Restart=always #程序自動(dòng)重啟(守護(hù)線程)
RestartSec=10 #程序重啟間隔
StartLimitInterval=5 #間隔內(nèi)重啟最大次數(shù)
User=root #使用者[Install]
WantedBy=multi-user.target
3.完成后,設(shè)置程序的啟動(dòng)或開機(jī)自啟:
通用命令:
systemctl start WEI-iEdge.service (啟動(dòng)服務(wù))
systemctl enable WEI-iEdge.service (啟動(dòng)服務(wù)的開機(jī)自啟)
- #重新加載配置
systemctl daemon-reload
示例一 設(shè)置minio為服務(wù),并設(shè)置開機(jī)自啟動(dòng)
/usr/local/minio/etc/minio.conf
MINIO_VOLUMES="/usr/local/minio/data"#文件存儲(chǔ)地址
MINIO_OPTS="-C /usr/local/minio/etc --address xxxxx:9000 --console-address xxxxx:8848"
MINIO_ACCESS_KEY="minioadmin"
#用戶名
MINIO_SECRET_KEY="xxxxxx"
#密碼
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/minio/bin/minio[Service]
# User and group
User=minio
Group=minioEnvironmentFile=/usr/local/minio/etc/minio.conf
ExecStart=/usr/local/minio/bin/minio server $MINIO_OPTS $MINIO_VOLUMES# Let systemd restart this service always
Restart=always
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
#啟動(dòng)minio服務(wù)
systemctl start minio.service
#添加開機(jī)自啟動(dòng)
systemctl enable minio.service
#查看狀態(tài)
systemctl status minio.service
#關(guān)閉服務(wù):
systemctl stop minio
#重新加載配置
systemctl daemon-reload
示例二 ,設(shè)置niginx的服務(wù)為自啟服務(wù)
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s quit
ExecReload=/usr/local/nginx/sbin/nginx -s reload
PrivateTmp=true[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
#啟動(dòng)minio服務(wù)
systemctl start nginx.service
#添加開機(jī)自啟動(dòng)
systemctl enable nginx.service
#查看狀態(tài)
systemctl status nginx.service
#關(guān)閉服務(wù):
systemctl stop minio
#重新加載配置
systemctl daemon-reload