標籤:源碼redis安裝
##### 安裝redis-server #####
# 建立運行使用者
useradd redis -s /sbin/nologin -M
# 上傳軟體到指定位置,我的軟體儲存位置為
mkdir -p /server/tools/
# 解壓,配置,編譯,安裝
cd /server/tools/tar -zxf redis-3.0.5.tar.gz cd redis-3.0.5make PREFIX=/usr/local/redismake PREFIX=/usr/local/redis install
# 配置redis環境變數
echo ‘ ‘ >> /etc/profile echo ‘PATH for redis-server‘ >> /etc/profile echo ‘export PATH=/usr/local/redis/bin/:$PATH‘ >> /etc/profile tail -3 /etc/profilesource /etc/profileecho $PATH
# 或者(重啟失效)
export PATH=/usr/local/redis/bin/:$PATHecho $PATH
# 建立設定檔,資料,日誌等相關目錄,並拷貝設定檔
# 建立規範的目錄結構有助於行成良好習慣,提高效率
mkdir -p /usr/local/redis/confmkdir -p /usr/local/redis/datamkdir -p /usr/local/redis/logscp redis.conf /usr/local/redis/conf/cd /usr/local/redis/conf/tree /usr/local/redis
# 到此redis基本配置便已完成,可以使用redis初始配置進行啟動
# 啟動命令
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf &
# 查看啟動狀態,進程和連接埠
ps -ef |grep redisnetstat -anptl |grep redis
# 測試及使用
# 用戶端串連命令為:
/usr/local/redis/bin/redis-cli -p 6379[[email protected] redis]# redis-cli -p 6379127.0.0.1:6379> set a 1OK127.0.0.1:6379> get a "1"127.0.0.1:6379> set b 2OK127.0.0.1:6379> set c 3OK127.0.0.1:6379> keys *1) "c"2) "a"3) "b"127.0.0.1:6379> exit
# 以上為簡單測試,驗證安裝正確與否
# 安全關閉redis
/usr/local/redis/bin/redis-cli shutdown
# 關閉redis時,資料預設會儲存在啟動redis時候所在的位置,儲存為dump.rdb
-------- 簡單最佳化redis --------- 
# 以預設配置啟動redis-server會出現以下警告資訊:不影響使用,
# 不過以筆者的習慣自然不會容忍此等警告資訊的存在:
[[email protected] redis]# redis-server /usr/local/redis/conf/redis.conf &[1] 4570[[email protected] redis]# [4570] 07 Dec 03:54:50.938 * Increased maximum number of open files to 10032 (it was originally set to 1024).                _._                                                             _.-``__ ‘‘-._                                                   _.-``    `.  `_.  ‘‘-._           Redis 3.0.5 (00000000/0) 64 bit  .-`` .-```.  ```\/    _.,_ ‘‘-._                                    (    ‘      ,       .-`  | `,    )     Running in stand alone mode |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379 |    `-._   `._    /     _.-‘    |     PID: 4570  `-._    `-._  `-./  _.-‘    _.-‘                                    |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                   |    `-._`-._        _.-‘_.-‘    |           http://redis.io          `-._    `-._`-.__.-‘_.-‘    _.-‘                                    |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                   |    `-._`-._        _.-‘_.-‘    |                                    `-._    `-._`-.__.-‘_.-‘    _.-‘                                         `-._    `-.__.-‘    _.-‘                                                 `-._        _.-‘                                                         `-.__.-‘                                               [4570] 07 Dec 03:54:50.939 # Server started, Redis version 3.0.5[4570] 07 Dec 03:54:50.939 # 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.[4570] 07 Dec 03:54:50.939 # 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.[4570] 07 Dec 03:54:50.939 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.[4570] 07 Dec 03:54:50.939 * The server is now ready to accept connections on port 6379
# 根據開機記錄提示需要最佳化一些核心的參數,按提示操作:
echo never > /sys/kernel/mm/transparent_hugepage/enabledcat /sys/kernel/mm/transparent_hugepage/enabledecho 511 > /proc/sys/net/core/somaxconncat /proc/sys/net/core/somaxconnecho "vm.overcommit_memory = 1" >>/etc/sysctl.confsysctl -p
# 以上操作重啟失效,可以按下操作配置下次開機生效,順便設定redis開機自啟動
echo " " >> /etc/rc.localecho "# redis-server by zs in $(date +%F)" >> /etc/rc.localecho "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.localecho "echo 511 > /proc/sys/net/core/somaxconn" >>/etc/rc.localecho "/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf" >> /etc/rc.localtail -5 /etc/rc.local
# 繼續最佳化設定檔
vim /usr/local/redis/conf/redis.conf
# 在設定檔中尋找以下關鍵字,可以按照以下內容修改:
daemonize yes                                # 是否後台運行,yes為後台運行pidfile /usr/local/redis/logs/redis.pid      # redis的pid檔案儲存位置port 6379                                    # redis監控連接埠bind 0.0.0.0                                 # redis監控的IPtimeout 0                                    # 用戶端串連關閉時服務端保持串連的時間長度,逾時                                             # 0為不中斷連線,等待用戶端再次串連logfile "/usr/local/redis/logs/redis.log"    # 記錄檔儲存位置dbfilename redis.rdb                         # redis資料檔案名dir /usr/local/redis/data/                   # redis資料儲存位置appendonly yes                               # 是否寫日誌,類似於mysql的bin-log
以上為簡單的redis最佳化配置
如果需要進行更加詳細的配置可以參考我在之後“redis配置詳解”裡面的說明
###### END ######
本文出自 “刺秦手記” 部落格,請務必保留此出處http://ciqin.blog.51cto.com/10608412/1794688
源碼安裝redis-3.0.5