centos7下redis6的安裝


redis的安裝

安裝環境

  • redis-6.0.6
  • centos 7

下載與解壓

下載地址:https://redis.io/download

下載至/usr/local目錄下,並解壓

# cd /usr/local # wget wget http://download.redis.io/releases/redis-6.0.6.tar.gz # tar -zxvf redis-6.0.6.tar.gz 
  • 1
  • 2
  • 3

如果沒有安裝wget,先安裝yum install -y wget

安裝

make之前確保安裝了gcc,未安裝則需安裝yum install -y gcc

# cd redis-6.0.6 # make # make install PREFIX=/usr/local/redis 
  • 1
  • 2
  • 3

具體安裝過程可以查詢redis-6.0.6目錄下的README.md文件。

make命令時linux提供的一個編譯命令(類似java中的javac命令),它會在當前目錄下查找Makefile文件,根據里面的內容進行安裝,與執行maven的mvn命令時,會去查找當前目錄下的pom.xml類似。

安裝過程中可能會報一個如下的錯誤:

server.c: In function ‘main’: server.c:5011:11: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ server.sentinel_mode = checkForSentinelMode(argc,argv); ^ server.c:5028:15: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ if (server.sentinel_mode) { ^ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

需要升級GCC版本

#升級到 5.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命令啟用只是臨時的,退出xshell或者重啟就會恢復到原來的gcc版本。 #如果要長期生效的話,執行如下: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

先運行make distclean清理上次make失敗的文件和目錄,再次make。

安裝成系統服務

配置redis環境變量:

# vi /etc/profile 增加如下內容 export REDIS_HOME=/usr/local/redis export PATH=$PATH:$REDIS_HOME/bin # source /etc/profile 
  • 1
  • 2
  • 3
  • 4
  • 5

進入utils目錄執行注冊服務腳本install_server.sh

# cd utils # ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server ./install_server.sh: line 82: 3: command not found Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/redis/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/redis/bin/redis-server Cli Executable : /usr/local/redis/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

一個服務器上可以使用這個腳本安裝多個redis實例(進程),每個實例都運行的是同一份腳本,但是都擁有不同的數據目錄、配置文件、日志文件。

運行腳本后默認會啟動redis。

以后就可以使用系統服務的命令來操作redis了:

# systemctl stop redis_6379 # systemctl status redis_6379 # systemctl start redis_6379 
  • 1
  • 2
  • 3

運行腳本install_server.sh可能會報如下錯誤:

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry! 
  • 1
  • 2

打開install_server.sh,注釋掉下面的內容:

#_pid_1_exe="$(readlink -f /proc/1/exe)" #if [ "${_pid_1_exe##*/}" = systemd ] #then # echo "This systems seems to use systemd." # echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!" # exit 1 #fi #unset _pid_1_exe 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

redis.conf配置

下面來看一下/etc/redis/6379.conf中配置:

開啟守護進程模式

daemonize yes 
  • 1

daemonize設置yes或者no區別:

  • yes:代表開啟守護進程模式,redis會在后台運行,並將進程pid號寫入至redis.conf選項pidfile設置的文件中。
  • no:啟動將進入redis的命令行界面,exit或者關閉連接工具(putty,xshell等)都會導致redis進程退出。

去除bind的ip,注釋掉下面這一行,否則無法使用遠程連接,只能本地連接redis。

# bind 127.0.0.1 
  • 1

關閉保護模式,將protected-mode的yes改為no,也是開啟遠程連接。

protected-mode no
  • 1

運行客戶端

# redis-cli 127.0.0.1:6379> set hello world OK 127.0.0.1:6379> get hello "world"


免責聲明!

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



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