由于minimal版本的基础软包是具备,但lib包大多都缺。所以需要编译加载lib相关包。在此次编译安装中,需要涉及到openssl zlib的lib包。如果用yum安装也行;yum install openssl-devel zlib-devel。本文主要记录编译安装,我们开始吧。
安装前确认gcc-c++是否安装
[root@localhost ~] #yum install gcc-c++ -y
上传源码包。版本自己选择,均可网上下载
openssl-1.0.1t.tar.gz redis-3.2.0.tar.gz ruby-2.3.1.tar.gz zlib-1.2.8.tar.gz
解压包:
[root@localhost ~]# tar -xzf openssl-1.0.1t.tar.gz
[root@localhost ~]# tar -xzf zlib-1.2.8.tar.gz
[root@localhost ~]# tar -xzf ruby-2.3.1.tar.gz
[root@localhost ~]# tar -xzf redis-3.2.0.tar.gz
编译安装openssl
[root@localhost ~]# cd openssl-1.0.1t
[root@localhost openssl-1.0.1t]# ./config --prefix=/usr/local/openssl shared
[root@localhost openssl-1.0.1t]# make
[root@localhost openssl-1.0.1t]# make install
编译安装zlib
[root@localhost openssl-1.0.1t]# cd ../zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.8]# make && make install
编译安装ruby
[root@localhost zlib-1.2.8]# cd ../ruby-2.3.1
[root@localhost ruby-2.3.1]# ./configure --prefix=/usr/local/ruby
[root@localhost ruby-2.3.1]# make && make install
处理环境变量PATH
[root@localhost ruby-2.3.1]# vim /etc/profile
PATH=$PATH:/usr/local/ruby/bin
[root@localhost ruby-2.3.1]# source /etc/profile
增加ruby的openssl\zlib模块。如果不扩展安装这两个模块会在执行gem install redis时报类式错,如下:
[root@localhost ruby-2.3.1]# gem install redis
ERROR: Loading command: install (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
添加ruby的openssl zlib模块
[root@localhost ruby-2.3.1]# cd ext/openssl/
[root@localhost openssl]# pwd
/root/ruby-2.3.1/ext/openssl
[root@localhost openssl]# ruby extconf.rb --with-openssl-dir=/usr/local/openssl
在执行make时报错,需要修改Makefile文件,报错如下:
[root@localhost openssl]# make
make: *** No rule to make target `/include/ruby.h',needed by `ossl_x509store.o'. Stop.
[root@localhost openssl]# vim Makefile
top_srcdir = ../..
将上一条内容插入 Makefile 文件前几行就行。再次执行make
[root@localhost openssl]# make
[root@localhost openssl]# make install
/usr/bin/install -c -m 0755 openssl.so /usr/local/ruby/lib/ruby/site_ruby/2.3.0/x86_64-linux
installing default openssl libraries
[root@localhost openssl]# cd ../zlib
[root@localhost zlib]# ruby extconf.rb --with-zlib-dir=/usr/local/zlib
[root@localhost zlib]# make && make install
linking shared-object zlib.so
/usr/bin/install -c -m 0755 zlib.so /usr/local/ruby/lib/ruby/site_ruby/2.3.0/x86_64-linux
OK..ruby相关编译安装完成。
修改gem更新源
[root@localhost ~]# gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
由于国内种种原因,好多更新源只能用国人自已的。所以得改一改。
http://gems.ruby-china.org
https://ruby.taobao.org/
由于这里使用淘宝的源。会报一个ssl证书无效,参考:http://blog.csdn.net/beyondlpf/article/details/51275051,百度了一个说是腾讯的源。不需要ssl..
[root@localhost ~]# gem sources -a http://gems.ruby-china.org/ -r https://rubygems.org/
在这里等一分钟左右,会报如下信息,表示替换成功。
http://gems.ruby-china.org/ added to sources
https://rubygems.org/ removed from sources
OK。。。整个ruby前期环境搞完了,下面开始搞redis了。just go...
[root@localhost ~]# cd redis-3.2.0
在以往的安装中(非root用户安装)。一般都是直接make && make install 。。或者按网上的说的 make --prefix=/xxxx这个方法我试过,感觉没有对。后边对[root@localhost redis-3.2.0]# vim src/Makefile这个文件查看发现对于prefix的位置是定了的。PREFIX?=/usr/local
[root@localhost redis-3.2.0]# vim src/Makefile
PREFIX?=/usr/local/redis
[root@localhost redis-3.2.0]# make && make install
在大多数的网上文档中都说要安装tcl。其实不执行make test 是不需要安装tcl的。
再次修改环境变量PATH
[root@localhost ~]# vim /etc/profile
PATH=$PATH:/usr/local/ruby/bin:/usr/local/redis/bin
[root@localhost ~]# source /etc/profile
配置redis
[root@localhost ~]# cd /usr/local/redis/
[root@localhost redis]# ls
bin
[root@localhost redis]# pwd
/usr/local/redis
[root@localhost redis]# mkdir conf log
[root@localhost redis]# cd conf/
[root@localhost conf]# mkdir 7001 7002 7003 7004 7005 7006
[root@localhost conf]# cd 7001
[root@localhost 7001]# vim redis.conf
bind 127.0.0.1
protected-mode yes
port 7001
tcp-backlog 511
timeout 0
tcp-keepalive 0
daemonize yes
supervised no
pidfile /usr/local/redis/log/7001_redis.pid
loglevel notice
logfile "/usr/local/redis/log/7001.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay yes
slave-priority 100
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
按官网的相关文档。做一个集群只有对应的cluster那几个参数足够了,其实参数作为调优相关,以上是百度的,只作参考。
将此配置文件复制到7002...7006里,并修改对应的端口号
[root@localhost 7001]# cp redis.conf ../7002/
[root@localhost 7001]# cp redis.conf ../7003/
[root@localhost 7001]# cp redis.conf ../7004/
[root@localhost 7001]# cp redis.conf ../7005/
[root@localhost 7001]# cp redis.conf ../7006/
[root@localhost 7001]# vim ../7002/redis.conf
[root@localhost 7001]# vim ../7003/redis.conf
[root@localhost 7001]# vim ../7004/redis.conf
[root@localhost 7001]# vim ../7005/redis.conf
[root@localhost 7001]# vim ../7006/redis.conf
启动redis
[root@localhost 7001]# redis-server /usr/local/redis/conf/7001/redis.conf
[root@localhost 7001]# cd ../7002
[root@localhost 7002]# redis-server /usr/local/redis/conf/7002/redis.conf
[root@localhost 7002]# cd ../7003
[root@localhost 7003]# redis-server /usr/local/redis/conf/7003/redis.conf
[root@localhost 7003]# cd ../7004
[root@localhost 7004]# redis-server /usr/local/redis/conf/7004/redis.conf
[root@localhost 7004]# cd ../7005
[root@localhost 7005]# redis-server /usr/local/redis/conf/7005/redis.conf
[root@localhost 7005]# cd ../7006
[root@localhost 7006]# redis-server /usr/local/redis/conf/7006/redis.conf
查看端口情况
[root@localhost 7006]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:7005 0.0.0.0:* LISTEN 32770/redis-server
tcp 0 0 127.0.0.1:7006 0.0.0.0:* LISTEN 32774/redis-server
tcp 0 0 127.0.0.1:17001 0.0.0.0:* LISTEN 32741/redis-server
tcp 0 0 127.0.0.1:17002 0.0.0.0:* LISTEN 32758/redis-server
tcp 0 0 127.0.0.1:17003 0.0.0.0:* LISTEN 32762/redis-server
tcp 0 0 127.0.0.1:17004 0.0.0.0:* LISTEN 32766/redis-server
tcp 0 0 127.0.0.1:17005 0.0.0.0:* LISTEN 32770/redis-server
tcp 0 0 127.0.0.1:17006 0.0.0.0:* LISTEN 32774/redis-server
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1261/sshd
tcp 0 0 127.0.0.1:7001 0.0.0.0:* LISTEN 32741/redis-server
tcp 0 0 127.0.0.1:7002 0.0.0.0:* LISTEN 32758/redis-server
tcp 0 0 127.0.0.1:7003 0.0.0.0:* LISTEN 32762/redis-server
tcp 0 0 127.0.0.1:7004 0.0.0.0:* LISTEN 32766/redis-server
tcp 0 0 :::22 :::* LISTEN 1261/sshd
[root@localhost 7006]#
创建集群
[root@localhost ~]# gem install redis
将redis源码包里的 redis-trib.rb 复制到 /usr/local/redis/bin/
[root@localhost ~]# cp /root/redis-3.2.0/src/redis-trib.rb /usr/local/redis/bin/
[root@localhost ~]# redis-trib.rb create --replicas 1 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 127.0.0.1:7006
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
Adding replica 127.0.0.1:7006 to 127.0.0.1:7003
M: 291f04f678dd9606cae6368b566e0f6e73e9d27c 127.0.0.1:7001
slots:0-5460 (5461 slots) master
M: 37be4be6b9ce5a8e7beaf0ab655305b445124e75 127.0.0.1:7002
slots:5461-10922 (5462 slots) master
M: 877151589fda8b09612ec8d5608897e83cb2872d 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
S: 31871de5c884cef4e9ea8049c1301ae417400d1f 127.0.0.1:7004
replicates 291f04f678dd9606cae6368b566e0f6e73e9d27c
S: 3de40d5c74fca6d4b27d2cb0a4d94df64efbdb60 127.0.0.1:7005
replicates 37be4be6b9ce5a8e7beaf0ab655305b445124e75
S: fd072e7bbcd631f52ad81cb984a4eda5ceeaf00a 127.0.0.1:7006
replicates 877151589fda8b09612ec8d5608897e83cb2872d
Can I set the above configuration? (type 'yes' to accept): 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 127.0.0.1:7001)
M: 291f04f678dd9606cae6368b566e0f6e73e9d27c 127.0.0.1:7001
slots:0-5460 (5461 slots) master
M: 37be4be6b9ce5a8e7beaf0ab655305b445124e75 127.0.0.1:7002
slots:5461-10922 (5462 slots) master
M: 877151589fda8b09612ec8d5608897e83cb2872d 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
M: 31871de5c884cef4e9ea8049c1301ae417400d1f 127.0.0.1:7004
slots: (0 slots) master
replicates 291f04f678dd9606cae6368b566e0f6e73e9d27c
M: 3de40d5c74fca6d4b27d2cb0a4d94df64efbdb60 127.0.0.1:7005
slots: (0 slots) master
replicates 37be4be6b9ce5a8e7beaf0ab655305b445124e75
M: fd072e7bbcd631f52ad81cb984a4eda5ceeaf00a 127.0.0.1:7006
slots: (0 slots) master
replicates 877151589fda8b09612ec8d5608897e83cb2872d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
查看核对集群功能
[root@localhost ~]# redis-trib.rb info 127.0.0.1:7001
127.0.0.1:7001 (291f04f6...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7002 (37be4be6...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7003 (87715158...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
[root@localhost ~]# cd /usr/local/redis/conf/7001/
[root@localhost 7001]# ls
appendonly.aof dump.rdb nodes.conf redis.conf
[root@localhost 7001]# cat nodes.conf
fd072e7bbcd631f52ad81cb984a4eda5ceeaf00a 127.0.0.1:7006 slave 877151589fda8b09612ec8d5608897e83cb2872d 0 1465829294197 6 connected
31871de5c884cef4e9ea8049c1301ae417400d1f 127.0.0.1:7004 slave 291f04f678dd9606cae6368b566e0f6e73e9d27c 0 1465829291171 4 connected
37be4be6b9ce5a8e7beaf0ab655305b445124e75 127.0.0.1:7002 master - 0 1465829293191 2 connected 5461-10922
877151589fda8b09612ec8d5608897e83cb2872d 127.0.0.1:7003 master - 0 1465829296220 3 connected 10923-16383
291f04f678dd9606cae6368b566e0f6e73e9d27c 127.0.0.1:7001 myself,master - 0 0 1 connected 0-5460
3de40d5c74fca6d4b27d2cb0a4d94df64efbdb60 127.0.0.1:7005 slave 37be4be6b9ce5a8e7beaf0ab655305b445124e75 0 1465829295208 5 connected
vars currentEpoch 6 lastVoteEpoch 0
[root@localhost ~]# redis-cli -c -h 127.0.0.1 -p 7001
OK....整个集群部署完成了。。
踩过的坑。。
[root@localhost 7001]# redis-trib.rb create --replicas 1 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 127.0.0.1:7006 >>> Creating cluster [ERR] Sorry,can't connect to node 127.0.0.1:7001