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

相关推荐
hgz071016 小时前
Redis多实例部署与主从架构
redis
Yyyy4821 天前
Ubuntu安装Jenkis
linux·运维·ubuntu
zhuzewennamoamtf1 天前
Linux SPI设备驱动
android·linux·运维
春日见1 天前
在虚拟机上面无法正启动机械臂的控制launch文件
linux·运维·服务器·人工智能·驱动开发·ubuntu
松涛和鸣1 天前
Linux Makefile : From Basic Syntax to Multi-File Project Compilation
linux·运维·服务器·前端·windows·哈希算法
Predestination王瀞潞1 天前
JDK安装及环境变量配置
java·linux·开发语言
再睡一夏就好1 天前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
小小药1 天前
09-vmware配置虚机连接互联网-nat模式
linux·运维·centos
Bright Xu1 天前
Qemu 安装 LoongArch架构 Fedora Remix F42 Linux系统
linux·loongarch·国产cpu
莫白媛1 天前
Linux创作笔记综合汇总篇
linux·运维·笔记