大家好,我是Tester1991,一枚普通測試工程師,熱愛生活,熱愛分享!
$ wget http://download.redis.io/releases/redis-6.0.8.tar.gz
$ tar xzf redis-6.0.8.tar.gz
$ cd redis-6.0.8
$ make
安裝過程中如果出現如下錯誤:
serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
^
server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
if (!server.masterhost) {
^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5118: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: 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:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/src/redis-6.0.1/src'
make: *** [install] Error 2
出現上面錯誤的原因是redis6.0+以上安裝需要gcc版本5.3及以上。
檢視當前gcc版本
gcc -v
我們發現阿里雲伺服器上面,centos7系統gcc版本預設為4.8.5。
所以我們需要升級gcc版本。
//升級gcc到9以上
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
還需要執行下面命令,二者任選其一
//臨時將此時的gcc版本改為9
scl enable devtoolset-9 bash
//或永久改變
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
執行完上述操作後,執行gcc -v命令,我們會發現gcc版本成功升級到了9.1.1。接下來我們繼續執行make安裝redis6.0+,應該就不會出現什麼問題。
redis6.0+安裝成功後,我們如何驗證redis服務是否正常?
啟動伺服器端
src/redis-server
如上圖,我們發現redis服務已經正常啟動了。
redis伺服器端已經啟動成功,我們如何進行使用者端連線呢?
位置:redis安裝路徑下面redis.conf檔案
修改redis.conf組態檔
1.daemonize設定成yes
2.註釋掉bind 127.0.0.1 新增bind 0.0.0.0
3.protected-mode yes 改為 protected-mode no
經過上述的設定,我們現在完全可以使用redis使用者端進行連線我們的阿里雲上面的redis服務了。
Redis使用者端我推薦大家使用AnotherRedisDesktopManager這個開源工具。
https://github.com/qishibo/AnotherRedisDesktopManager
AnotherRedisDesktopManager支援通過工具直接開啟redis命令使用者端。
import redis
pool = redis.ConnectionPool(host='xxx', port='6379', decode_responses=True)
r = redis.Redis(host='xxx', port='6379', decode_responses=True, password='xxx')
print(r.get('name'))
import redis.clients.jedis.Jedis;
public class RedisTest {
public static void main(String[] args) {
Jedis jedis = new Jedis("xxx", 6379);
jedis.auth("root");
System.out.println("連線成功");
//檢視服務是否執行
System.out.println("服務正在執行: " + jedis.ping());
System.out.println("redis 儲存的字串為: " + jedis.get("name"));
}
}
如果您覺得我的文章幫助了您,後續我會持續分享軟體測試相關知識,本篇部落格實戰視訊後續我錄製好會上傳,歡迎大家一起學習測試知識,一起分享!