redis linux下的开机启动

参考文章https://www.cnblogs.com/zsg88/p/8323475.html

https://my.oschina.net/luoyedao/blog/535448


 步骤1

在redis/utils找到redis_init_script 将它拷贝到  /etc/init.d 目录并重命名为redis


[root@centos213 utils]# cd /etc/init.d
[root@centos213 init.d]# 
[root@centos213 init.d]# cp /usr/local/redis/redis-4.0.8/utils/redis_init_script  redis
[root@centos213 init.d]# ls
functions  imageService  mysql  netconsole  network  nexus  README  redis  tomcat  vmware-tools

步骤2 编辑redis脚本

vi redis

做以下修改

(1)在脚本的第一行后面添加一行内容如下:

#chkconfig: 2345 80 90

(2) 请根据自己的安装目录修改以下5个参数的实际路径

REDISPORT=6379 #端口

EXEC=/usr/local/bin/redis-server #启动服务的命令路径

CLIEXEC=/usr/local/bin/redis-cli #客户端路径

PIDFILE=/var/run/redis_${REDISPORT}.pid #记录pid(进程id)文件路径

CONF="/etc/redis/${REDISPORT}.conf" #配置文件路径

修改后如下

#chkconfig: 2345 80 90
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis/redis/bin/redis-server
CLIEXEC=/usr/local/redis/redis/bin/redis-cli

PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/redis/redis_6379.conf"

步骤3 .添加 Redis 为开机服务: 

 
[root@centos213 init.d]#  chkconfig --add redis 
[root@centos213 init.d]# 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]'.

mysql          	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
nexus          	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
tomcat         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

4启动服务

[root@centos213 init.d]# service redis start 
/var/run/redis_6379.pid exists, process is already running or crashed

错误原因,我第一次搭建成功后,用这个命令./bin/redis-server ./redis.conf 启动,做开机开机自启动前,使用kill -9 pid杀死了redis服务。并创建了redis_6379.conf文件


因为刚开启redis,所以毫不犹豫的删除掉(rm -rf /var/run/redis_6379.pid)redis的pid号

再启动



成功

 



猜你喜欢

转载自blog.csdn.net/zhou920786312/article/details/80482293