centos配置开机自启方式:
- 直接在/etc/rc.d/rc.local中添加服务启动命令
- 通过chkconfig配置服务自启动
- Centos7通过systemctl enble 配置服务自启动
方式一
在 /etc/rc.d/rc.local 中添加启动服务的命令:
/etc/rc.d/rc.local脚本会在Centos系统启动时被自动执行,所以可以把需要开机后执行的命令直接放在这里:
$ vim /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
/opt/node_exporter/start.sh
# centos7 中/etc/rc.d/rc.local没有执行权限需要添加权限
$ chmod +x /etc/rc.d/rc.local
注意&