centos设置服务开机自动启动的方法有很多种。下面介绍如何通过chkconfig命令添加启动时自动启动的脚本。编写脚本autostart.sh(这里以启动redis服务为例),脚本内容如下:`#!/bin/sh#chkconfig:23458090#description:autostartscriptpowerbyhttps://www.上马园。com#rediscd/data1/redis-server/data1/redis/redis.conf`脚本的第一行“#!/bin/sh”告诉系统使用的shell;脚本第二行“#chkconfig:23458090”表示在2/3/4/5运行级别启动,启动序号(S80),关机序号(K90);脚本第三行表示服务的描述信息注意:第二行和第三行一定要写,负责的会出现如下“serviceautostart.shdoesnotsupportchkconfig”之类的错误。将编写的autostart.sh脚本移动到/etc/rc.d/init.d/目录下,并赋予脚本可执行权限`chmod+xautostart.sh`将脚本添加到自动启动项目`chkconfig--addautostart.shchkconfigautostart.shon`
