Linux安裝Redis

上篇剛裝完MySQL,現在我們再來裝Redis

1、大家先下載Redis安裝包

[root@izbp1g3d9v59h2hak283f2z ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
--2019-12-30 14:24:03--  http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1975750 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.5.tar.gz’

100%[=============================================================================================================================================>] 1,975,750   18.2KB/s   in 2m 14s 

2019-12-30 14:26:19 (14.4 KB/s) - ‘redis-5.0.5.tar.gz’ saved [1975750/1975750]

我是直接通過網絡下載的,大家也可以現在Windows下下載好在通過工具上傳至Linux服務器

2、解壓

[root@izbp1g3d9v59h2hak283f2z ~]# tar -zxf redis-5.0.5.tar.gz 
[root@izbp1g3d9v59h2hak283f2z ~]# ll
total 631756
-rw-r--r-- 1 root root 644930593 Oct  4  2018 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
drwxrwxr-x 6 root root      4096 May 16  2019 redis-5.0.5
-rw-r--r-- 1 root root   1975750 May 16  2019 redis-5.0.5.tar.gz

3、移動

[root@izbp1g3d9v59h2hak283f2z ~]# mv redis-5.0.5 /usr/local/redis
[root@izbp1g3d9v59h2hak283f2z ~]# cd /usr/local/
[root@izbp1g3d9v59h2hak283f2z local]# ll
total 52
drwxr-xr-x   6 root  root  4096 Dec 24 02:24 aegis
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 bin
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 etc
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 games
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 include
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 lib
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 lib64
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 libexec
drwxr-xr-x  10 mysql mysql 4096 Dec 30 11:21 mysql
drwxrwxr-x   6 root  root  4096 May 16  2019 redis
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 sbin
drwxr-xr-x.  6 root  root  4096 Dec 23 16:19 share
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 src
[root@izbp1g3d9v59h2hak283f2z local]# cd redis

4、編譯

進入解壓後的Redis目錄,輸入 make 進行編譯

[root@izbp1g3d9v59h2hak283f2z redis]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/src'
make[1]: Entering directory `/usr/local/redis/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/local/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/usr/local/redis/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings

編譯完成後,發現Redis目錄下會有對應的src、conf等文件夾

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/redis/src'
[root@izbp1g3d9v59h2hak283f2z redis]# ll
total 268
-rw-rw-r--  1 root root 106874 May 16  2019 00-RELEASENOTES
-rw-rw-r--  1 root root     53 May 16  2019 BUGS
-rw-rw-r--  1 root root   2381 May 16  2019 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16  2019 COPYING
drwxrwxr-x  6 root root   4096 Dec 30 14:36 deps
-rw-rw-r--  1 root root     11 May 16  2019 INSTALL
-rw-rw-r--  1 root root    151 May 16  2019 Makefile
-rw-rw-r--  1 root root   6888 May 16  2019 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16  2019 README.md
-rw-rw-r--  1 root root  61797 May 16  2019 redis.conf
-rwxrwxr-x  1 root root    275 May 16  2019 runtest
-rwxrwxr-x  1 root root    280 May 16  2019 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16  2019 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16  2019 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16  2019 sentinel.conf
drwxrwxr-x  3 root root   4096 Dec 30 14:37 src
drwxrwxr-x 11 root root   4096 May 16  2019 tests
drwxrwxr-x  8 root root   4096 May 16  2019 utils

5、安裝 

進入src目錄,執行 make install 命令

[root@izbp1g3d9v59h2hak283f2z redis]# cd src
[root@izbp1g3d9v59h2hak283f2z src]# make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@izbp1g3d9v59h2hak283f2z src]# ll

至此,Linux服務器上已成功安裝Redis

6、部署

爲了方便管理,將Redis文件中的conf配置文件和常用命令移動到統一文件中

1)、創建bin和etc文件

[root@izbp1g3d9v59h2hak283f2z redis]# mkdir etc
[root@izbp1g3d9v59h2hak283f2z redis]# mkdir bin
[root@izbp1g3d9v59h2hak283f2z redis]# ll
total 276
-rw-rw-r--  1 root root 106874 May 16  2019 00-RELEASENOTES
drwxr-xr-x  2 root root   4096 Dec 30 14:41 bin
-rw-rw-r--  1 root root     53 May 16  2019 BUGS
-rw-rw-r--  1 root root   2381 May 16  2019 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16  2019 COPYING
drwxrwxr-x  6 root root   4096 Dec 30 14:36 deps
drwxr-xr-x  2 root root   4096 Dec 30 14:41 etc
-rw-rw-r--  1 root root     11 May 16  2019 INSTALL
-rw-rw-r--  1 root root    151 May 16  2019 Makefile
-rw-rw-r--  1 root root   6888 May 16  2019 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16  2019 README.md
-rw-rw-r--  1 root root  61797 May 16  2019 redis.conf
-rwxrwxr-x  1 root root    275 May 16  2019 runtest
-rwxrwxr-x  1 root root    280 May 16  2019 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16  2019 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16  2019 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16  2019 sentinel.conf
drwxrwxr-x  3 root root   4096 Dec 30 14:39 src
drwxrwxr-x 11 root root   4096 May 16  2019 tests
drwxrwxr-x  8 root root   4096 May 16  2019 utils

 2)、配置文件及常用命令移動

[root@izbp1g3d9v59h2hak283f2z redis]# mv redis.conf /usr/local/redis/etc/
[root@izbp1g3d9v59h2hak283f2z redis]# cd src
[root@izbp1g3d9v59h2hak283f2z src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin/
[root@izbp1g3d9v59h2hak283f2z src]# cd ..
[root@izbp1g3d9v59h2hak283f2z redis]# cd etc/
[root@izbp1g3d9v59h2hak283f2z etc]# ll
total 64
-rw-rw-r-- 1 root root 61797 May 16  2019 redis.conf
[root@izbp1g3d9v59h2hak283f2z etc]# cd ..
[root@izbp1g3d9v59h2hak283f2z redis]# cd bin
[root@izbp1g3d9v59h2hak283f2z bin]# ll
total 32748
-rwxrwxr-x 1 root root     734 May 16  2019 mkreleasehdr.sh
-rwxr-xr-x 1 root root 4365912 Dec 30 14:37 redis-benchmark
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-check-aof
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-check-rdb
-rwxr-xr-x 1 root root 4806248 Dec 30 14:37 redis-cli
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-server

7、啓動服務

進入 bin 目錄 以 etc 目錄下的配置文件作爲 Redis 服務的配置文件

[root@izbp1g3d9v59h2hak283f2z bin]# redis-server /usr/local/redis/etc/redis.conf 
20597:C 30 Dec 2019 15:12:25.112 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
20597:C 30 Dec 2019 15:12:25.112 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=20597, just started
20597:C 30 Dec 2019 15:12:25.112 # Configuration loaded
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 20597
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

20597:M 30 Dec 2019 15:12:25.113 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
20597:M 30 Dec 2019 15:12:25.113 # Server initialized
20597:M 30 Dec 2019 15:12:25.113 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
20597:M 30 Dec 2019 15:12:25.113 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
20597:M 30 Dec 2019 15:12:25.113 * DB loaded from disk: 0.000 seconds
20597:M 30 Dec 2019 15:12:25.113 * Ready to accept connections

redis.conf  配置解析 (vim redis.conf)

daemonize:如需要在後臺運行,把該項的值改爲yes
 
pdifile:把pid文件放在/var/run/redis.pid,可以配置到其他地址
 
bind:指定redis只接收來自該IP的請求,如果不設置,那麼將處理所有請求,在生產環節中最好設置該項

            (設置0.0.0.0 則改爲用iptables來控制訪問權限)
 
port:監聽端口,默認爲6379
 
timeout:設置客戶端連接時的超時時間,單位爲秒
 
loglevel:等級分爲4級,debug,revbose,notice和warning。生產環境下一般開啓notice
 
logfile:配置log文件地址,默認使用標準輸出,即打印在命令行終端的端口上
 
database:設置數據庫的個數,默認使用的數據庫是0
 
save:設置redis進行數據庫鏡像的頻率
 
rdbcompression:在進行鏡像備份時,是否進行壓縮
 
dbfilename:鏡像備份文件的文件名
 
dir:數據庫鏡像備份的文件放置的路徑
 
slaveof:設置該數據庫爲其他數據庫的從數據庫
 
masterauth:當主數據庫連接需要密碼驗證時,在這裏設定
 
requirepass:設置客戶端連接後進行任何其他指定前需要使用的密碼
 
maxclients:限制同時連接的客戶端數量
 
maxmemory:設置redis能夠使用的最大內存
 
appendonly:開啓appendonly模式後,redis會把每一次所接收到的寫操作都追加到appendonly.aof文件中,當redis重新啓動時,會從該文件恢復出之前的狀態
 
appendfsync:設置appendonly.aof文件進行同步的頻率
 
vm_enabled:是否開啓虛擬內存支持
 
vm_swap_file:設置虛擬內存的交換文件的路徑
 
vm_max_momery:設置開啓虛擬內存後,redis將使用的最大物理內存的大小,默認爲0
 
vm_page_size:設置虛擬內存頁的大小
 
vm_pages:設置交換文件的總的page數量
 
vm_max_thrrads:設置vm IO同時使用的線程數量

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章