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 软重启让系统自动恢复下就行了

相关推荐
chlk12312 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑12 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件13 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统