Redis的編譯安裝

Redis 官網:http://redis.io/redis

 

實驗環境:shell

  • OS:centos6數據庫

  • 軟件:redis2.4.4(截至本文的最新版本)centos

測試整個編譯安裝的基本過程以下:ide

 

[1].編譯安裝過程測試

    # wget http://redis.googlecode.com/files/redis-2.4.4.tar.gzthis

    # tar -zxvf redis-2.4.4.tar.gzgoogle

    # mv redis-2.4.4 /usr/local/idea

    # cd /usr/local/redis-2.4.4spa

   ps: 該軟件的編譯安裝不須要執行 ./configure 和make install 命令

    # make

 

    若是看到有如下提示信息:

Hint: To run 'make test' is a good idea ;)

    再執行命令# make test

 

    應該會看到以下信息:

\o/ All tests passed without errors!

Cleanup: may take some time... OK

    上面的提示信息表示:測試沒有錯誤都經過,編譯成功 。

 

[2]. 配置:

 

    # cp src/redis-server /usr/local/bin

    # cp src/redis-benchmark /usr/local/bin

    # cp src/redis-cli /usr/local/bin

    # cp src/redis-check-dump /usr/local/bin

    # cp src/redis-check-aof /usr/local/bin

     這樣之後就能夠直接在shell窗口下調用這些命令了。

 

    複製配置文件redis.conf:

    # mkdir /usr/local/etc/redis

    # cp redis.conf /usr/local/etc/redis

 

    啓動redis:

    # redis-server /usr/local/etc/redis/redis.conf

 

    控制檯會看到以下信息:

[28335] 16 Dec 16:37:41 * Server started, Redis version 2.4.4
[28335] 16 Dec 16:37:41 # 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.
[28335] 16 Dec 16:37:41 * The server is now ready to accept connections on port 6379
[28335] 16 Dec 16:37:41 - 0 clients connected (0 slaves), 717480 bytes in use
[28335] 16 Dec 16:37:46 - 0 clients connected (0 slaves), 717480 bytes in use
[28335] 16 Dec 16:37:51 - 0 clients connected (0 slaves), 717480 bytes in use

    ps:默認配置中redis程序啓動不是之後臺守護進程的模式啓動的

 

[3]. 修改配置文件:/usr/local/etc/redis/redis.conf

 

    具體的參數含義能夠看conf文件中的註釋,測試時只是簡單修改了下面幾個參數:

 

daemonize no => yes 是否後天守護進程
logfile stdout => /var/log/redis.log 日誌文件
dir ./ => /var/db/redis 目錄設置

   ps: 要確保你設置的目錄已經存在 

 

    執行下面的測試命令:

# redis-server /usr/local/etc/redis/redis.conf
# redis-cli 
redis 127.0.0.1:6379> set myblog "sjsky.iteye.com"
OK
redis 127.0.0.1:6379> get myblog
"sjsky.iteye.com"
redis 127.0.0.1:6379> shutdown
redis 127.0.0.1:6379> exit

   能夠看到數據庫的數據文件:

# ls -lh /var/db/redis/
總用量 4.0K
-rw-r--r--. 1 root root 36 12月 16 17:05 dump.rdb

 

   能夠看到redis的日誌文件以下:

# cat /var/log/redis.log 
[28468] 16 Dec 17:04:53 * Server started, Redis version 2.4.4
[28468] 16 Dec 17:04:53 # 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.
[28468] 16 Dec 17:04:53 * DB loaded from disk: 0 seconds
[28468] 16 Dec 17:04:53 * The server is now ready to accept connections on port 6379
[28468] 16 Dec 17:04:53 - 0 clients connected (0 slaves), 717512 bytes in use
[28468] 16 Dec 17:04:58 - 0 clients connected (0 slaves), 717512 bytes in use
[28468] 16 Dec 17:05:01 - Accepted 127.0.0.1:54313
[28468] 16 Dec 17:05:03 - 1 clients connected (0 slaves), 726040 bytes in use
[28468] 16 Dec 17:05:08 - 1 clients connected (0 slaves), 726040 bytes in use
[28468] 16 Dec 17:05:13 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[28468] 16 Dec 17:05:13 - 1 clients connected (0 slaves), 726296 bytes in use
[28468] 16 Dec 17:05:18 - DB 0: 1 keys (0 volatile) in 4 slots HT.
[28468] 16 Dec 17:05:18 - 1 clients connected (0 slaves), 726280 bytes in use
[28468] 16 Dec 17:05:20 # User requested shutdown...
[28468] 16 Dec 17:05:20 * Saving the final RDB snapshot before exiting.
[28468] 16 Dec 17:05:21 * DB saved on disk
[28468] 16 Dec 17:05:21 * Removing the pid file.
[28468] 16 Dec 17:05:21 # Redis is now ready to exit, bye bye...

 

    有關上面日誌中的告警信息的說明:

# 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.

    這個告警信息是因爲當內存分配策略設置爲「0」時,啓動會有警告提示,根據它的提示咱們能夠修改相應的配置文件/etc/sysctl.conf或者是經過sysctl命令設置,使之生效便可。

相關文章
相關標籤/搜索