安裝
step1:下載安裝包
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
step2:解壓
tar -zxvf redis-4.0.6.tar.gz
step3:安裝依賴
yum install gcc
step4:編譯安裝
cd /usr/opt/redis-4.0.6
make MALLOC=libc
step5:將/usr/opt/redis-4.0.6/src目錄下的文件加到/usr/local/bin目錄
cd /usr/opt/redis-4.0.6/src
make install
啟動(dòng)
1)方式一:直接啟動(dòng)旗国。但是這種啟動(dòng)方式需要一直打開(kāi)窗口巍扛,不能進(jìn)行其他操作,不太方便弟塞。
cd /usr/opt/redis-4.0.6/src
./redis-server
2)后臺(tái)進(jìn)程啟動(dòng)
cd /usr/opt/redis-4.0.6
vi redis.conf
將daemonize no修改為daemonize yes
cd /usr/opt/redis-4.0.6/src
./redis-server /usr/opt/redis-4.0.6/redis.conf
關(guān)閉redis
step1:查找進(jìn)程
ps -aux | grep redis
step2:強(qiáng)制殺掉
kill -9 pid
設(shè)置開(kāi)機(jī)啟動(dòng)
step1:在etc新建redis目錄
cd /etc
mkdir redis
step2:將/usr/opt/redis-4.0.6/redis.conf 文件復(fù)制一份到/etc/redis目錄下捷兰,并命名為6379.conf
cp /usr/opt/redis-4.0.6/redis.conf /etc/redis/6379.conf
step3:將redis的啟動(dòng)腳本復(fù)制一份放到/etc/init.d目錄下
cp /usr/opt/redis-4.0.6/utils/redis_init_script /etc/init.d/redisd
step4:編輯redisd文件
cd /etc/init.d
在redisd文件開(kāi)頭加入以下內(nèi)容(注釋的意思是出革,redis服務(wù)必須在運(yùn)行級(jí)2贝或,3谓着,4泼诱,5下被啟動(dòng)或關(guān)閉,啟動(dòng)的優(yōu)先級(jí)是90赊锚,關(guān)閉的優(yōu)先級(jí)是10):
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
step5:開(kāi)機(jī)自啟
chkconfig redisd on
step6:啟動(dòng)redis
service redisd start
step7:關(guān)閉redis
service redisd stop
redis開(kāi)通外網(wǎng)訪問(wèn)
1)更改配置文件
cd /usr/opt/redis-4.0.6
vi redis.conf
將protected-mode yes修改為protected-mode no
注釋掉bind 127.0.0.1
2)重啟
cd /usr/opt/redis-4.0.6/src
redis-cli shutdown
./redis-server /usr/opt/redis-4.0.6/redis.conf
如何查看redis的版本
cd /usr/opt/redis-4.0.6/src
redis-cli
127.0.0.1:6379>info
redis設(shè)置永久密碼
1)更改配置文件
cd /usr/opt/redis-4.0.6
vi redis.conf
requirepass foobared
requirepass 密碼
2)重啟
cd /usr/opt/redis-4.0.6/src
redis-cli shutdown
./redis-server /usr/opt/redis-4.0.6/redis.conf