Centos7安裝Redis
一、安裝gcc依賴
由于 redis 是用 C 語言開發(fā),安裝之前必先確認(rèn)是否安裝 gcc 環(huán)境(gcc -v)滚粟,如果沒有安裝晾匠,執(zhí)行以下命令進(jìn)行安裝
[root@localhost local]# yum install -y gcc
二呀癣、下載并解壓安裝包
[root@localhost local]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz
[root@localhost local]# tar -zxvf redis-5.0.3.tar.gz
三食磕、cd切換到redis解壓目錄下冗恨,執(zhí)行編譯
[root@localhost local]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make
四答憔、安裝并指定安裝目錄
[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis
五、啟動(dòng)服務(wù)
5.1前臺(tái)啟動(dòng)
[root@localhost redis-5.0.3]# cd /usr/local/redis/bin/
[root@localhost bin]# ./redis-server
5.2后臺(tái)啟動(dòng)
從 redis 的源碼目錄中復(fù)制 redis.conf 到 redis 的安裝目錄
[root@localhost bin]# cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/
修改 redis.conf 文件掀抹,把 daemonize no 改為 daemonize yes
[root@localhost bin]# vi redis.conf
image
后臺(tái)啟動(dòng)
[root@localhost bin]# ./redis-server redis.conf
image
六虐拓、設(shè)置開機(jī)啟動(dòng)
添加開機(jī)啟動(dòng)服務(wù)
[root@localhost bin]# vi /etc/systemd/system/redis.service
復(fù)制粘貼以下內(nèi)容:
[Unit]
Description=redis-server
After=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)
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start redis.service
[root@localhost bin]# systemctl enable redis.service
已經(jīng)完成了,下面是測(cè)試代碼傲武,可直接重啟服務(wù)器測(cè)試是否開機(jī)啟動(dòng)了蓉驹。
創(chuàng)建 redis 命令軟鏈接
[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
測(cè)試 redis
image
服務(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)
代碼改變一切!