因爲 redis 是用 C 語言開發,安裝以前必先確認是否安裝 gcc 環境(gcc -v),若是沒有安裝,執行如下命令進行安裝redis
[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
[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
[root@localhost redis-5.0.3]# cd /usr/local/redis/bin/ [root@localhost bin]# ./redis-server
從 redis 的源碼目錄中複製 redis.conf 到 redis 的安裝目錄apache
[root@localhost bin]# cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/
修改 redis.conf 文件,把 daemonize no 改成 daemonize yesbash
[root@localhost bin]# vi redis.conf測試
後臺啓動spa
[root@localhost bin]# ./redis-server redis.conf.net
添加開機啓動服務rest
[root@localhost bin]# vi /etc/systemd/system/redis.service
複製粘貼如下內容:
code
[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配置成本身的路徑 server
設置開機啓動blog
[root@localhost bin]# systemctl daemon-reload [root@localhost bin]# systemctl start redis.service [root@localhost bin]# systemctl enable redis.service
建立 redis 命令軟連接
[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
測試 redis
服務操做命令
systemctl start redis.service #啓動redis服務 systemctl stop redis.service #中止redis服務 systemctl restart redis.service #從新啓動服務 systemctl status redis.service #查看服務當前狀態 systemctl enable redis.service #設置開機自啓動 systemctl disable redis.service #中止開機自啓動