Redis的安装与简单部署
截止到本文完成這一天,redis的最穩定版本是3.2.1,其下載地址:http://download.redis.io/releases/redis-3.2.1.tar.gz。直接wget一下就好了。
Redisの安裝
在當前目錄下#tar -zxvf redis-3.2.1.tar.gz之后,來到redis-3.2.1文件夾里,#make && make test,之后會出來一大片東西,會提示“\o/ All tests passed without errors!”,但是無法像其他軟件那樣去#make install,即使#make install還是提示hint:it's a good idea to "make test"。
進入redis文件包文件夾把redis.conf拷貝到/usr/local/redis/etc文件夾里,如果沒有此文件夾請新建。再返回redis安裝包文件夾的/src文件夾里,把里面所有的綠色腳本文件都mv到/usr/local/redis/bin里,來到/usr/local/redis/bin,#./redis-server,啟動服務器程序。
這時,會有如下提示:
19183:C 29 Jun 09:35:07.086 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
意思是說沒有給redis-server一個配置文件,需要制定一個配置文件,于是乎,把命令更改成#./redis-server /usr/local/redis/etc/redis.conf。就會出現這樣的圖片。
這里面的英文我拷貝出來,然后加以翻譯。
18988:M 29 Jun 09:38:52.458 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
警告:TCP backlog的值設定是511,這是無法啟動的,因為/proc/sys/net/core/somaxconn的設定值是128,比你的511要低。
【解決方案】echo 511 > /proc/sys/net/core/somaxconn
18988:M 29 Jun 09:38:52.458 # 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.
警告:overcommit_memory這個值被設定為0!這樣的低內存條件后臺可能會失敗,要解決這個問題,在/etc/sysctl.conf里增加一句話'vm.overcommit_memory = 1'然后重新啟動服務器,如果你不想重新啟動服務器,那么就輸入'sysctl vm.overcommit_memory=1'解決。
18988:M 29 Jun 09:38:52.458 # 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.
警告:你的內核里有THP支持功能,這個可能會和redis建立一些延遲和內存,要解決這個問題請以root的身份運行命令:“echo never > /sys/kernel/mm/transparent_hugepage/enabled”,而且把這句話添加到/etc/rc.local里,這樣在服務器重啟之后就會關上這個設定,在THP禁用的時候,redis必須被重啟。
18988:M 29 Jun 09:38:52.458 * The server is now ready to accept connections on port 6379
把上面三個problem都解決了之后,再一次#./redis-server /usr/local/redis/etc/redis.conf,屏幕變成這樣:
提示:服務器已經準備好從6379號端口接收連接了,意味著server端已經啟動成功。如果你不喜歡6379號端口,而是喜歡4444號端口,那么就要把/usr/local/redis/etc下的redis.conf里的端口由6379改成4444,然后#./redis-server /usr/local/redis/etc/redis.conf。
轉后臺啟動
但是這樣的啟動是在前臺啟動,屏幕被霸占了,其他工作都做不了了,比較煩。我們希望redis在后臺啟動就好,怎么辦呢?
#vim /usr/local/redis/etc/redis.conf。找到daemonize,把原來的no改成yes。這意味著redis是后臺啟動了。
這時候再一次的以redis.conf啟動redis.server。就會發現屏幕沒有什么變化和提示,但是使用#pstree -p|grep redis查看一下進程就知道redis已經在后臺啟動了,如圖:
用#ps -ef的效果也在上面那張圖里,至此整個redis的安裝和啟動過程結束。
在/usr/local/redis/bin里有一個文件叫redis-cli,cli是client登錄的簡寫,也就是說這個是客戶端登陸的啟動文件。
可見redis也是那種key-value模式的數據庫,在上面的例子里name是key,value是Chris,name是ID,value是33664,但是一旦再一次將name賦值成了99f90,以前的33664就會消失。
而且即使退出客戶端連接,再一次進入的話,原有的key和value也不會消失。而如果事前沒有啟動redis server,那么redis-cli是無法連接的,如圖:
Redisの退出
至于關閉redis,方法就效仿其他軟件,要么#pkill redis-server,要么就是#/usr/local/redis/bin/redis-cli shutdown。
轉載于:https://blog.51cto.com/chenx1242/1793895
總結
以上是生活随笔為你收集整理的Redis的安装与简单部署的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Emacs学用快捷键
- 下一篇: 7 款顶级开源 BI(商务智能)软件和报