這篇文章給大家分享的是有關(guān)如何通過源碼安裝redis-3.0.5的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,先為上虞等服務(wù)建站,上虞等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為上虞企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
##### 安裝redis-server #####
# 創(chuàng)建運行用戶
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.5 make PREFIX=/usr/local/redis make PREFIX=/usr/local/redis install
# 配置redis環(huán)境變量
echo ' ' >> /etc/profile echo 'PATH for redis-server' >> /etc/profile echo 'export PATH=/usr/local/redis/bin/:$PATH' >> /etc/profile tail -3 /etc/profile source /etc/profile echo $PATH
# 或者(重啟失效)
export PATH=/usr/local/redis/bin/:$PATH echo $PATH
# 創(chuàng)建配置文件,數(shù)據(jù),日志等相關(guān)目錄,并拷貝配置文件
# 創(chuàng)建規(guī)范的目錄結(jié)構(gòu)有助于行成良好習(xí)慣,提高效率
mkdir -p /usr/local/redis/conf mkdir -p /usr/local/redis/data mkdir -p /usr/local/redis/logs cp 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 &
# 查看啟動狀態(tài),進程和端口
ps -ef |grep redis netstat -anptl |grep redis
# 測試及使用
# 客戶端連接命令為:
/usr/local/redis/bin/redis-cli -p 6379 [root@cache redis]# redis-cli -p 6379 127.0.0.1:6379> set a 1 OK 127.0.0.1:6379> get a "1" 127.0.0.1:6379> set b 2 OK 127.0.0.1:6379> set c 3 OK 127.0.0.1:6379> keys * 1) "c" 2) "a" 3) "b" 127.0.0.1:6379> exit
# 以上為簡單測試,驗證安裝正確與否
# 安全關(guān)閉redis
/usr/local/redis/bin/redis-cli shutdown
# 關(guān)閉redis時,數(shù)據(jù)默認會保存在啟動redis時候所在的位置,保存為dump.rdb
-------- 簡單優(yōu)化redis ---------
# 以默認配置啟動redis-server會出現(xiàn)以下警告信息:不影響使用,
# 不過以筆者的習(xí)慣自然不會容忍此等警告信息的存在:
[root@cache redis]# redis-server /usr/local/redis/conf/redis.conf & [1] 4570 [root@cache 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
# 根據(jù)啟動日志提示需要優(yōu)化一些內(nèi)核的參數(shù),按提示操作:
echo never > /sys/kernel/mm/transparent_hugepage/enabled cat /sys/kernel/mm/transparent_hugepage/enabled echo 511 > /proc/sys/net/core/somaxconn cat /proc/sys/net/core/somaxconn echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf sysctl -p
# 以上操作重啟失效,可以按下操作配置下次開機生效,順便設(shè)置redis開機自啟動
echo " " >> /etc/rc.local echo "# redis-server by zs in $(date +%F)" >> /etc/rc.local echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local echo "echo 511 > /proc/sys/net/core/somaxconn" >>/etc/rc.local echo "/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf" >> /etc/rc.local tail -5 /etc/rc.local
# 繼續(xù)優(yōu)化配置文件
vim /usr/local/redis/conf/redis.conf
# 在配置文件中尋找以下關(guān)鍵字,可以按照以下內(nèi)容修改:
daemonize yes # 是否后臺運行,yes為后臺運行 pidfile /usr/local/redis/logs/redis.pid # redis的pid文件保存位置 port 6379 # redis監(jiān)控端口 bind 0.0.0.0 # redis監(jiān)控的IP timeout 0 # 客戶端連接關(guān)閉時服務(wù)端保持連接的時長,超時 # 0為不斷開連接,等待客戶端再次連接 logfile "/usr/local/redis/logs/redis.log" # 日志文件保存位置 dbfilename redis.rdb # redis數(shù)據(jù)文件名 dir /usr/local/redis/data/ # redis數(shù)據(jù)保存位置 appendonly yes # 是否寫日志,類似于MySQL的bin-log
以上為簡單的redis優(yōu)化配置
感謝各位的閱讀!關(guān)于“如何通過源碼安裝redis-3.0.5”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
網(wǎng)頁標題:如何通過源碼安裝redis-3.0.5
鏈接地址:http://muchs.cn/article30/ghjcso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、定制網(wǎng)站、云服務(wù)器、網(wǎng)站設(shè)計公司、微信公眾號、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)