Linux下启动redis

一、直接启动redis

使用这种启动方式需要一直打开窗口,不能进行其他操作,按 ctrl + c可以关闭窗口。

[root@xxx ~]# cd /usr/local/redis-4.0.6/src
[root@xxx src]# ./redis-server

在这里插入图片描述

二、以后台进程形式启动redis

①设置redis.conf中daemonize为yes,确保守护进程开启,也就是在后台可以运行

 [root@xxx ~]# vim /usr/local/redis-4.0.6/redis.conf

在这里插入图片描述

②指定redis.conf文件启动

[root@xxx ~]# ./redis-server /usr/local/redis-4.0.6/redis.conf

在这里插入图片描述

③关闭redis进程

[root@xxx ~]# ps -aux|grep redis
[root@xxx ~]# kill -9 1350

在这里插入图片描述

三、设置redis开机自启动

①将redis自带的脚本复制到指定目录(/etc/init.d/)的redis文件

[root@xxx ~]# cp /usr/local/redis-4.0.6/utils/redis_init_script /etc/init.d/redis

②修改(/etc/init.d/)redis文件

//在文件最前面加入这个注释
# chkconfig: 2345 10 90
# description: Start and Stop redis
//对下面地址、端口号等进行修改
REDISPORT=6379
EXEC=/usr/local/redis-4.0.6/src/redis-server
CLIEXEC=/usr/local/redis-4.0.6/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid//与redis.conf中保持一致
CONF="/usr/local/redis-4.0.6/redis.conf"

③授予权限

[root@xxx ~]# chkconfig --add redis//添加redis服务
[root@xxx ~]# chkconfig redis on//设为开机启动
[root@xxx ~]# service redis start//开启redis服务
[root@xxx ~]# service redis stop//关闭redis服务

注:启动redis服务时,一般因没有正常关机,可造成如下问题:

[root@xxx ~]# service redisd start
/var/run/redis_6379.pid exists, process is already running or crashed

解决办法:
1:可用安装文件启动:redis-server /etc/redis/6379.conf
2:shutdown -r now 软重启让系统自动恢复下就行了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值