1.安装
下载redis https://download.redis.io/releases/redis-6.2.6.tar.gz 或直接wget
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6/
make && make install
后面会修改这个文件 redis_init_script
cp utils/redis_init_script /etc/init.d/
2.配置
cp redis.conf /usr/local/redis
cd /usr/local/redis
1. 设置后台运行 daemonize yes
vim redis.conf
2.设置工作路径(可以省略)
mkrid db
3.设置允许远程访问
4.修改初始化脚本
cd /etc/init.d/
vim /etc/init.d/redis_init_script
CONF="/etc/redis/${REDISPORT}.conf" ——> CONF="/usr/local/redis/redis.conf"
chmod +x /etc/init.d/redis_init_script
sh /etc/init.d/redis_init_script start
ps -ef|grep redis
redis-cli
成功
5.开机自启
方法一:chkconfig
vim /etc/init.d/redis_init_script
添加以下chkconfig脚本
#chkconfig: 22345 10 90
#description: Start and Stop redis
方法二:设置systemd方式
vim /etc/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target
[Service]
Type=forkin
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/usr/local/bin/redis-server -s reload
ExecStop=/usr/local/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq保存
重启redis
systemctl daemon-reload
启动redis:
systemctl start redis
停止redis:
systemctl stop redis
设置redis开机启动:
systemctl enable redis
完!
|