十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
具体就不做介绍了,直接开始安装
10年积累的成都网站建设、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有海原免费网站建设让你可以放心的选择与我们合作。准备环境:
使用2台centos服务器,每台机器上部署3个实例,集群为三个主节点与三个从节点: 第一台 192.168.1.107:7000 192.168.1.107:7001 192.168.1.107:7002 第二台 192.168.1.108:7003 192.168.1.108:7004 192.168.1.108:7005安装配置:
192.168.1.107服务器
#yum -y install gcc zlib ruby rubygems #gem install redis #wget http://download.redis.io/releases/redis-3.2.8.tar.gz #tar -zxvf redis-3.2.8.tar.gz #cd redis-3.2.8 #make && make install 将 redis-trib.rb 复制到 /usr/local/bin 目录下 #cp src/redis-trib.rb /usr/local/bin/ #mkdir -p /data/redis/{conf,data,logs} #cp redis.conf /data/redis/conf/redis-7000.conf #cp redis.conf /data/redis/conf/redis-7001.conf #cp redis.conf /data/redis/conf/redis-7002.conf配置内容如下(redis-7000.conf其它类同):
daemonize yes pidfile /data/redis/data/redis-7000.pid port 7000 bind 192.168.1.107 unixsocket /data/redis/data/redis-7000.sock unixsocketperm 700 timeout 300 loglevel verbose logfile /data/redis/logs/redis-7000.log databases 16 dbfilename dump-7000.rdb dir /data/redis/data/ #aof持久化 appendonly yes appendfilename appendonly-7000.aof appendfsync everysec no-appendfsync-on-rewrite yes auto-aof-rewrite-percentage 80-100 auto-aof-rewrite-min-size 64mb lua-time-limit 5000 #集群配置 cluster-enabled yes cluster-config-file /data/redis/data/nodes-7000.conf cluster-node-timeout 5000同样的在192.168.1.108上配置其它端口,配置后我们分别启动
192.168.1.107主机 #redis-server /data/redis/conf/redis-7000.conf #redis-server /data/redis/conf/redis-7001.conf #redis-server /data/redis/conf/redis-7002.conf 192.168.1.108主机 #redis-server /data/redis/conf/redis-7003.conf #redis-server /data/redis/conf/redis-7004.conf #redis-server /data/redis/conf/redis-7005.conf分别在两台主机查看启动进程与端口:
# ps -ef|grep redis root 4663 1 0 10:53 ? 00:00:09 redis-server 192.168.1.107:7000 [cluster] root 4667 1 0 10:53 ? 00:00:09 redis-server 192.168.1.107:7001 [cluster] root 5566 1 0 12:12 ? 00:00:06 redis-server 192.168.1.107:7002 [cluster] root 5611 5313 0 14:49 pts/1 00:00:00 grep redis # netstat -tnlp | grep redis tcp 0 0 192.168.1.107:7000 0.0.0.0:* LISTEN 4663/redis-server 1 tcp 0 0 192.168.1.107:7001 0.0.0.0:* LISTEN 4667/redis-server 1 tcp 0 0 192.168.1.107:7002 0.0.0.0:* LISTEN 5566/redis-server 1 tcp 0 0 192.168.1.107:17000 0.0.0.0:* LISTEN 4663/redis-server 1 tcp 0 0 192.168.1.107:17001 0.0.0.0:* LISTEN 4667/redis-server 1 tcp 0 0 192.168.1.107:17002 0.0.0.0:* LISTEN 5566/redis-server 1创建集群
redis-trib.rb命令介绍可以参考: http://weizijun.cn/2016/01/08/redis%20cluster%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7redis-trib-rb%E8%AF%A6%E8%A7%A3/ # redis-trib.rb create --replicas 1 192.168.1.107:7000 192.168.1.107:7001 192.168.1.107:7002 192.168.1.108:7003 192.168.1.108:7004 192.168.1.108:7005 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.1.108:7003 192.168.1.107:7000 192.168.1.108:7004 Adding replica 192.168.1.107:7001 to 192.168.12.108:7003 Adding replica 192.168.1.108:7005 to 192.168.12.107:7000 Adding replica 192.168.1.107:7002 to 192.168.12.108:7004 M: d0ce4d4eb8c503267ffea606e90d1c537a83a22e 192.168.1.107:7000 slots:5461-10922 (5462 slots) master S: 24ca2753885db7f37c0e0077b1f43eb2b1a52e42 192.168.1.107:7001 replicates 8ee448821d5e757af73bab65861340e557b8cd14 S: 90c36924c71ae924b1179ff1a384c53e5ea2e484 192.168.1.107:7002 replicates 5a93221a3281f88f9984c24b6e1d6f08b3685c89 M: 8ee448821d5e757af73bab65861340e557b8cd14 192.168.1.108:7003 slots:0-5460 (5461 slots) master M: 5a93221a3281f88f9984c24b6e1d6f08b3685c89 192.168.1.108:7004 slots:10923-16383 (5461 slots) master S: a63176f88cbf58ab879421148da3b171f169540d 192.168.1.108:7005 replicates d0ce4d4eb8c503267ffea606e90d1c537a83a22e Can I set the above configuration? (type 'yes' to accept): yes #输入yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join..... >>> Performing Cluster Check (using node 192.168.1.107:7000) M: d0ce4d4eb8c503267ffea606e90d1c537a83a22e 192.168.1.107:7000 slots:5461-10922 (5462 slots) master M: 24ca2753885db7f37c0e0077b1f43eb2b1a52e42 192.168.1.107:7001 slots: (0 slots) master replicates 8ee448821d5e757af73bab65861340e557b8cd14 M: 90c36924c71ae924b1179ff1a384c53e5ea2e484 192.168.1.107:7002 slots: (0 slots) master replicates 5a93221a3281f88f9984c24b6e1d6f08b3685c89 M: 8ee448821d5e757af73bab65861340e557b8cd14 192.168.1.108:7003 slots:0-5460 (5461 slots) master M: 5a93221a3281f88f9984c24b6e1d6f08b3685c89 192.168.1.108:7004 slots:10923-16383 (5461 slots) master M: a63176f88cbf58ab879421148da3b171f169540d 192.168.1.108:7005 slots: (0 slots) master replicates d0ce4d4eb8c503267ffea606e90d1c537a83a22e [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. #集群创建成功集群验证
192.168.1.107的7002端口的节点写入数据,在192.168.1.108的7005端口查询,接方式为 redis-cli -h 192.168.31.245 -c -p 7002 ,加参数 -C 可连接到集群,因为上面 redis.conf 将 bind 改为了ip地址,所以 -h 参数不可以省略。 # redis-cli -h 192.168.1.107 -c -p 7002 192.168.1.108:7003> set test01 "this is test01" OK 192.168.1.108:7003> # redis-cli -h 192.168.1.108 -c -p 7005 192.168.12.108:7005> get test01 -> Redirected to slot [1840] located at 192.168.12.108:7003 "this is test01" 说明集群运作正常。Redis 集群会把数据存在一个 master 节点,然后在这个 master 和其对应的salve 之间进行数据同步。当读取数据时,也根据一致性哈希算法到对应的 master 节点获取数据。只有当一个master 挂掉之后,才会启动一个对应的 salve 节点,充当 master 。
需要注意的是:必须要3个或以上
的主节点,否则在创建集群时会失败,并且当存活的主节点数小于总节点数的一半时,整个集群就无法提供服务了。
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。