编译安装:
- 下载redis-5.0.8.tar.gz,下载到
/usr/local/src
- 安装依赖:
yum install gcc gcc-c++ tcl
- 编译:
make
- 安装(可以选择指定或不指定目录前缀):
make PREFIX=/opt/redis/redis-5.0.8 install
。不指定前缀默认安装到/usr/local/bin
启动配置:
- 开放外网访问:在配置文件中找到
bind 127.0.0.1
,注释掉这一行 - 设置密码或关闭保护模式:在开启外网访问且没有设置密码的情况下,保护模式会禁止外网访问
- (建议)设置密码:
requirepass xxxxxxxx
- (不建议)关闭保护模式:
protected-mode yes
—>protected-mode no
- (建议)设置密码:
- (可选)修改端口:
port 6400
- 为配置systemd做准备:
daemonize yes
pidfile /var/run/redis_6400.pid
logfile "notice.log"
supervised systemd
注册systemd服务:
- 在/etc/systemd/system下新建
xxx.service
文件 - 加载配置文件:
systemctl daemon-reload
- 配置开机启动:
systemctl enable xxx.service
- 启动redis服务:
systemctl start xxx.service
service配置文件:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=root
Type=forking
WorkingDirectory=/root/redis-data/single-6400/
ExecStart=/usr/local/bin/redis-server /root/redis-conf/single.6400.conf
ExecStop=/usr/local/bin/redis-cli -p 6400 shutdown
Restart=always
[Install]
WantedBy=multi-user.target