centos设置服务跟随系统启动

本文介绍了如何使用chkconfig命令查看和管理CentOS系统的服务状态,包括添加服务到启动项,确保服务在特定运行级别下自动启动。通过编辑/etc/rc.d/rc.local文件也可以实现开机启动服务。

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

chkconfig 命令

使用chkconfig 或者 chkconfig –list就可以看出当前系统已经设置的各个服务在各个运行级别下的开闭状态

[root@VM-0-14-centos /]# chkconfig servicename on/off

[root@VM-0-14-centos /]# chkconfig --list


Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

bt             	0:off	1:off	2:on	3:on	4:on	5:on	6:off
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm-56     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm-70     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm-72     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm-80     	0:off	1:off	2:on	3:on	4:on	5:on	6:off
pure-ftpd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
redis          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

添加到chkconfig

[root@VM-0-14-centos /]#  chkconfig add php-fpm-80 
[root@VM-0-14-centos /]# chkconfig php-fpm-80 on
[root@VM-0-14-centos /]# chkconfig --list

php-fpm-80     	0:off	1:off	2:on	3:on	4:on	5:on	6:off

2-5都开启证明服务会跟随系统启动

方法2修改/etc/rc.d/rc.local这个文件
[root@VM-0-14-centos /]#  vi /etc/rc.d/rc.local

!/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 contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/local/qcloud/irq/net_smp_affinity.sh >/tmp/net_affinity.log 2>&1
/usr/local/qcloud/cpuidle/cpuidle_support.sh &> /tmp/cpuidle_support.log
/usr/local/qcloud/rps/set_rps.sh >/tmp/setRps.log 2>&1
/usr/local/qcloud/irq/virtio_blk_smp_affinity.sh > /tmp/virtio_blk_affinity.log 2>&1
/usr/local/qcloud/gpu/nv_gpu_conf.sh >/tmp/nv_gpu_conf.log 2>&1

将启动的路径加进去
列如:

/usr/local/nginx/sbin/nginx 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值