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

相关推荐
色空大师9 分钟前
【debug调试详解-idea】
java·ide·intellij-idea·调试·远程调试
程序猿阿越9 分钟前
AutoMQ源码(一)读、写、Compaction
java·后端·源码
ywl47081208728 分钟前
jwt生产token,简单版helloworld
java·数据库·spring
未若君雅裁33 分钟前
生产问题排查与性能瓶颈定位:日志、监控、链路追踪、压测与Arthas
java·web安全
器灵科技40 分钟前
AI视频工具实测:Seedance/可灵/HappyHorse谁最能打?
java·运维·数据库·人工智能·github
南部余额1 小时前
RabbitMQ 进阶:延迟队列完全指南
java·分布式·spring·rabbitmq
phltxy1 小时前
Spring AI Agents 智能体模式实战
java·人工智能·spring
摇滚侠1 小时前
MyBatis 入门到项目实战 特殊 SQL 的执行 34-37
java·sql·mybatis
phltxy2 小时前
Spring AI 可观测性与 Zipkin 实战
java·人工智能·spring
兰令水2 小时前
leecodecode【面试150】【2026.6.13打卡-java版本】
java·算法·leetcode