1、安装 redis
# window版本
https://github.com/microsoftarchive/redis/releases
# 下载 redis
tar -xvzf redis-5.0.5.tar.gz && mv redis-5.0.5 redis
# 安装 redis
cd redis && make && make install
2、初始化脚本
# 复制启动脚本
cp utils/redis_init_script /etc/init.d/redis_6379
# 创建目录
mkdir /etc/redis /var/redis/6379 -p
# 拷贝配置文件
cp redis.conf /etc/redis/6379.conf
# 配置文件内容
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
dir /var/redis/6379
bind 192.168.23.110
3、启动方式
- 手动启动
cd /etc/init.d
./redis_6379 start
- 自动启动
chkconfig redis_6379 on
#vim /etc/init.d/redis_6379
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#加入这两行
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
4、redis 操作命令
# 连接 redis
redis-cli -h 127.0.0.1 -p 6379
# 关闭 redis
redis-cli shutdown
5、持久化配置
- RDB 方式
#vim /etc/redis/6379.conf
save 5 1
- AOF 方式
#vim /etc/redis/6379.conf
appendonly yes
appendfsync everysec
6、docker 方式
version: "3"
services:
redis:
image: daocloud.io/library/redis:3.2.9
ports:
- "6379:6379"
volumes:
- "/usr/local/work/docker/redis:/data"
container_name: redis
privileged: true
entrypoint:
- redis-server