CentOS搭建Redis
2017-09-26 本文已影响0人
天一生水_AL
1. 下载并解压redis文件
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
tar xzf redis-4.0.2.tar.gz
2. 编译安装
cd redis-4.0.2
make install
3. 创建运行文件
#数据文件存储路径
mkdir /var/redis/data
#log文件存储 xxx为端口号
mkdir /var/redis/log
touch /var/redis/log/redis_xxx.log
#pid文件存储 xxx为端口号
mkdir /var/redis/run
touch /var/redis/run/redis_xxx.pid
4. 修改配置文件并copy到 /etc/redis/redis_xxx.conf , xxx为端口号
其中要修改:
bind 0.0.0.0 允许所有ip连接
port xxx 设置端口号
daemonize yes 后台运行
pidfile /var/redis/run/redis_xxx.pid
logfile /var/redis/log/redis_xxx.log
dir /var/redis/data
requirepass 123456 设置连接密码
5. 修改启动文件 并复制到 /etc/init.d/redisd
启动文件在: /redis-4.0.2/utils/redis_init_script
修改头部: xxx为端口号
#!/bin/sh
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
#
REDISPORT=xxx
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/reids/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis_${REDISPORT}.conf"
6. 启动redis
- 设置开机启动
chkconfig redisd on
- 启动和停止
# 启动redis
service redisd start
# 关闭redis
service redisd stop
6. 测试连接 xxx为端口号, 123456为密码
redis-cli -h 127.0.0.1 -p xxx -a 123456