- 下载redis
cd /usr/local
wget http://download.redis.io/redis-stable.tar.gz
- 解压编译安装
tar -xzvf redis-stable.tar.gz
cd redis-stable && make
cd src make install PREFIX=/usr/local/redis ##PREFIX 指定安装目录
cd ..
mkdir /usr/local/redis/etc ##创建配置文件存放目录
mv redis.conf /usr/local/redis/etc
- 启动
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
-
配置使用systemctl方式启动
在 /etc/systemd/system 下新建redis.service,并添加一下内容
以下内容中 /usr/local/redis 路径修改成自己安装的redis路径
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/usr/local/redis/bin/redis-server -s reload
ExecStop=/usr/local/redis/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存成功后 sudo systemctl daemon-reload 载入服务配置文件
- systemctl的一些命令
systemctl enable redis # 开机自启redis服务
systemctl disable redis # 取消开机自启
systemctl start redis # 启动redis服务
systemctl stop redis # 停止服务
systemctl restart redis # 重新启动服务
systemctl status redis # 查看服务当前状态