?一罪佳、安裝gcc依賴
由于 redis 是用 C 語言開發(fā)杠娱,安裝之前必先確認(rèn)是否安裝 gcc 環(huán)境(gcc -v)邀泉,如果沒有安裝唯灵,執(zhí)行以下命令進(jìn)行安裝:
yum install -y gcc
#安裝TCL
yum install -y tcl
二、下載并解壓安裝包
wget http://download.redis.io/releases/redis-5.0.3.tar.gztar-zxvf redis-5.0.3.tar.gz
三达址、cd切換到redis解壓目錄下蔑祟,執(zhí)行編譯
cd redis-5.0.3
make
#或者指定安裝目錄
make install PREFIX=/usr/local/redis
四、啟動(dòng)服務(wù)
#前臺(tái)啟動(dòng)
cd /usr/local/redis/bin/
./redis-server
#后臺(tái)啟動(dòng)
#從 redis 的源碼目錄中復(fù)制 redis.conf 到 redis 的安裝目錄
cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/
#修改 redis.conf 文件沉唠,把 daemonize no 改為 daemonize yes
#后臺(tái)啟動(dòng)
./redis-server redis.conf
#查看redis是否啟動(dòng)
ps -ef | grep redis
測試 redis
# redis
# 127.0.0.1:6379> ping
PONG
# 127.0.0.1:6379>
五疆虚、設(shè)置開機(jī)啟動(dòng)
添加開機(jī)啟動(dòng)服務(wù)
新建文件/etc/systemd/system/redis.service,復(fù)制粘貼以下內(nèi)容:
[Unit]
Description=redis-serverAfter=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server? ?/usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意:ExecStart配置成自己的路徑
設(shè)置開機(jī)啟動(dòng)
systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service
#創(chuàng)建 redis 命令軟鏈接
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
#服務(wù)操作命令
systemctl start redis.service? #啟動(dòng)redis服務(wù)
systemctl stop redis.service? #停止redis服務(wù)
systemctl restart redis.service? #重新啟動(dòng)服務(wù)
systemctl status redis.service? #查看服務(wù)當(dāng)前狀態(tài)
systemctl enable redis.service? #設(shè)置開機(jī)自啟動(dòng)
systemctl disable redis.service? #停止開機(jī)自啟動(dòng)