在centos7.5服務器上按照官方發布的安裝方式並不能進行正確的安裝,現收集並整理如下安裝方式,親測有效
1.安裝依賴
yum install -y cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make tcl
2.需要先安裝gcc新版才能編譯
centos7 默認的 gcc 版本小於 5.3 無法編譯
sudo yum -y install centos-release-scl
sudo yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
// 臨時生效,退出 shell 或重啟會恢復原 gcc 版本
sudo scl enable devtoolset-9 bash
// 永久生效
sudo echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
3.下載最新版本redis
wget http://download.redis.io/releases/redis-6.0.5.tar.gz
- 解壓安裝
tar -zxvf redis-6.0.5.tar.gz
cd redis-6.0.5
make
make test
make install
編譯文件會復制到/usr/local/bin目錄下
5.修改redis.conf文件並復制到etc目錄
bind 127.0.0.1 #根據情況是否需要遠程訪問去掉注釋
requirepass 123456 #修改密碼
protected-mode no # 關閉protected-mode模式,此時外部網絡可以直接訪問
sudo mkdir /etc/redis
sudo cp redis.conf /etc/redis/
6.在 /etc/systemd/system新建service文件
sudo vi /etc/systemd/system/redis.service
內容如下:
[Unit]
Description=Redis
After=network.target
[Service]
#Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecReload=/usr/local/bin/redis-server -s reload
ExecStop=/usr/local/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意Type=forking不注釋掉 服務無法啟動
使服務自動運行
sudo systemctl daemon-reload
sudo systemctl enable redis
啟動服務
sudo systemctl restart redis
sudo systemctl status redis
作者:_江邊城外_
鏈接:https://www.jianshu.com/p/aa01d4055a6f
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。