由于我团队开发的在线坐席系统,即将面对线上每周3000W的下行投放客户,产品的咨询量可能会很大,基于前期,200W的投放时,前10分钟,大概800问题量,平均一个客户大概8个问题,也就是说每分钟10个客户,折算3000W的话,就是每分钟150客户。系统容量应该问题不是太大,考虑一下极端情况(叠加效应),或者留下富余5倍,也就不到800吧,我们的生产环境,需要扩容消费者服务器,redis作为调度,需要扩容,由现在的一主从升级到一个集群(3对主从的cluster)。

 

这里大概记录下我们开发环境的redis集群的配置和安装过程,这些属于运维的工作,但是也是系统架构的范畴,这些若没有实战的经验,不要和我说什么架构设计。。。我就是搞这个的,我要对我的系统负责,但是又不会出现系统的过度设计。

 

有三台机器,准备搭建redis集群环境,redis的版本是3.2.8,源码安装,安装过程略去。

10.90.7.2
10.90.7.10
10.90.2.102

每个上面部署两个redis的实例,端口配置信息如下:

10.90.7.2 7000/7010
10.90.7.10 7001/7011
10.90.2.102 7002/7012

三台的redis的配置采用近乎一样的配置,除了因为端口的不同造成的一点点差异。这里拿10.90.7.2的配置7000为例:

在/opt/redis-3.2.8下面创建目录tkcluster。将/opt/redis-3.2.8下面的redis.conf文件copy到tkcluster目录下,重命名为7000.conf,修改的内容如下,其他的采用默认值。

bind 10.90.7.2
protected-mode no
port 7000
daemonize yes
pidfile /var/run/redis_7000.pid
appendonly yes
appendfilename "appendonly7000.aof"
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 15000
notify-keyspace-events Ex

 

配置完后,copy一下7000.conf到7010.conf,将上述相应的7000改成7010的参数即可完成7010.conf的配置。为了方便启动redis-server。写一个简单shell脚本:

#!/bin/bash

/opt/redis-3.2.8/src/redis-server 7000.conf
echo "status from 7000: $?"
sleep 5
/opt/redis-3.2.8/src/redis-server 7010.conf
echo "status from 7010: $?"

运行一下后,成功。得到文件列表:

[root@localhost tkcluster]# ll
总计 116
-rw-r--r-- 1 root root 46695 11-21 15:11 7000.conf
-rw-r--r-- 1 root root 46684 11-21 15:11 7010.conf
-rw-r--r-- 1 root root    54 11-22 19:10 appendonly7000.aof
-rw-r--r-- 1 root root     0 11-22 18:43 appendonly7010.aof
-rw-r--r-- 1 root root    90 11-22 19:10 dump.rdb
-rw-r--r-- 1 root root   739 11-22 18:43 nodes-7000.conf
-rw-r--r-- 1 root root   739 11-22 18:43 nodes-7010.conf
-rwxr-xr-x 1 root root   166 11-21 14:59 stcluster.sh

 

检查下,集群创建的指令是否能工作:

[root@bogon src]# ./redis-trib.rb --help
/usr/bin/env: ruby: 没有那个文件或目录

系统里面没有ruby这个环境,需要安装一下。

 

这个过程有点让人头疼,开始,在10.90.7.10的机器上进行安装,通过yum,下面是我遇到的问题

[root@bogon src]# yum install -y ruby

源找到了,很快安装成功。继续尝试:

[root@bogon src]# ./redis-trib.rb --help
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
        from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
        from ./redis-trib.rb:25:in `<main>'

这个错误,呵呵,熟悉ruby的话,很容易看出来,是ruby的环境需要访问redis,但是系统里面没有ruby的redis客户端程序,需要安装一下ruby的redis客户端插件。

[root@bogon src]# gem install redis
Fetching: redis-4.0.1.gem (100%)
ERROR:  Error installing redis:
        redis requires Ruby version >= 2.2.2.

这个错误,是因为ruby版本太低,需要升级,采用下面的方式可以完成:

[root@bogon src]# curl -L get.rvm.io | bash -s stable 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    194      0  0:00:01 --:--:--  0:00:01   249
100 24090  100 24090    0     0  24090      0  0:00:01  0:00:01 --:--:-- 25304
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
curl: (22) The requested URL returned error: 503

Could not download 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'.
  curl returned status '22'.

Creating group 'rvm'

Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

执行完成后,按照上面的提示,首先推出ssh,然后再登陆ssh。然后执行source /etc/profile.d/rvm.sh指令。接下来执行一下rvm list known指令,看看当前查看rvm库中已知的ruby版本

[root@bogon redis-3.2.8]# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head

# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2

# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby[-9.1.13.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.84]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1[.3.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head
[root@bogon redis-3.2.8]# 
View Code

相关文章:

  • 2021-06-16
  • 2021-05-26
  • 2021-11-25
  • 2021-07-30
  • 2022-01-08
  • 2021-05-02
猜你喜欢
  • 2022-02-10
  • 2021-04-03
  • 2021-07-26
  • 2021-11-22
相关资源
相似解决方案