1.獲取redis資源
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
2.解壓
tar xzvf redis-4.0.8.tar.gz
3.安裝
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
如果 make 編譯失敗,可執行以下命令安裝 編譯所需的環境
yum -y install gcc
yum -y install gcc-c++
再次執行 make 編譯命令,如果報 error: jemalloc/jemalloc.h: No such file or directory等這種錯誤
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error “Newer version of jemalloc required”
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data0/src/redis-2.6.2/src’
make: *** [all] Error 2
可查看 “Redis 安裝報錯 error: jemalloc/jemalloc.h: No such file or directory解決方法” 解決問題
4.移動配置文件到安裝目錄下
cd …/
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
5.配置redis爲後臺啓動
vi /usr/local/redis/etc/redis.conf //將daemonize no 改成daemonize yes
6.將redis加入到開機啓動
vi /etc/rc.local //在裏面添加內容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是開機調用這段開啓redis的命令)
7.開啓redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
常用命令
redis-server /usr/local/redis/etc/redis.conf //啓動redis
pkill redis //停止redis
卸載redis:
rm -rf /usr/local/redis //刪除安裝目錄
rm -rf /usr/bin/redis-* //刪除所有redis相關命令腳本
rm -rf /root/download/redis-4.0.4 //刪除redis解壓文件夾
擴展:
1、給redis設置登錄密碼
需要永久配置密碼的話就去redis.conf的配置文件中找到requirepass這個參數,如下配置:
將 # requirepass foobared 註釋打開
並修改爲 requirepass xxx #指定密碼xxx
保存後重啓redis就可以了
2、遠程連接失敗問題:
同樣修改redis.conf配置文件
#bind 127.0.0.1 修改爲 bind 0.0.0.0
redis密碼方式登錄
./redis-cli -h 127.0.0.1 -p 6379 -a yourpassword
1.Redis服務端正在加載數據時,由於退出redis服務端或者關閉redis服務端窗口…,導致無法再次進入redis服務端,如下錯誤:
$ redis-server # 啓動redis服務端
1051:C 06 May 2019 14:13:49.227 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1051:C 06 May 2019 14:13:49.227 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1051, just started
1051:C 06 May 2019 14:13:49.227 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1051:M 06 May 2019 14:13:49.228 * Increased maximum number of open files to 10032 (it was originally set to 256).
1051:M 06 May 2019 14:13:49.228 # Could not create server TCP listening socket *:6379: bind: Address already in use
(1)解決錯誤信息:
查看系統限制
$ ulimit -a
設置“open files”數量
$ ulimit -n 10032
2.再次進入redis服務端,如下錯誤:
$ redis-server
1061:C 06 May 2019 14:14:36.611 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1061:C 06 May 2019 14:14:36.611 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1061, just started
1061:C 06 May 2019 14:14:36.611 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1061:M 06 May 2019 14:14:36.613 # Could not create server TCP listening socket *:6379: bind: Address already in use
6379地址已經在使用(6379是redis默認的端口)
(2)解決錯誤信息:$ ps -ef | grep -i redis
進程號3272是redis的服務器
2.2、殺死該進程
使用"kill -9"命令
kill -9 3272 # 進程3272是redis服務器
2.3、重新啓動redis服務器
$ redis-server
5377:C 05 May 2019 21:20:46.788 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5377:C 05 May 2019 21:20:46.788 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5377, just started
5377:C 05 May 2019 21:20:46.788 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
.
.-__ ''-._ _.-
.
. ‘’-._ Redis 5.0.4 (00000000/0) 64 bit
.-.-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.
-.|’_.-'| Port: 6379 |
-.._ / _.-' | PID: 5377
-._-._
-./ .-’ .-’
|-._
-.-.__.-' _.-'_.-'| |
-.-._ _.-'_.-' | http://redis.io
-._-._
-..-’.-’ .-’
|-._
-.-.__.-' _.-'_.-'| |
-.-._ _.-'_.-' |
-._-._
-..-’_.-’ _.-’
-._
-..-’ _.-’
-._ _.-'
-..-’
5377:M 05 May 2019 21:20:46.791 # Server initialized
5377:M 05 May 2019 21:20:46.791 * Ready to accept connections