Linux—添加开机启动(服务/脚本)

pve7.x、8.x版本一键升级、换源、优化工具脚本推荐 每次安装完pve之后都需要、换各种debain源、pve源、lxc源等、去掉弹窗、合并local-lvm等一系列的工作。按照提示手动删除分卷、数据中心》存储》编辑local,内容全部勾选,表示local可以存储所有种类数据,删除local-lvm即可。一、以删除local-lvm为例,注意:我这里新装的系统,没数据直接删、有数据的朋友记得先将数据备份或移动到local存储。安装完成后、shift+f5强制刷新网页、新增了一些信息、可能对8.x版本支持不是很好,硬盘这个稍微有点儿用。选择o 回车 全展示。 阅读详情

系统启动时需要加载的配置文件

/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)

一、修改开机启动文件:/etc/rc.local(或者/etc/rc.d/rc.local)

转存失败重新上传取消

# 1.编辑rc.local文件
[root@localhost ~]# vi /etc/rc.local

# 2.修改rc.local文件,在 exit 0 前面加入以下命令。保存并退出。
/etc/init.d/mysqld start                                         # mysql开机启动
/etc/init.d/nginx start                                          # nginx开机启动
supervisord -c /etc/supervisor/supervisord.conf                  # supervisord开机启动
/bin/bash /server/scripts/test.sh >/dev/null 2>/dev/null

# 3.最后修改rc.local文件的执行权限
[root@localhost ~]# chmod +x  /etc/rc.local
[root@localhost ~]# chmod 755 /etc/rc.local

转存失败重新上传取消

二、自己写一个shell脚本

将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。

三、通过chkconfig命令设置

转存失败重新上传取消

# 1.将(脚本)启动文件移动到 /etc/init.d/或者/etc/rc.d/init.d/目录下。(前者是后者的软连接)
mv  /www/wwwroot/test.sh /etc/rc.d/init.d

# 2.启动文件前面务必添加如下三行代码,否侧会提示chkconfig不支持。
#!/bin/sh                          告诉系统使用的shell,所以的shell脚本都是这样
#chkconfig: 35 20 80               分别代表运行级别,启动优先权,关闭优先权,此行代码必须
#description: http server          自己随便发挥!!!,此行代码必须
/bin/echo $(/bin/date +%F_%T) >> /tmp/test.log

# 3.增加脚本的可执行权限
chmod +x  /etc/rc.d/init.d/test.sh

# 4.添加脚本到开机自动启动项目中。添加到chkconfig,开机自启动。
[root@localhost ~]# cd /etc/rc.d/init.d
[root@localhost ~]# chkconfig --add test.sh
[root@localhost ~]# chkconfig test.sh on

# 5.关闭开机启动 
[root@localhost ~]# chkconfig test.sh off

# 6.从chkconfig管理中删除test.sh
[root@localhost ~]# chkconfig --del test.sh

# 7.查看chkconfig管理
[root@localhost ~]# chkconfig --list test.sh

转存失败重新上传取消

四、自定义服务文件,添加到系统服务,通过Systemctl管理

1.写服务文件:如nginx.service、redis.service、supervisord.service

转存失败重新上传取消

[Unit]:服务的说明
Description:描述服务
After:描述服务类别

[Service]服务运行参数的设置
Type=forking            是后台运行的形式
ExecStart               为服务的具体运行命令
ExecReload              为服务的重启命令
ExecStop                为服务的停止命令
PrivateTmp=True         表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径

[Install]               服务安装的相关设置,可设置为多用户
WantedBy=multi-user.target 

转存失败重新上传取消

2.文件保存在目录下:以754的权限。目录路径:/usr/lib/systemd/system。如上面的supervisord.service文件放在这个目录下面。

[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service
[root@localhost ~]# cat /usr/lib/systemd/system/supervisord.service

3.设置开机自启动(任意目录下执行)。如果执行启动命令报错,则执行:systemctl daemon-reload

转存失败重新上传取消

设置开机自启动
[root@localhost ~]# systemctl enable nginx.service       
[root@localhost ~]# systemctl enable supervisord

停止开机自启动
[root@localhost ~]# systemctl disable nginx.service
[root@localhost ~]# systemctl disable supervisord

验证一下是否为开机启动
[root@localhost ~]# systemctl is-enabled nginx
[root@localhost ~]# systemctl is-enabled supervisord

转存失败重新上传取消

4.其他命令

转存失败重新上传取消

启动nginx服务
[root@localhost ~]# systemctl start nginx.service

停止nginx服务
[root@localhost ~]# systemctl start nginx.service

重启nginx服务
[root@localhost ~]# systemctl restart nginx.service

查看nginx服务当前状态
[root@localhost ~]# systemctl status nginx.service

查看所有已启动的服务
[root@localhost ~]# systemctl list-units --type=service

转存失败重新上传取消

5.服务文件示例:

转存失败重新上传取消

# supervisord.service进程管理服务文件
[Unit]
Description=Process Monitoring and Control Daemon   # 内容自己定义:Description=Supervisor daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop= /usr/bin/supervisorctl shutdown 
ExecReload=/usr/bin/supervisorctl reload
Restart=on-failure
RestartSec=42s
KillMode=process 

[Install]
WantedBy=multi-user.target

转存失败重新上传取消

转存失败重新上传取消

# nginx.service服务文件
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

转存失败重新上传取消

转存失败重新上传取消

# redis.service服务文件
[Unit]
Description=Redis
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=kill -INT `cat /tmp/redis.pid`
User=www
Group=www

[Install]
WantedBy=multi-user.target

转存失败重新上传取消

 https://www.cnblogs.com/zwcry/p/9602756.html

 https://www.jianshu.com/p/e1442913eb0e

分类: Linux

好文要顶 关注我 收藏该文 转存失败重新上传取消 

转存失败重新上传取消

刘_love_田
关注 - 10
粉丝 - 15

+加关注

2

0

« 上一篇:  Mysql—索引原理与详解 
» 下一篇:  Linux—文件上传和下载

posted @ 2019-09-19 15:32  刘_love_田  阅读(48399)  评论(0)  编辑  收藏  举报

Aruba无线控制器实战:如何用Client Match优化企业办公区漫游(附SNR调优技巧) 本文深入解析了如何利用Aruba无线控制器的Client Match功能优化企业办公区无线漫游体验。通过实战配置,详细阐述了基于SNR(信噪比)的精细化调优策略,包括阈值设定、负载均衡与场景化参数调整,旨在解决终端粘滞、乒乓漫游等问题,实现智能、平滑的无缝漫游。 阅读详情

相关推荐

unity2D 摸索建立一个塔防游戏(一)

今天将用这几天学的知识实现一个小士兵攻打堡垒的2D游戏,当然,画面极其简单,全部扁平化。。。 用ps画出了一个带弯刀的士兵: 字体大一点。。。 然后再画一个堡垒 这是炮弹: 在Assets文件夹中建立7个子文件夹方便之后的内容整理: Animation  Animator  Material Texture Script Prefab S

少放点闫 5012

PVE/Debian11设置开机自启动项

在PVE中想要设置WOL网络唤醒,这其中遇到了debian开机自启动项一直不生效的问题,根据实验怀疑是sh兼容性不好的问题,最后通过使用bash执行解决问题。

我的世界没光的博客 1万+

前导0预测(Leading-Zero Anticipator,LZA)

前导0预测(Leading-Zero Anticipator,LZA) 浮点加法在完成之后会进行尾数规格化移位,而在进行尾数加法时,可以使用前导0预测(Leading-Zero Anticipator,LZA)同时计算移位,前导0预测只发生在一个正数加上一个负数的情况下,电路图如图1所示。 图1 传统LZD算法和LZA算法 1. 基础算法 算法的目标是计算出加法结果序列左边连续0的数量,下文中对...

crw1111111的博客 7400

开机自启脚本示例

#!/bin/sh #chkconfig: 235 99 99 #description: ljk auto script (1, vim /etc/init.d/auto; 2, chmod a+x /etc/init.d/auto; 3, chkconfig --add auto) case "${1}" in start) echo ""${0}" start"; log

chn475111的博客 878

台达PLC DIAdesigner-AX 编程实战:从安装到通信配置

本文详细介绍了台达PLC DIAdesigner-AX编程的实战操作,从软件安装、项目创建到通信配置的全流程。重点讲解了TCP/IP通信设置、库文件管理及常见错误处理,帮助工程师快速掌握台达PLC编程技巧,提升工业自动化项目的开发效率。

weixin_29215391的博客 548

Unity URP热扭曲效果实战:如何让半透明物体也‘动’起来(附完整Shader代码)

本文深入解析Unity URP管线中热扭曲效果无法影响半透明物体的核心原因,并提供一套完整的实战解决方案。通过编写自定义Shader,并巧妙利用URP的Render Objects渲染器功能,成功让指定半透明物体(如粒子特效)也能被扭曲效果影响,从而制作出火焰、热浪等更具视觉冲击力的特效。文末附有完整的Shader代码与进阶优化技巧。

pz890123的博客 506

Linux环境变量配置在/etc/profile文件或/etc/profile.d/中的区别

为什么配置在source /etc/profile中的环境变量没有生效? Linux环境变量配置在~/.bash_profile、/etc/profile、~/.bashrc、/etc/bashrc、/etc/profile.d中有什么区别?什么是 login shell,什么是 no login shell?本文将带你深入了解 profile 运行机制。...

独码乐,不如众码乐,乐享其中 2687

Ardupilot无人船(车)mavros自主控制

rover 4.4。

超维空间科技的博客 3254

开机自启脚本

django程序开机自启脚本

qq_41193005的博客 411

AIGC游戏本地化:用AI实现多语言自动翻译

游戏本地化是游戏全球化战略的关键环节,传统人工翻译方式成本高、周期长。本文旨在探讨如何利用AIGC技术实现高效、准确、低成本的游戏多语言自动翻译解决方案。我们将覆盖从文本翻译到语音合成的完整本地化流程,重点关注AI技术在游戏特定语境下的应用优化。文章首先介绍游戏本地化的核心挑战和AI解决方案,然后深入讲解关键技术原理,接着通过实战项目演示具体实现,最后讨论应用场景和未来趋势。AIGC:人工智能生成内容,指利用AI技术自动生成文本、图像、音频等内容本地化(Localization)

AI 领航者的博客 1347

AIGC算法工程师面试八股文深度解析与进阶指南:揭秘Diffusion Models核心原理与实战技巧

总结来说,Cosine Noise Scheduler 的核心优势在于它能够更巧妙地平衡信号和噪声的比例,在扩散过程的早期阶段更长时间地保留原始图像的细节信息,从而为去噪模型提供一个更友好的学习环境,最终带来更优异的生成质量。🚀

FJN110的博客 354

linux添加nginx启动脚本_Linux—添加开机启动(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_39972151的博客 162

基于 STM32 的智慧图书馆智能控制系统设计与实现

智慧图书馆智能控制系统集成环境调控、安全监控、借阅管理与信息推送功能,通过 STM32 主控芯片联动传感器、执行器及云平台,实现图书馆智能化管理。系统架构分为感知层(传感器)、控制层(STM32 主控)、执行层(继电器 / 显示屏)及云端层(数据交互),支持温度自动调节、灯光自控、火情安防监控、天气推送及 RFID 借还书管理。本系统通过 STM32 实现多传感器融合与设备控制,结合 RFID 与云平台技术,构建了集环境智能调控、安全监控、便捷借阅于一体的智慧图书馆解决方案。

weixin_42300449的博客 2223

linux 运行ctl文件_Linux 添加开机启动方法(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_36118752的博客 664

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

linux 添加服务开机启动,Linux—添加开机启动(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_39996762的博客 505

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

linux手动添加开机启动,Linux—添加开机启动(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_42480540的博客 501

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Linux 添加开机启动方法(服务/脚本)

引用作者:刘_love_田 的文章#

erhisme的专栏 2112

linux 脚本加入开机启动服务,Linux 添加开机启动方法(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_30423863的博客 414

linux添加php开机启动脚本,centos7之添加开机启动服务/脚本

一、添加开机启动脚本#!/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 ...

weixin_29669899的博客 253

Linux服务跟随启动,Linux—添加开机启动(服务/脚本)

系统启动时需要加载的配置文件/etc/profile、/root/.bash_profile/etc/bashrc、/root/.bashrc/etc/profile.d/*.sh、/etc/profile.d/lang.sh/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)一、修改开机启动文件:/etc/rc.local(或者/etc/rc...

weixin_32017501的博客 439
上一篇: turnserver启动时::1的端口绑定失败
下一篇: 什么是“堆”,“栈“,“堆栈“,“队列“,它们的区别
firstcode666
博客等级 码龄5年 53粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址