1.檢查安裝依賴程序
//安裝需要的運行環(huán)境,防止安裝出錯
yum -y install gcc automake autoconf libtool make
yum install gcc-c++
yum install -y tcl
2.獲取安裝文件
mkdir /www
cd /www
#獲取安裝文件
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
#解壓?
tar -xvf redis-5.0.7.tar.gz
3.進(jìn)入目錄、編譯、安裝
cd /www/redis-5.0.7/
make test
make
cd??/www/redis-5.0.7/src
make PREFIX=/www/redis install
cp /www/redis-5.0.7/redis.conf /www/redis
mkdir /www/redis/log
4.修改配置文件
#開啟后臺啟動
lmonize yes (no -> yes)
# 你可以綁定單一接口,注掉,可以允許任何機器訪問
# bind 127.0.0.1
#設(shè)置redis連接密碼,配置了連接密碼,客戶端在連接redis時需要通過auth 123465 命令提供密碼,
#requirepass 123456
#設(shè)置模式非保護(hù)模式,
protected-mode no
#數(shù)據(jù)存放路徑,rdb存放的路徑
dir /usr/local/redis/log
#指定持久化方式,
appendonly yes
5.創(chuàng)建服務(wù)啟動配置文件
vi /lib/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/www/redis/bin/redis-server /www/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
創(chuàng)建軟連接
ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
剛剛配置的服務(wù)需要讓systemctl能識別,就必須刷新配置
systemctl daemon-reload
redis服務(wù)加入開機啟動
systemctl enable redis
6.常用命令集合
禁止開機啟動
systemctl disable redis
啟動
systemctl start redis
重啟
systemctl restart redis
停止
systemctl stop redis
查看狀態(tài)
systemctl status redis
啟動Redis
/www/redis/bin/redis-server /www/redis/redis.conf