1. 程式人生 > 資料庫 >Linux安裝Redis實現過程及報錯解決方案

Linux安裝Redis實現過程及報錯解決方案

今天安裝redis出現些之前安裝不曾出現錯誤,一併在此做個記錄

一、安裝redis及出現錯誤

首先下載redis,官方下載地址頁面:https://redis.io/download

我們這裡選擇穩定版6.0.1版本

Linux安裝Redis實現過程及報錯解決方案

正常安裝步驟如下:

[root@localhost ~]# yum install gcc
[root@localhost ~]# cd /usr/local
[root@localhost local]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz
[root@localhost local]# tar -xvf redis-6.0.1.tar.gz
[root@localhost local]# cd /usr/local/redis-6.0.1/
[root@localhost redis-6.0.1]# make PREFIX=/usr/local/redis install

這裡報瞭如下錯誤

make[1]: *** [server.o] 錯誤 1
make[1]: 離開目錄“/usr/redis-6.0.1/src”
make: *** [all] 錯誤 2

server.c:2402:11: 錯誤:‘struct redisServer'沒有名為‘assert_file'的成員
server.assert_file = "<no file>";
^
server.c:2403:11: 錯誤:‘struct redisServer'沒有名為‘assert_line'的成員
server.assert_line = 0;
^
server.c:2404:11: 錯誤:‘struct redisServer'沒有名為‘bug_report_start'的成員

server.bug_report_start = 0;
^
server.c:2405:11: 錯誤:‘struct redisServer'沒有名為‘watchdog_period'的成員
server.watchdog_period = 0;
^
server.c:2411:11: 錯誤:‘struct redisServer'沒有名為‘lua_always_replicate_commands'的成員
server.lua_always_replicate_commands = 1;
^
server.c: 在函式‘restartServer'中:
server.c:2464:32: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
for (j = 3; j < (int)server.maxclients + 1024; j++) {
^
server.c: 在函式‘adjustOpenFilesLimit'中:
server.c:2491:29: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
rlim_t maxfiles = server.maxclients+CONFIG_MIN_RESERVED_FDS;
^
server.c:2497:15: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
server.maxclients = 1024-CONFIG_MIN_RESERVED_FDS;
^
server.c:2529:53: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
unsigned int old_maxclients = server.maxclients;
^
server.c:2530:23: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
server.maxclients = bestlimit-CONFIG_MIN_RESERVED_FDS;
^
server.c:2554:59: 錯誤:‘struct redisServer'沒有名為‘maxclients'的成員
(unsigned long long) bestlimit,server.maxclients);
^
server.c: 在函式‘checkTcpBacklogSettings'中:
server.c:2574:48: 錯誤:‘struct redisServer'沒有名為‘tcp_backlog'的成員
if (somaxconn > 0 && somaxconn < server.tcp_backlog) {
^
server.c:2575:171: 錯誤:‘struct redisServer'沒有名為‘tcp_backlog'的成員
serverLog(LL_WARNING,"WARNING: The TCP backlog setting of %d cannot be enforced because /proc/sys/net /core/somaxconn is set to the lower value of %d.",server.tcp_backlog,somaxconn);

Linux安裝Redis實現過程及報錯解決方案

Linux安裝Redis實現過程及報錯解決方案

Linux安裝Redis實現過程及報錯解決方案

解決辦法:升級gcc版本

[root@localhost redis-6.0.1]# gcc -v # 檢視gcc版本
[root@localhost redis-6.0.1]# yum -y install centos-release-scl # 升級到9.1版本
[root@localhost redis-6.0.1]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@localhost redis-6.0.1]# scl enable devtoolset-9 bash
以上為臨時啟用,如果要長期使用gcc 9.1的話:
[root@localhost redis-6.0.1]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

再執行編譯:

[root@mmjredis redis-6.0.1]# make PREFIX=/usr/local/redis install

安裝成功會出現:Hint: It's a good idea to run 'make test' 😉

Linux安裝Redis實現過程及報錯解決方案

我們執行一下make test來進行測試一下

出現瞭如下錯誤:

[root@localhost redis-6.0.1]# make test
cd src && make test
make[1]: 進入目錄“/usr/redis-6.0.1/src”
CC Makefile.dep
make[1]: 離開目錄“/usr/redis-6.0.1/src”
make[1]: 進入目錄“/usr/redis-6.0.1/src”
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 錯誤 1
make[1]: 離開目錄“/usr/redis-6.0.1/src”
make: *** [test] 錯誤 2

Linux安裝Redis實現過程及報錯解決方案

解決辦法:

[root@localhost redis-6.0.1]# yum install tcl[root@localhost redis-6.0.1]# make test

測試成功如下:

Linux安裝Redis實現過程及報錯解決方案

先執行redis試一下:

[root@localhost redis-6.0.1]# /usr/local/redis-6.0.1/src/redis-server /usr/local/redis-6.0.1/redis.conf
32101:C 13 May 2020 17:01:48.248 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
32101:C 13 May 2020 17:01:48.248 # Redis version=6.0.1,bits=64,commit=00000000,modified=0,pid=32101,just started
32101:C 13 May 2020 17:01:48.248 # Configuration loaded
32101:M 13 May 2020 17:01:48.249 * Increased maximum number of open files to 10032 (it was originally set to 1024).
        _._
      _.-``__ ''-._
   _.-``  `. `_. ''-._      Redis 6.0.1 (00000000/0) 64 bit
 .-`` .-```. ```\/  _.,_ ''-._
 (  ',.-` | `,)   Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|   Port: 6379
 |  `-._  `._  /   _.-'  |   PID: 32101
 `-._  `-._ `-./ _.-'  _.-'
 |`-._`-._  `-.__.-'  _.-'_.-'|
 |  `-._`-._    _.-'_.-'  |      http://redis.io
 `-._  `-._`-.__.-'_.-'  _.-'
 |`-._`-._  `-.__.-'  _.-'_.-'|
 |  `-._`-._    _.-'_.-'  |
 `-._  `-._`-.__.-'_.-'  _.-'
   `-._  `-.__.-'  _.-'
     `-._    _.-'
       `-.__.-'

Linux安裝Redis實現過程及報錯解決方案

二、後臺啟動

簡單修改後臺啟動

[root@localhost redis-6.0.1]# vim redis.conf

daemonize no 改成 daemonize yes

再來執行一下

[root@localhost redis-6.0.1]# /usr/redis-6.0.1/src/redis-server /usr/redis-6.0.1/redis.conf
30385:C 13 May 2020 16:57:58.918 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30385:C 13 May 2020 16:57:58.918 # Redis version=6.0.1,pid=30385,just started
30385:C 13 May 2020 16:57:58.918 # Configuration loaded

後臺執行成功,我們檢視一下,並終止程式

[root@localhost redis-6.0.1]# ps -aux|grep redis| grep -v grep
root 29836 0.0 0.0 162416 7912 ? Ssl 16:56 0:00 /usr/redis-6.0.1/src/redis-server 127.0.0.1:6379
[root@localhost redis-6.0.1]# kill -9 29836

我們這裡用到的是用後臺systemctl啟動redis

首先把redis加入service服務

vim /lib/systemd/system/redis.service

寫入

[Unit]
Description=redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis-6.0.1/src/redis-server /usr/local/redis-6.0.1/etc/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

注意路徑問題,以及PIDFile的路徑對應的是redis-6.0.1/src/redis-server裡面的PIDFile

wq儲存退出即可

接著執行以下

[root@localhost redis-6.0.1]# systemctl enable redis.service # 加入開機啟動

[root@localhost redis-6.0.1]# systemctl is-enabled redis.service # 檢視開機是否啟動成功
enabled

[root@localhost redis-6.0.1]# systemctl start redis #開啟redis服務

[root@localhost redis-6.0.1]# systemctl status redis //檢視redis執行狀態

如果啟動出現問題,可以通過systemctl status redis來檢視日誌修復

Linux安裝Redis實現過程及報錯解決方案

如圖已經啟動成功

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。