redis的启动方式

redis的启动方式

1.直接启动

进入redis根目录,执行命令:

#加上'&'号使redis以后台程序方式运行

复制代码
./redis-server &

2.通过指定配置文件启动

可以为redis服务启动指定配置文件,例如配置为/etc/redis/6379.conf

进入redis根目录,输入命令:

复制代码
redis-server redis.windows.conf

#如果更改了端口,使用redis-cli客户端连接时,也需要指定端口,例如:

复制代码
redis-cli -p 6380

3.使用redis启动脚本设置开机自启动

启动脚本 redis_init_script 位于位于Redis的 /utils/ 目录下,redis_init_script脚本代码如下:

复制代码
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
 
#redis服务器监听的端口
REDISPORT=6379
 
#服务端所处位置
EXEC=/usr/local/bin/redis-server
 
#客户端位置
CLIEXEC=/usr/local/bin/redis-cli
 
#redis的PID文件位置,需要修改
PIDFILE=/var/run/redis_${REDISPORT}.pid
 
#redis的配置文件位置,需将${REDISPORT}修改为文件名
CONF="/etc/redis/${REDISPORT}.conf"
 
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

根据启动脚本,将修改好的配置文件复制到指定目录下,用root用户进行操作:

复制代码
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf

将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(通常都以d结尾表示是后台自启动服务)。

复制代码
cp redis_init_script /etc/init.d/redisd

设置为开机自启动,直接配置开启自启动 chkconfig redisd on 发现错误: service redisd does not support chkconfig

解决办法,在启动脚本开头添加如下注释来修改运行级别:

复制代码
#!/bin/sh
# chkconfig:   2345 90 10

再设置即可

复制代码
#设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop
相关推荐
Devin~Y几秒前
互联网大厂 Java 面试实录:Spring Boot、MyBatis、Redis、Kafka、Spring Security、RAG 与 MCP 全链路问答
java·redis·kafka·mybatis·spring security·spring mvc·sprint boot
AAA@峥37 分钟前
Ceph 集群配置管理完整指南
运维·数据库·分布式·ceph
旺仔学长 哈哈40 分钟前
基于SpringBoot的在线招聘测评系统的设计与实现----附源码35253+数据库文档
数据库·spring boot·后端·在线招聘
海兰1 小时前
【高速缓存】 RedisVL MCP 运行指南(下)
人工智能·redis·哈希算法·高速缓存
吴声子夜歌1 小时前
MongoDB 4.2——索引(二)
数据库·mongodb·索引
米码收割机1 小时前
【Python】Django恒达科技门户网站(源码+文档)【独一无二】
数据库·python·科技
艾莉丝努力练剑1 小时前
【MYSQL】MYSQL学习的一大重点:基本查询(下)
android·数据库·学习·mysql·面试·八股文
冰暮流星1 小时前
mysql之数据库创建,查询,删除,启用
数据库·mysql·oracle
GIS数据转换器2 小时前
智慧灌区管理平台
大数据·服务器·网络·数据库·人工智能·生活
777VG11 小时前
PostgreSQL +martin将多张表输出成一个 MVT
前端·数据库·postgresql