中国发展在线网站官网,百度如何发布信息推广,wordpress文章标题优化,做公众号封面网站方式一、 1#xff1a;rc.local 文件
1、执行命令#xff1a;编辑 “/etc/rc.local”
vi /ect/rc.local
2、然后在文件最后一行添加要执行程序的全路径。 例如#xff0c;每次开机时要执行一个 hello.sh#xff0c;这个脚本放在 / usr 下面#xff0c;那就可以在 “/et…方式一、 1rc.local 文件
1、执行命令编辑 “/etc/rc.local”
vi /ect/rc.local
2、然后在文件最后一行添加要执行程序的全路径。 例如每次开机时要执行一个 hello.sh这个脚本放在 / usr 下面那就可以在 “/etc/rc.local” 中加一行 “/usr/./hello.sh”或者 cd /usr/ ./hello.sh 注意你的命令应该添加在exit 0 之前
3、添加完保存后设置 rc.local 可执行权限 chmod x /etc/rc.local
方式二 在 / etc/init.d 目录下添加自启动脚本
linux 在 “/etc/rc.d/init.d” 下有很多的文件每个文件都是可以看到内容的其实都是一些 shell 脚本或者可执行二进制文件 Linux 开机的时候会加载运行 / etc/init.d 目录下的程序因此我们可以把想要自动运行的脚本放到这个目录下即可。系统服务的启动就是通过这种方式实现的。 PS添加完后务必设置文件的可执行权限 chmod x filename
方式三制作 Linux 服务并设置开机自启动
1.在这个目录下创建服务 /etc/systemd/system 文件名为 XXXX.service
2.对应XXXX.service内容
[Unit]
DescriptionXXXX你程序的名字
Afternetwork.target在哪个服务之后[Service]
Typesimple
ExecStart/root/xxx/xxx/XXXX #启动程序 对应路径或绝对路径
WorkingDirectory/root/xxx/xxx #程序工作目录这个和上面这一项可自由搭配
StandardOutputnull #日志相关
Restartalways #程序自动重启守护线程
RestartSec10 #程序重启间隔
StartLimitInterval5 #间隔内重启最大次数
Userroot #使用者[Install]
WantedBymulti-user.target3.完成后设置程序的启动或开机自启 通用命令 systemctl start WEI-iEdge.service (启动服务) systemctl enable WEI-iEdge.service (启动服务的开机自启)
#重新加载配置 systemctl daemon-reload
示例一 设置minio为服务并设置开机自启动
/usr/local/minio/etc/minio.conf
MINIO_VOLUMES/usr/local/minio/data#文件存储地址
MINIO_OPTS-C /usr/local/minio/etc --address xxxxx:9000 --console-address xxxxx:8848
MINIO_ACCESS_KEYminioadmin
#用户名
MINIO_SECRET_KEYxxxxxx
#密码[Unit]
DescriptionMinIO
Documentationhttps://docs.min.io
Wantsnetwork-online.target
Afternetwork-online.target
AssertFileIsExecutable/usr/local/minio/bin/minio[Service]
# User and group
Userminio
GroupminioEnvironmentFile/usr/local/minio/etc/minio.conf
ExecStart/usr/local/minio/bin/minio server $MINIO_OPTS $MINIO_VOLUMES# Let systemd restart this service always
Restartalways
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE65536# Disable timeout logic and wait until process is stopped
TimeoutStopSecinfinity
SendSIGKILLno[Install]
WantedBymulti-user.target
启动服务 #启动minio服务 systemctl start minio.service
#添加开机自启动 systemctl enable minio.service
#查看状态 systemctl status minio.service #关闭服务 systemctl stop minio #重新加载配置 systemctl daemon-reload
示例二 设置niginx的服务为自启服务
[Unit]
DescriptionThe NGINX HTTP and reverse proxy server
Afternetwork.target remote-fs.target nss-lookup.target[Service]
Typeforking
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
PrivateTmptrue[Install]
WantedBymulti-user.target
启动服务 #启动minio服务 systemctl start nginx.service
#添加开机自启动 systemctl enable nginx.service
#查看状态 systemctl status nginx.service #关闭服务 systemctl stop minio #重新加载配置 systemctl daemon-reload