Docker
- 创建文件夹,用于数据持久化
mkdir -p /data/docker-storage/your-redis/conf
mkdir -p /data/docker-storage/your-redis/data
- 创建自定义配置文件
wget -P /data/docker-storage/your-redis/conf/ 'http://download.redis.io/redis-stable/redis.conf'
vim /data/docker-storage/your-redis/conf/redis.conf
protected-mode no
requirepass yourpassword
maxmemory 4GB
maxmemory-policy volatile-lru
appendonly yes
- 启动容器
docker run -d \
--name your-redis \
--restart=always \
-p 6379:6379 \
-v /data/docker-storage/your-redis/conf/redis.conf:/etc/redis/redis.conf \
-v /data/docker-storage/your-redis/data:/data \
redis:7 \
redis-server /etc/redis/redis.conf
CentOS 7
软件:redis-6.2.6.tar.gz
准备
- 安装依赖
yum install gcc
安装
-
下载二进制包
- 浏览器下载:https://redis.io/download
- wget下载:
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
-
安装
tar -xzvf redis-6.2.6.tar.gz mv redis-6.2.6 /usr/local/redis cd /usr/local/redis make
-
配置环境变量
cat << EOF >> /etc/profile # redis export PATH=/usr/local/redis/src:\$PATH EOF source /etc/profile
配置
-
配置
ln -s /usr/local/redis/redis.conf /etc/ vim /etc/redis.conf bind 0.0.0.0 daemonize yes dir /data/redis requirepass 123456 maxmemory 4GB maxmemory-policy volatile-lru
-
创建文件夹
mkdir -p /data/redis
启动
-
添加启动服务
cat << EOF > /usr/lib/systemd/system/redis.service [Unit] Description=Redis After=network.target [Service] Type=forking ExecStart=/usr/local/redis/src/redis-server /etc/redis.conf [Install] WantedBy=multi-user.target EOF
-
启动
systemctl enable redis.service systemctl start redis.service