稷然如此

  • 首页
  • 文章分类
    • AI
    • Android
    • Java
    • Shell
    • Vue
    • C#
    • Python
    • 数据库
    • 组件
    • 其他
    • Game
  • 常用命令
    • Docker
    • Git
    • Linux
  • 操作系统
    • CentOS
    • Ubuntu
    • Windows
    • Kylin
  • 工具
    • IntelliJ IDEA
    • Visual Studio Code
稷然如此
不积跬步,无以至千里
  1. 首页
  2. 操作系统
  3. CentOS
  4. 正文

Linux 启动 Redis

2023年7月11日 832点热度 0人点赞

1.下载

https://github.com/redis/redis/releases

2.解压

tar -zxvf redis-7.0.5.tar.gz

3.进入src目录

cd /home/install_package/redis-7.0.5/src

4.编译到指定目录

make install PREFIX=/opt/redis

5.复制配置文件

从源码目录复制redis.conf配置文件到编译后bin目录
cp /home/install_package/redis-7.0.5/redis.conf /opt/redis/bin/

6.编辑redis.conf配置文件

cd /opt/redis/bin
vim redis.conf

7.修改配置文件

将redis.conf配置文件属性daemonize=no改为yes,标识通过守护进程方式启动
daemonize no >> daemonize yes
将redis.conf配置文件属性bind=127.0.0.1注释掉,要不外部不可以连接
bind 127.0.0.1 -::1 >> #bind 127.0.0.1 -::1
将redis.conf配置文件属性protected-mode=yes改为no,要不外部不可以连接
protected-mode yes >> protected-mode no

8.可选设置密码

9.启动服务

cd /opt/redis/bin
./redis-server redis.conf

10.查看进程状态

ps -ef |grep redis

11.关闭redis

cd /opt/redis/bin
./redis-cli shutdown

12.设置开机启动

1.进入init.d目录
cd /etc/init.d
2.创建服务文件
vim redis
3.编写脚本
#!/bin/bash
#chkconfig: 2345 63 37
#description: redis service
#processname: redis-7.0.5
export REDIS_HOME=/opt/redis
case $1 in
	start)
		$REDIS_HOME/bin/redis-server $REDIS_HOME/bin/redis.conf > /dev/null 2>&1 &
		echo "redis is started"
		;;
	stop)
		$REDIS_HOME/bin/redis-cli shutdown
		echo "redis is stopped"
		;;
	restart)
		$REDIS_HOME/bin/redis-cli shutdown
		echo "redis is stopped"
		sleep 1
		$REDIS_HOME/bin/redis-server $REDIS_HOME/bin/redis.conf > /dev/null 2>&1 &
		echo "redis is started"
		;;
	*)
	echo "start|stop|restart"
	;;
esac
exit 0
4.修改文件权限:
chmod 777 redis
5.添加或删除服务
添加:
chkconfig --add redis
删除:
chkconfig --del redis
6.启动、停止或重启服务
启动:
service redis start
停止:
service redis stop
重启:
service redis restart
7.设置开启或关闭开机启动
开启:
chkconfig redis on
关闭:
chkconfig redis off
8.查看es进程,验证是否已启动
ps -ef | grep redis
标签: CentOS Redis
最后更新:2025年3月26日

Akim

犇 骉 Java、C#、Python、Go、Android、MiniProgram、Bootstrap、Vue2

点赞
< 上一篇
下一篇 >
文章目录
  • 1.下载
  • 2.解压
  • 3.进入src目录
  • 4.编译到指定目录
  • 5.复制配置文件
  • 6.编辑redis.conf配置文件
  • 7.修改配置文件
  • 8.可选设置密码
  • 9.启动服务
  • 10.查看进程状态
  • 11.关闭redis
  • 12.设置开机启动

Copyright © 2025 aianran.com All Rights Reserved.

免责申明 | 隐私政策 | 服务条款 | 关于我们

黔ICP备2023008200号-1

贵公网安备 52010202003594号