一,單機(jī)模式
1,下載安裝包
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
2,解壓安裝包并安裝
tar -zxvf redis-4.0.2.tar.gz
cd redis-4.0.2
make
報(bào)錯:jemalloc/jemalloc.h:沒有那個文件或目錄,執(zhí)行make MALLOC=libc
cd /usr/local/redis-4.0.2/src
make install
3,建立兩個文件夾用于存放redis配置和命令文件
mkdir -p /usr/local/redis/etc
mkdir -p /usr/local/redis/bin
4,將redis配置和命令文件放入到新建的文件夾下
cd /usr/local/redis-4.0.2
cp redis.conf /usr/local/redis/etc
cd /usr/local/redis-4.0.2/src
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin
5,啟動時(shí)并指定配置文件
前臺啟動:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
6,驗(yàn)證啟動是否成功:
ps -ef |grep 6379
netstat -tunpl| grep redis
7,修改后臺啟動
vim /usr/local/redis/etc/redis.conf
daemonize yes 使Redis以守護(hù)進(jìn)程模式運(yùn)行
8,停止Redis
/usr/local/redis/bin/redis-cli SHUTDOWN
創(chuàng)新互聯(lián)建站 - 成都溫江機(jī)房,四川服務(wù)器租用,成都服務(wù)器租用,四川網(wǎng)通托管,綿陽服務(wù)器托管,德陽服務(wù)器托管,遂寧服務(wù)器托管,綿陽服務(wù)器托管,四川云主機(jī),成都云主機(jī),西南云主機(jī),成都溫江機(jī)房,西南服務(wù)器托管,四川/成都大帶寬,機(jī)柜大帶寬租用·托管,四川老牌IDC服務(wù)商
二,主從復(fù)制模式(讀寫分離:主可寫,從只讀)
規(guī)劃:101主節(jié)點(diǎn),102,103從節(jié)點(diǎn)
三,哨兵模式
規(guī)劃:將102作為哨兵的部署服務(wù)器以下操作是在102服務(wù)器上操作
(1)copy文件 sentinel.conf到/usr/local/redis/etc/中
cd /usr/local/redis-4.0.2
cp sentinel.conf /usr/local/redis/etc
(2)修改 sentinel.con文件:
vim /usr/local/redis/etc/sentinel.conf
sentinel monitor mymaster 192.168.1.101 6379 1
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 900000
sentinel parallel-syncs mymaster 2
(3)啟動 sentinel哨兵
/usr/local/redis/bin/redis-server /usr/local/redis/etc/sentinel.conf --sentinel &
(4)查看哨兵相關(guān)信息命令
/usr/local/redis/bin/redis-cli -h 192.168.0.102 -p 26379 info Sentinel
這里報(bào)錯:
(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified,
no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface.
If you want to connect from external computers to Redis you may adopt one of the following solutions:
1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
修改sentinel.conf文件
vim /usr/local/redis/etc/sentinel.conf
#bind 127.0.0.1
protected-mode no
對應(yīng)的101,102,103的redis.conf配置文件也要這樣配置
reboot重啟服務(wù)再次執(zhí)行
/usr/local/redis/bin/redis-cli -h 192.168.0.102 -p 26379 info Sentinel
(5)關(guān)閉主服務(wù)器查看集群信息:
/usr/local/redis/bin/redis-cli -h 192.168.0.101 -p 6379 shutdown
master節(jié)點(diǎn)轉(zhuǎn)移成功(其實(shí)質(zhì)修改了對應(yīng)redis.conf配置文件的參數(shù)slaveof)
網(wǎng)站名稱:centOS下安裝Redis
標(biāo)題來源:http://www.rwnh.cn/article22/gshcjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、移動網(wǎng)站建設(shè)、服務(wù)器托管、企業(yè)建站、ChatGPT、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)