您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何开启redis

2025/5/12 15:20:53发布21次查看
redis的启动方式
1.直接启动
进入redis根目录,执行命令:         (推荐学习:redis视频教程)
#加上‘&’号使redis以后台程序方式运行./redis-server &
2.通过指定配置文件启动
可以为redis服务启动指定配置文件,例如配置为/etc/redis/6379.conf
进入redis根目录,输入命令:
./redis-server /etc/redis/6379.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/rediscp 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
更多redis相关技术文章,请访问redis入门教程栏目进行学习!
以上就是如何开启redis的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product