CentOS 添加开机启动脚本

本文介绍了一种通过编写shell脚本实现一键启动多种IT服务的方法,包括Nginx、PHP-FPM、Elasticsearch等。该脚本简化了服务器部署流程,并通过设置执行权限和系统启动项确保服务开机自动启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

生成脚本内容


# start nginx
# chkconfig 2345 10 90
/usr/local/nginx/sbin/nginx 
# start php
/usr/local/sbin/php-fpm
# start es
nohup /usr/local/elasticsearch-6.4.0/bin/elasticsearch & 
# start redis
nohup /usr/local/redis-4.0.10/src/redis-server ../redis.conf & 
# start mongodb
nohup /usr/local/mongodb/mongodb_3.6.5/bin/mongod --dbpath /usr/local/mongodb/mongodb_3.6.5/data --bind_ip 172.25.50.122 --port 27017 2>&1  &
# start mysql
nohup mysqld --defaults-file=/etc/my.cnf -u root 2>&1 &


添加脚本执行权限


chmod +x autostart.sh


配置启动项


chkconfig --add autostart.sh
chkconfig autostart.sh on
chkconfig --list

异常


service autostart.sh does not support chkconfig

在脚本的第二行添加 chkconfig 2345 10 90
#服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值