1. 程式人生 > >CentOS7安裝Redis教程

CentOS7安裝Redis教程

一、Redis編譯環境

執行sudo yum install gcc-c++,執行過程中有兩個地方選擇y,不用其餘操作。

[[email protected] ~]# yum install gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.......

Total download size: 54 M
# 第一處選擇
Is this ok [y/d/N]: y
Downloading packages:

.......
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <
[email protected]
>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 # 第二處選擇 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded ....... Complete!

二、下載原始碼

  建立目錄/home/redis,進入目錄執行 
  ` wget http://download.redis.io/releases/redis-3.2.11.tar.gz    `
[[email protected] redis]# wget http://download.redis.io/releases/redis-3.2.11.tar.gz
--2017-12-13 06:30:49--  http://download.redis.io/releases/redis-3.2.11.tar.gz
Connecting to ----:----... connected.
Proxy request sent, awaiting response... 200 OK
Length: 1550452 (1.5M) [application/x-gzip]
Saving to: ‘redis-3.2.11.tar.gz’

100%[============================>] 1,550,452   51.7KB/s   in 16s  

2017-12-13 06:31:06 (95.6 KB/s) - ‘redis-3.2.11.tar.gz’ saved [1550452/1550452]

三、編譯原始碼

# 解壓原始碼
tar -xzvf redis-3.2.11.tar.gz 

# 進入Redis原始碼目錄
cd redis-3.2.11/

# 編譯Redis(編譯完成後,會在src下產生redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-rdb、redis-sentinel共6個可執行的檔案)
make MALLOC=libc
--------------------- 

四、安裝Redis

# 進入src目錄
cd src/

# 執行安裝命令
[[email protected] src]# make install
Hint: It's a good idea to run 'make test' ;)
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
# 安裝tcl8.5(此步可忽略,為執行make test準備)
yum install tcl

# 執行make test(此步可忽略)
[[email protected] src]# make test
\o/ All tests passed without errors!

Cleanup: may take some time... OK
--------------------- 

五、Redis自動啟動

設定Redis開機自動啟動

# 進入Redis的util目錄
cd /home/redis/redis-3.2.11/utils

# 執行./install_server.sh(執行過程中全部Enter,使用預設配置,如果想修改,可依次自行修改)
[[email protected] utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

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/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/bin/redis-server
Cli Executable : /usr/local/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!

# 檢視Redis程序
[[email protected] utils]# ps -ef|grep redis
root     10280     1  0 08:15 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
--------------------- 

六、Redis開啟遠端訪問

# 查詢Redis配置(注意不是安裝目錄下的redis.conf)
# 開啟第五步設計的Redis配置,預設為:/etc/redis/6379.conf
# 修改配置檔案如下幾項,其它保持不變
daemonize yes
#bind 127.0.0.1 (註釋,不限制IP)
protected-mode no

# 重啟服務
[[email protected] redis-3.2.11]# service redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...

# 關閉防火牆(生產禁止直接關閉,應設定對應規則,此處不延伸)
# 停止firewall
systemctl stop firewalld.service

# 禁止firewall開機啟動
systemctl disable firewalld.service
--------------------- 

七、遠端訪問Redis

Redist配置好後可通過客戶端和程式進行訪問,本人通過Redis Desktop Manager進行訪問。
在這裡插入圖片描述