Redis安装
2021-05-07 本文已影响0人
若熙笔记
一、Redis安装
下载:
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
解压:
tar xzvf redis-5.0.7.tar.gz
进入目录:
cd redis-5.0.7/
编译:
make
安装:
cd src
make install PREFIX=/usr/local/redis
二、Redis相关配置
移动配置文件到安装目录下:
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
配置redis为后台启动:
vi /usr/local/redis/etc/redis.conf
# 将daemonize no 改成daemonize yes
三、Redis环境变量
修改/etc/profile文件:
vim /etc/profile
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
重新加载/etc/profile文件:
source /etc/profile 或者 . /etc/profile
四、Redis开机启动
编辑/etc/rc.local文件:
vi /etc/rc.local
#在里面添加内容:意思就是开机调用这段开启redis的命令
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
五、启动redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
六、添加开机启动服务
添加redis.service服务文件:
vim /etc/systemd/system/redis.service
[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
设置开机启动:
systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service