Redis的安裝及集羣的搭建

1.查看CentOS版本號

[root@localhost redis-cluster]# uname -a
Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost redis-cluster]# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

2.下載和解包

[root@localhost local]# cd software
[root@localhost software]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz
--2019-04-13 16:44:18--  http://download.redis.io/releases/redis-4.0.2.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... 302 Found
Location: http://117.128.6.16/cache/download.redis.io/releases/redis-4.0.2.tar.gz?ich_args2=523-14164406036346_113e7a0347822da565c9642e3e7b68c9_10001002_9c896129d5c0f0d5913b518939a83798_280e902604d61efc4e826f1739c22ef6 [following]
--2019-04-13 16:44:18--  http://117.128.6.16/cache/download.redis.io/releases/redis-4.0.2.tar.gz?ich_args2=523-14164406036346_113e7a0347822da565c9642e3e7b68c9_10001002_9c896129d5c0f0d5913b518939a83798_280e902604d61efc4e826f1739c22ef6
Connecting to 117.128.6.16:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1713990 (1.6M) [application/x-gzip]
Saving to: ‘redis-4.0.2.tar.gz’

100%[=======================================================================================================================================================================================================>] 1,713,990   1.47MB/s   in 1.1s   

2019-04-13 16:44:20 (1.47 MB/s) - ‘redis-4.0.2.tar.gz’ saved [1713990/1713990]

[root@localhost software]# ll
total 1676
-rw-r--r--. 1 root root 1713990 Sep 21  2017 redis-4.0.2.tar.gz
[root@localhost software]# tar -zxvf redis-4.0.2.tar.gz  -C /usr/local

2.安裝gcc環境
由於Redis是由C語言編寫的,它的運行需要C環境,因此需要先安裝gcc。安裝命令是yum install gcc-c++

3.編譯安裝
我們到/usr/local/redis-4.0.2目錄下,要運行make和make install命令就要有Makefile這個文件,我們可以看到是有這個文件的。

[root@localhost local]# cd /usr/local/redis-4.0.2
[root@localhost redis-4.0.2]# ll
total 280
-rw-rw-r--.  1 root root 131381 Sep 21  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 Sep 21  2017 BUGS
-rw-rw-r--.  1 root root   1815 Sep 21  2017 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 Sep 21  2017 COPYING
drwxrwxr-x.  6 root root    192 Apr 13 09:30 deps
-rw-rw-r--.  1 root root     11 Sep 21  2017 INSTALL
-rw-rw-r--.  1 root root    151 Sep 21  2017 Makefile
-rw-rw-r--.  1 root root   4223 Sep 21  2017 MANIFESTO
-rw-rw-r--.  1 root root  20530 Sep 21  2017 README.md
-rw-rw-r--.  1 root root  57765 Apr 13 12:39 redis.conf
-rwxrwxr-x.  1 root root    271 Sep 21  2017 runtest
-rwxrwxr-x.  1 root root    280 Sep 21  2017 runtest-cluster
-rwxrwxr-x.  1 root root    281 Sep 21  2017 runtest-sentinel
-rw-rw-r--.  1 root root   7606 Sep 21  2017 sentinel.conf
drwxrwxr-x.  3 root root   8192 Apr 13 09:31 src
drwxrwxr-x. 10 root root    167 Sep 21  2017 tests
drwxrwxr-x.  8 root root   4096 Sep 21  2017 utils
[root@localhost redis-4.0.2]# 

4.先進行編譯

[root@localhost redis-4.0.2]# make

5.在進行安裝

[root@localhost redis-4.0.2]# make install PREFIX=/usr/local/redis

安裝完之後,我們到/usr/local目錄下,可以看到redis目錄,我們進入redis目錄,在該目錄下可以看到bin目錄,進入到bin目錄可以看到redis的客戶端和服務端,如下所示。

6.啓動redis服務端
第一種啓動方式是直接使用./redis-server命令啓動,如下所示(可以看到默認端口是6379),只不過這種啓動會佔用終端,如果我們按Ctrl+C就會停止redis-server。

[root@localhost bin]# ./redis-server
36770:C 13 Apr 17:21:27.055 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
36770:C 13 Apr 17:21:27.055 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=36770, just started
36770:C 13 Apr 17:21:27.055 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
36770:M 13 Apr 17:21:27.055 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 36770
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

36770:M 13 Apr 17:21:27.056 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
36770:M 13 Apr 17:21:27.056 # Server initialized
36770:M 13 Apr 17:21:27.056 # 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.
36770:M 13 Apr 17:21:27.056 # 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.
36770:M 13 Apr 17:21:27.056 * DB loaded from disk: 0.000 seconds
36770:M 13 Apr 17:21:27.056 * Ready to accept connections

第二種啓動方式是使用配置文件啓動(也叫後端啓動),我們需要先到redis的安裝目錄下把redis.conf文件複製一份到/usr/local/redis/bin目錄下。如下所示。

[root@localhost bin]# ll
total 21844
-rw-r--r--. 1 root root     175 Apr 13 17:21 dump.rdb
-rwxr-xr-x. 1 root root 2451944 Apr 13 09:31 redis-benchmark
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-check-aof
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-check-rdb
-rwxr-xr-x. 1 root root 2606168 Apr 13 09:31 redis-cli
-rw-r--r--. 1 root root   57765 Apr 13 12:54 redis.conf
lrwxrwxrwx. 1 root root      12 Apr 13 09:31 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-server

[root@localhost redis-4.0.2]# ll
total 280
-rw-rw-r--.  1 root root 131381 Sep 21  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 Sep 21  2017 BUGS
-rw-rw-r--.  1 root root   1815 Sep 21  2017 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 Sep 21  2017 COPYING
drwxrwxr-x.  6 root root    192 Apr 13 09:30 deps
-rw-rw-r--.  1 root root     11 Sep 21  2017 INSTALL
-rw-rw-r--.  1 root root    151 Sep 21  2017 Makefile
-rw-rw-r--.  1 root root   4223 Sep 21  2017 MANIFESTO
-rw-rw-r--.  1 root root  20530 Sep 21  2017 README.md
-rw-rw-r--.  1 root root  57765 Apr 13 12:39 redis.conf
-rwxrwxr-x.  1 root root    271 Sep 21  2017 runtest
-rwxrwxr-x.  1 root root    280 Sep 21  2017 runtest-cluster
-rwxrwxr-x.  1 root root    281 Sep 21  2017 runtest-sentinel
-rw-rw-r--.  1 root root   7606 Sep 21  2017 sentinel.conf
drwxrwxr-x.  3 root root   8192 Apr 13 09:31 src
drwxrwxr-x. 10 root root    167 Sep 21  2017 tests
drwxrwxr-x.  8 root root   4096 Sep 21  2017 utils
[root@localhost redis-4.0.2]# 

[root@localhost redis-4.0.2]# cp redis.conf /usr/local/redis/bin

[root@localhost redis-4.0.2]# cd /usr/local/redis/bin
[root@localhost bin]# ll
total 21844
-rw-r--r--. 1 root root     175 Apr 13 17:21 dump.rdb
-rwxr-xr-x. 1 root root 2451944 Apr 13 09:31 redis-benchmark
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-check-aof
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-check-rdb
-rwxr-xr-x. 1 root root 2606168 Apr 13 09:31 redis-cli
-rw-r--r--. 1 root root   57765 Apr 13 12:54 redis.conf
lrwxrwxrwx. 1 root root      12 Apr 13 09:31 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 5742760 Apr 13 09:31 redis-server
[root@localhost bin]# 

下面我們需要簡單修改下redis.conf文件,把daemonize的值由默認的no修改爲yes,這個配置是指定是否在後臺運行。如下圖所示。

在這裏插入圖片描述
下面使用後臺啓動

[root@localhost bin]# ./redis-server redis.conf

要想查看是否正常啓動了,可以使用ps -ef|grep redis或ps aux | grep redis,如下所示,可以看到已經正常啓動了。

[root@localhost bin]# ps -ef|grep redis
root      11056      1  0 04:35 ?        00:00:00 ./redis-server 127.0.0.1:6379
root      11061  10933  0 04:35 pts/0    00:00:00 grep --color=auto redis

至此redis的安裝完成了

下面開始搭建集羣

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