Linux 下软件开机自启动
Linux下将Apache(httpd)新增为系统服务及开机自启动
参考 https://www.cnblogs.com/rnckty/p/4560608.h...
1、 查看一下/etc/init.d/下是否存在httpd这个服务
ls /etc/init.d/ | grep httpd 如果没有执行下一步
2、将自己安装目录下的apachect1复制到该目录下并改为httpd
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
3、执行 chkconfig --add httpd 目的是想新增所制定的系统服务 但是会出现以下警告:
[root@server ~]# chkconfig --add httpd
service httpd does not support chkconfig
这里说的是httpd服务不支持chkconfig , 添加支持: vi /etc/init.d/httpd 在 #!/bin/sh 下添加这两句:
#chkconfig:345 85 15
#description:Start and stop the Apache HTTP Server
最终结果为:
[root@server ~]# vi /etc/init.d/httpd
#!/bin/sh
#
#chkconfig:345 85 15
#
#description:Start and stop the Apache HTTP Server
#
4> 执行:
chkconfig --add httpd
chkconfig httpd on 就可以添加成功了
5>查看一下是否添加成功:
[root@server ~]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysql 自启动
1,将服务文件复制一份到init.d下,并重命名为mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2,对文件赋予执行权限
chmod +x /etc/init.d/mysqld 或 chmod 777 /etc/init.d/mysqld
3,增加mysqld服务
chkconfig --add mysqld
4,查询mysqld服务情况
chkconfig --list mysqld
#mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 默认的运行级别为2,3,4,5
5,如果3,4,5 为off:
chkconfig --level 345 mysqld on
6,重启服务器验证:reboot
redis开机自启动
1.设置redis.conf中daemonize为yes,确保守护进程开启,也就是在后台可以运行.
#vi编辑redis安装目录里面的redis.conf文件
vi /usr/redis/redis-3.2.4/redis.conf
2.复制redis配置文件(启动脚本需要用到配置文件内容,所以要复制)
#1.在/etc下新建redis文件夹
[root@localhost /]# mkdir /etc/redis
#2.把安装redis目录里面的redis.conf文件复制到/etc/redis/6379.conf里面,6379.conf是取的文件名称,启动脚本里面的变量会读取这个名称,所以要是redis的端口号改了,这里也要修改
[root@localhost redis]# cp /usr/redis/redis-3.2.4/redis.conf /etc/redis/6379.conf
3.复制redis启动脚本
#1.redis启动脚本一般在redis根目录的utils,如果不知道路径,可以先查看路径
[root@localhost redis]# find / -name redis_init_script
/usr/redis/redis-3.2.4/utils/redis_init_script
#2.复制启动脚本到/etc/init.d/redis文件中
[root@localhost redis]# cp /usr/redis/redis-3.2.4//utils/redis_init_script /etc/init.d/redis
4.修改启动脚本参数
[root@localhost redis]# vi /etc/init.d/redis
#在/etc/init.d/redis文件的头部添加下面两行注释代码,也就是在文件中#!/bin/sh的下方添加
# chkconfig: 2345 10 90
# description: Start and Stop redis
同时还要修改参数,指定redis的安装路径
5.启动redis
打开redis命令:service redis start
关闭redis命令:service redis stop
设为开机启动:chkconfig redis on
设为开机关闭:chkconfig redis off
本作品采用《CC 协议》,转载必须注明作者和本文链接