阿里雲安裝Redis教程與相關問題


Redis

Redis 安裝

  • 本文基於阿里雲服務器 centos7 系統

1.gcc 安裝

-- 執行如下命令
1. yum install cpp  
2. yum install binutils
3. yum install glibc-kernheaders
4. yum install glibc-common
5. yum install glibc-devel
6. yum install gcc
7. yum install make

-- 備注
安裝成功的話會提示:Complete
原先已安裝完成的會提示:Nothing todo

2.tcl 安裝

Step01.

在 /usr/local/ 目錄下創建自己的文件夾
cd usr/local/ 
mkdir matrix/  -- 目錄名自定義
cd matrix/

Step02.

1.下載 tcl
wget http://downloads.sourceforge.net/tcl/tcl8.6.3-src.tar.gz

2.解壓文件
tar -zxvf tcl8.6.3-src.tar.gz

3.修改文件夾名稱
mv tcl8.6.3 tcl

4.進入tcl目錄
cd tcl/

Step03.

按以下順序執行命令
cd unix/
./configure
make
make install

3.redis 安裝

# 回到 /usr/local/matrix/ 目錄下
1.下載資源
wget http://download.redis.io/releases/redis-6.0.3.tar.gz

2.解壓
tar xzf redis-6.0.3.tar.gz

3.切換Redis目錄
cd redis-6.0.3

4.安裝
4.1 make
make 成功會顯示如下信息
Hint: It's a good idea to run 'make test' ;)

4.2 make test
make test 成功顯示如下信息
\o/ All tests passed without errors!

Cleanup: may take some time... OK

4.3 make install
redis 安裝成功
Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

5.檢測是否安裝成功
5.1啟動 redis
(1)src/redis-server &  -- &:表示使redis以后台程序方式運行
(2)redis-server /usr/local/kencery/redis/redis.conf 

5.2 檢測redis默認端口是否在使用中,如在使用則安裝程。
netstat -ntlp grep 6379

5.3 測試
src/redis-cli
-- 進行key設值讀值檢測

5.4 關閉 redis
src/redis-cli shutdown

6. 修改redis.conf配置
vi redis.conf

-- 添加密碼,找到 requirepass 
requirepass ****(添加自己的密碼)

-- 設置后台開啟
daemonize yes

-- 外部訪問
bind 0.0.0.0

7.修改配置 重啟Redis驗證
auth pwd -- 密碼訪問redis
exit -- 退出 redis-cli

4.防火牆設置

由於centos需自行設置,所以redis其他配置完成后還無法訪問的話,check 一下防火牆端口設置。

有的同學可能發現 阿里雲服務器安全配置和redis.conf 文件都已配置好了,但是發現還是無法連接Redis,此時檢查下服務器的端口是否開放

-- 查看端口列表
firewall-cmd --list-port

-- 添加所需開放的redis端口 6479
firewall-cmd --zone=public --add-port=6379/tcp --permanent

5.遇到的問題

問題一:

You need tcl 8.5 or newer in order to run the Redis test make.............

解決辦法:

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
cd  /usr/local/tcl8.6.1/unix/  
sudo ./configure  
sudo make  
sudo make install 

問題二:

...............

server.c:5170:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
          ^
server.c:5170:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
                                  ^
server.c:5171:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
    serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
                                                                                                                                                                           ^
server.c:5174:31: error: ‘struct redisServer’ has no member named ‘server_cpulist’
redisSetCpuAffinity(server.server_cpulist);
                          ^
server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3789:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘iAmMaster’:
server.c:4966:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/local/redis-6.0.3/src'
make: *** [all] Error 2

解決辦法:

# 查看gcc版本是否在5.3以上,centos7.6默認安裝4.8.5
gcc -v
# 升級gcc到5.3及以上,如下:
升級到gcc 9.3:
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
需要注意的是scl命令啟用只是臨時的,退出shell或重啟就會恢復原系統gcc版本。
如果要長期使用gcc 9.3的話:
 
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
這樣退出shell重新打開就是新版的gcc了
以下其他版本同理,修改devtoolset版本號即可。

6.Redis 卸載

1.刪除目錄
rm -rf /usr/local/matrix/redis

2.刪除redis相關的命令腳本
rm -rf /usr/bin/redis-*

7.阿里雲配置安全規則

因需要外部訪問服務器上的 Redis 服務,當作開發測試使用,需進行配置

添加Redis配置規則

Step01.

實例

Step02.

配置規則

Step03. (我這里已經配置好了)

1

Step04. 選擇Redis 保存即可

Redis 安全規則

Step05. 完成以上設置后使用 telnet 命令測試訪問是否已通

telent ip port


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM