安装准备
Redis下载地址:Redis官网
- 将redis的gz包传送至主机
- tar zxvf 解压至/usr/local/redis目录
该步骤可以忽略
## 存放可执行文件
[root@alycentos redis]# mkdir bin
## 存放配置文件
[root@alycentos redis]# mkdir etc
[root@alycentos redis]# mv ../redis.conf /usr/local/redis/etc/
[root@alycentos src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentine ../bin
文件赋权
## 改变redis文件夹所属(可忽略)
[root@alycentos src]# chown redis:redis /usr/local/redis/*
编译
- 进入redis目录,执行make命令
- 进入redis/src目录,执行make命令
至此,redis已安装完毕
配置
Redis配置
日志文件(启动日志等)
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "/usr/local/redis/log/redis.log"
后台运行
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
pid文件路劲
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
pidfile /var/run/redis_6379.pid
连接密码
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass redis
systemctl 开启自启
[root@alycentos /]# cd usr/lib/systemd/system
[root@alycentos system]# vim redis-server.service
redis-server.service添加如下内容:
[Unit]
Description=Redis Server Manager
After=network.target remote-fs.target nss-lookup.target
[Service]
## 配置用户与用户组
group=redis
user=redis
## forking 后台运行
Type=forking
## 指定pid(进程id)文件
PIDFile=/var/run/redis_6379.pid
## 指定启动与停止运行脚本
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecStop=/usr/local/redis/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
运行命令:
## 重新加载systemctl配置
[root@alycentos system]# systemctl daemon-reload
## 开机自启
[root@alycentos system]# systemctl enable redis-server.service
## 将redis-cli建立软连接,已至于可以直接运行redis-cli
[root@alycentos system]# ln /usr/local/redis/bin/redis-cli /usr/bin/redis
问题
1.无法保存库文件
解决办法(可能):
[root@alycentos bin]# chmod 755 /usr/local/redis/bin/dump.rdb