linux環境下(centos 7)安裝redis(4.0.11版本)
以下是我安裝redis的筆記:
首先進入到linux環境需要安裝redis的目錄,我的是/etc/local/hxq
然後 wget http://download.redis.io/releases/redis-4.0.11.tar.gz
解壓到當前目錄:tar -zxvf redis-4.0.11.tar.gz
cd redis-4.0.11
make
make test
這一步如果報這個錯誤You need tcl 8.5 or newer in order to run the Redis test
說明需要下載安裝tcl。
退出到hxq目錄,然後
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar -zxvf tcl8.6.1-src.tar.gz
cd /tcl8.6.1/unix/
sudo ./configure
sudo make
sudo make install
然後退出到hxq目錄,在進入到redis-4.0.11目錄,執行make test
cd src
make install PREFIX=/usr/local/hxq/redis
移動配置檔案到安裝目錄下:
cd ../
mkdir /usr/local/hxq/redis/etc
mv redis.conf /usr/local/hxq/redis/etc
配置redis為後臺啟動
vi /usr/local/hxq/redis/etc/redis.conf
講daemonize改為 daemonize yes,講requirepass改為requirepass 123
預設是沒有設定密碼的,改為後臺啟動的時候,順便把密碼也設定一下。
開啟redis
/usr/local/hxq/redis/bin/redis-server /usr/local/hxq/redis/etc/redis.conf
連線redis客戶端:
./redis-cli -h 127.0.0.1 -p 6379 -a "123"
ping返回pong,表示成功。
關閉防火牆:
//臨時關閉
systemctl stop firewalld
//禁止開機啟動
systemctl disable firewalld
//停止redis服務
./redis-cli -h 127.0.0.1 -p 6379 -a "123" shutdown
//修改redis.conf
註釋掉 #bind 127.0.0.1 開啟外網訪問(這個版本是預設已經註釋掉的,有的版本可能需要手動註釋掉)