1. 程式人生 > >centOS 中安裝 Redis

centOS 中安裝 Redis

路徑 mman tom bugs over ons red enc jpg

之前安裝過了 jdk,mysql,tomcat,這次安裝 Redis,

1 . 首先得安裝 c環境,用來編譯 Redis源碼,

[[email protected] lib64]# clear
[[email protected] lib64]# yum install gcc-c++

接下來大約要下載 22MB 這個樣子,很快就能下載完,

2 . 準備 redis 源碼文件

利用 SSH 將 redis 拷貝到 centOS 中的 /soft 中,然後我在 /usr/local/ 下新建了一個 redis_home 的目錄,將 redis 解壓到這個裏面,解壓好之後查看一下,

[[email protected] soft]# cd /usr/local/redis_home/
[[email protected] redis_home]# ll
總用量 4
drwxrwxr-x. 6 root root 4096 4月   1 2015 redis-3.0.0
[root@msym redis_home]#

3 . 編譯 redis 源碼

解壓好,在進入 redis 目錄中,使用 make 指令進行編譯,大約需要一分鐘:

[[email protected] redis_home]# cd redis-3.0.0/
[[email protected] redis-3.0.0]# make

編譯完成後就可以安裝了,執行下面命令:(命令中的 redis 是真正的安裝目錄)

[[email protected] redis-3.0.0]# make PREFIX=/usr/local/redis install

4 . 啟動服務(前端啟動)

然後進行 redis 目錄,進入 bin 目錄,運行 redis-server:

[[email protected] redis-3.0.0]# cd ../
[[email protected] redis_home]#
cd ../ [[email protected] local]# cd redis [[email protected] redis]# ll 總用量 4 drwxr-xr-x. 2 root root 4096 7月 2 08:38 bin [root@msym redis]# cd bin [[email protected] bin]# ll 總用量 15440 -rwxr-xr-x. 1 root root 4588886 7月 2 08:38 redis-benchmark -rwxr-xr-x. 1 root root 22193 7月 2 08:38 redis-check-aof -rwxr-xr-x. 1 root root 45411 7月 2 08:38 redis-check-dump -rwxr-xr-x. 1 root root 4691801 7月 2 08:38 redis-cli lrwxrwxrwx. 1 root root 12 7月 2 08:38 redis-sentinel -> redis-server -rwxr-xr-x. 1 root root 6450321 7月 2 08:38 redis-server [root@msym bin]#

運行 redis :(./和redis之間沒有空格,是緊挨著的)

[[email protected] bin]# ./redis-server 
10010:C 02 Jul 08:44:03.199 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
10010:M 02 Jul 08:44:03.200 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ‘‘-._                                             
      _.-``    `.  `_.  ‘‘-._           Redis 3.0.0 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._                                   
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 10010
  `-._    `-._  `-./  _.-‘    _.-|`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io        
  `-._    `-._`-.__.-‘_.-‘    _.-|`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |                                  
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
      `-._    `-.__.-‘    _.-‘                                       
          `-._        _.-‘                                           
              `-.__.-10010:M 02 Jul 08:44:03.216 # Server started, Redis version 3.0.0
10010:M 02 Jul 08:44:03.217 # 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.
10010:M 02 Jul 08:44:03.218 # 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.
10010:M 02 Jul 08:44:03.219 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
10010:M 02 Jul 08:44:03.219 * The server is now ready to accept connections on port 6379

這樣 redis 服務器就啟動了。

在 SSH 客戶端下再開啟一個命令行窗口,進入redis的bin目錄,運行redis-cli,用作客戶端,

技術分享

如果將服務器的命令關閉或者按下Ctrl + c,就是關閉服務器了,接下來在後臺啟動 redis 服務器,

5 . 啟動服務器(後端啟動)

進入到之前的 redis_home 目錄中redis源碼所在目錄:

找到 redis.conf ,把它拷貝到 redis/bin目錄下,(其實拷到哪裏都可以,只要知道他的路徑就可以,這裏是為了方便)

[[email protected] redis]# cd /usr/local/redis_home/
[[email protected] redis_home]# ll
總用量 4
drwxrwxr-x. 6 root root 4096 4月   1 2015 redis-3.0.0
[root@msym redis_home]# cd redis-3.0.0/
[[email protected] redis-3.0.0]# ll
總用量 144
-rw-rw-r--.  1 root root 25890 4月   1 2015 00-RELEASENOTES
-rw-rw-r--.  1 root root    53 4月   1 2015 BUGS
-rw-rw-r--.  1 root root  1439 4月   1 2015 CONTRIBUTING
-rw-rw-r--.  1 root root  1487 4月   1 2015 COPYING
drwxrwxr-x.  6 root root  4096 7月   2 08:36 deps
-rw-rw-r--.  1 root root    11 4月   1 2015 INSTALL
-rw-rw-r--.  1 root root   151 4月   1 2015 Makefile
-rw-rw-r--.  1 root root  4223 4月   1 2015 MANIFESTO
-rw-rw-r--.  1 root root  5201 4月   1 2015 README
-rw-rw-r--.  1 root root 41403 4月   1 2015 redis.conf    【我在這裏】
-rwxrwxr-x.  1 root root   271 4月   1 2015 runtest
-rwxrwxr-x.  1 root root   280 4月   1 2015 runtest-cluster
-rwxrwxr-x.  1 root root   281 4月   1 2015 runtest-sentinel
-rw-rw-r--.  1 root root  7109 4月   1 2015 sentinel.conf
drwxrwxr-x.  2 root root  4096 7月   2 08:37 src
drwxrwxr-x. 10 root root  4096 4月   1 2015 tests
drwxrwxr-x.  5 root root  4096 4月   1 2015 utils
[root@msym redis-3.0.0]#

拷貝一份到 redis/bin下:

[[email protected] redis-3.0.0]# cp redis.conf /usr/local/redis/bin/
[[email protected] redis-3.0.0]# cd ../../redis/bin
[[email protected] bin]# ll
總用量 15488
-rw-r--r--. 1 root root      35 7月   2 09:03 dump.rdb
-rwxr-xr-x. 1 root root 4588886 7月   2 08:38 redis-benchmark
-rwxr-xr-x. 1 root root   22193 7月   2 08:38 redis-check-aof
-rwxr-xr-x. 1 root root   45411 7月   2 08:38 redis-check-dump
-rwxr-xr-x. 1 root root 4691801 7月   2 08:38 redis-cli
-rw-r--r--. 1 root root   41403 7月   2 09:10 redis.conf
lrwxrwxrwx. 1 root root      12 7月   2 08:38 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 6450321 7月   2 08:38 redis-server
[root@msym bin]#

然後 vim 編輯 redis.conf 文件:

將其中的一個 daemonize no 改為 daemonize yes,即後臺運行;

在下次啟動的時候,指定 redis.conf 文件,就能後端啟動了,

[[email protected] bin]# ./redis-server redis.conf 
[[email protected] bin]#

這樣就後端啟動了 redis 服務器了。

獲取之前存儲的字符串:

[[email protected] bin]# ./redis-server redis.conf 
[[email protected] bin]# ./redis-cli 
127.0.0.1:6379> get username
"msym"
127.0.0.1:6379>

6 . 關閉 redis 服務器:(先Ctrl + c 或者 exit 退出客戶端,再關閉服務器)

[[email protected] bin]# ./redis-cli shutdown

centOS 中安裝 Redis