CentOS环境上Redis的安装与配置
- 源码安装
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
- yum安装gcc依赖
yum install gcc
- 解压
tar -zxvf redis-4.0.6.tar.gz
mv redis-4.0.6 redis
- 编译安装
cd redis
make MALLOC=libc
cd src/
make && make install
- 直接启动redis
./redis-server
- 以后台进程方式启动redis
- 修改redis.conf文件,将daemonize no修改为daemonize yes,并设置密码requirepass的值
- 指定redis.conf文件启动
./redis-server /usr/local/redis/redis.conf
- 关闭redis进程
- 使用ps -aux | grep redis查看redis进程
ps -aux | grep redis
- 使用kill命令杀死进程
kill pid(进程id)
- 设置redis开机自启动
在/etc目录下新建redis目录
cd /etc
mkdir redis
cp /usr/local/redis/redis.conf /etc/redis/6379.conf
cp /usr/local/redis/utils/redis_init_script /etc/init.d/redisd
设置redis开机自启动
cd /etc/init.d
chkconfig redisd on
[root@iZ8vb3utiu7gwez7zb7f2fZ init.d]# chkconfig redisd on
service redisd does not support chkconfig
[root@iZ8vb3utiu7gwez7zb7f2fZ init.d]#
- redisd不支持chkconfig,使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出(redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10)
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
再次执行开机自启命令
chkconfig redisd on
9.服务形式启动和关闭redis
#启动
service redisd start
#停止
service redisd stop
#关闭
redis-cli SHUTDOWN
网友评论