日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

redis3.0.0 集群环境部署

發(fā)布時(shí)間:2023/12/31 综合教程 31 生活家
生活随笔 收集整理的這篇文章主要介紹了 redis3.0.0 集群环境部署 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

建站服務(wù)器

(要讓集群正常工作至少需要3個(gè)主節(jié)點(diǎn),在這里我們要?jiǎng)?chuàng)建6個(gè)Redis節(jié)點(diǎn),其中三個(gè)為主節(jié)點(diǎn),三個(gè)為從節(jié)點(diǎn),對應(yīng)的redis節(jié)點(diǎn)的ip和端口對應(yīng)關(guān)系如下)

127.0.0.1:7000
127.0.0.1:7001

127.0.0.1:7002

127.0.0.1:7003

127.0.0.1:7004

127.0.0.1:7005

1.下載redis。官網(wǎng)下載3.0.0版本,之前2.幾的版本不支持集群模式

wgethttps://github.com/antirez/redis/archive/3.0.0-rc2.tar.gz

2.解壓安裝

tar-zxvfredis-3.0.0-rc2.tar.gz

mvredis-3.0.0-rc2.tar.gz/usr/local/redis3.0

cd/usr/local/redis3.0

make 若報(bào)錯(cuò)則執(zhí)行(make MALLOC=libc)

makeinstall

編譯時(shí)可能會(huì)報(bào)錯(cuò):

安裝報(bào)錯(cuò) error: jemalloc/jemalloc.h: No such file or directory解決方法

錯(cuò)誤描述

安裝Redis 2.8.18時(shí)報(bào)錯(cuò):

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

原因分析

在README 有這個(gè)一段話。

Allocator

---------

Selecting a non-default memory allocator when building Redis is done by setting

the `MALLOC` environment variable. Redis is compiled and linked against libc

malloc by default, with the exception of jemalloc being the default on Linux

systems. This default was picked because jemalloc has proven to have fewer

fragmentation problems than libc malloc.

To force compiling against libc malloc, use:

% make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:

% make MALLOC=jemalloc

說關(guān)于分配器allocator,如果有MALLOC 這個(gè)環(huán)境變量,會(huì)有用這個(gè)環(huán)境變量的去建立Redis。

而且libc并不是默認(rèn)的分配器,默認(rèn)的是 jemalloc,因?yàn)?jemalloc 被證明有更少的fragmentation problems比libc。

但是如果你又沒有jemalloc 而只有 libc 當(dāng)然 make 出錯(cuò)。 所以加這么一個(gè)參數(shù)。

解決辦法

make MALLOC=libc

3.創(chuàng)建集群需要的目錄

mkdir-p/usr.local/cluster

cd/usr.local/cluster

4.修改配置文件redis.conf

cp /usr/local/redis3.0/redis.conf /usr.local/cluster/

vimredis.conf

###需要修改的內(nèi)容##

port 7000

daemonize yes

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

##修改完redis.conf配置文件中的這些配置項(xiàng)之后把這個(gè)配置文件分別拷貝到7000/7001/7002/7003/7004/7005目錄下面

##注意:拷貝完成之后要修改7001/7002/7003/7004/7005目錄下面redis.conf文件中的port參數(shù),分別改為對應(yīng)的文件夾的名稱

5.分別啟動(dòng)這6個(gè)redis實(shí)例

cd /usr/local/cluster/7000

redis-server redis.conf

cd /usr/local/cluster/7001

redis-server redis.conf

cd /usr/local/cluster/7002

redis-server redis.conf

cd /usr/local/cluster/7003

redis-server redis.conf

cd /usr/local/cluster/7004

redis-server redis.conf

cd /usr/local/cluster/7005

redis-server redis.conf

##啟動(dòng)之后使用命令查看redis的啟動(dòng)情況ps -ef|grep redis

[root@localhost ~]# ps -ef|grep redis

root 2495 1 0 20:09 ? 00:00:04 redis-server *:7000 [cluster]

root 2505 1 0 20:10 ? 00:00:05 redis-server *:7001 [cluster]

root 2510 1 0 20:10 ? 00:00:04 redis-server *:7002 [cluster]

root 2520 1 0 20:13 ? 00:00:04 redis-server *:7003 [cluster]

root 2528 1 0 20:14 ? 00:00:04 redis-server *:7004 [cluster]

root 2534 1 0 20:14 ? 00:00:04 redis-server *:7005 [cluster]

root 2878 1477 0 20:54 pts/0 00:00:00 grep redis

6.執(zhí)行redis的創(chuàng)建集群命令創(chuàng)建集群

安裝創(chuàng)建集群所需要的環(huán)境及插件

yuminstall -y ruby

yum install -y rubygems

gem install redis(redis和ruby的接口,使用gem安裝)(本次實(shí)驗(yàn)環(huán)境可上網(wǎng))

cd /usr/local/redis3.0/src/

./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

至此redis集群即搭建成功!

7.使用redis-cli命令進(jìn)入集群環(huán)境

redis-cli -c -p 7000

加入-c ,可以在輸入的鍵值不在指定的端口時(shí)會(huì)自動(dòng)跳轉(zhuǎn)到對應(yīng)的端口。

總結(jié)

以上是生活随笔為你收集整理的redis3.0.0 集群环境部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。