1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/redis-3.0.0.gem" wget -P ~/soft/ "http://ou0y29lb2.bkt.clouddn.com/redis-3.0.0.tar.gz"
yum -y install gcc-c++
if [ ! -d "/usr/local/redis" ]; then mkdir /usr/local/redis fi
cp ~/soft/redis-3.0.0.tar.gz /usr/local/redis/
cd /usr/local/redis
tar -zxvf redis-3.0.0.tar.gz
cd /usr/local/redis/redis-3.0.0
make
make install PREFIX=/usr/local/redis
cd /usr/local/redis/bin
cp /usr/local/redis/redis-3.0.0/redis.conf ./
sed -i "s/^daemonize no/daemonize yes/g" redis.conf
cat redis.conf| grep "^daemon"
./redis-server redis.conf
ps -ef | grep redis | awk -F " " '{if($8!="grep")print $2}' | xargs kill -9
./redis-cli shutdown
yum install ruby yum install rubygems
cp ~/soft/redis-3.0.0.gem /usr/local/redis
gem install redis-3.0.0.gem
cp /usr/local/redis/redis-3.0.0/src/redis-trib.rb /usr/local/redis/
mkdir /usr/local/redis-cluster
cd /usr/local/redis-cluster
mv /usr/local/redis/redis-trib.rb ./
if [ ! -d "/usr/local/redis-cluster/7001" ]; then mkdir /usr/local/redis-cluster/7001 fi
cp -r /usr/local/redis/bin/* /usr/local/redis-cluster/7001/
if [ -e /usr/local/redis-cluster/7001/dump.rdb ];then rm /usr/local/redis-cluster/7001/dump.rdb fi;
cd 7001 sed -r -i "s/^daemonize [a-z]+/daemonize yes/g" redis.conf sed -r -i "s/^port [0-9]+/port 7001/g" redis.conf sed -r -i "s/^# cluster-enable/cluster-enable/g" redis.conf cat redis.conf| grep -E "^port|^daemonize|^# cluster-enabled|^cluster-enabled"
cd ..
cp 7001 7002 -r cp 7001 7003 -r cp 7001 7004 -r cp 7001 7005 -r cp 7001 7006 -r
path="/usr/local/redis-cluster/" names=("7002" "7003" "7004" "7005" "7006") count=${
for (( i=0; i<"$count"; i=i+1 ))
do sed -r -i "s/^port [0-9]+/port ${names[$i]}/g" $path${names[$i]}/redis.conf done
path="/usr/local/redis-cluster/" names=("7001" "7002" "7003" "7004" "7005" "7006") count=${
for (( i=0; i<"$count"; i=i+1 ))
do cd /usr/local/redis-cluster/${names[$i]} ./redis-server redis.conf done
ipaddr=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
cd /usr/local/redis-cluster
./redis-trib.rb create --replicas 1 $ipaddr:7001 $ipaddr:7002 $ipaddr:7003 $ipaddr:7004 $ipaddr:7005 $ipaddr:7006
cd 7001
./redis-cli -p 7001 -c
|
坑1
重装: 先关闭6个节点, 将6个节点中, 任何一个节点的三个文件都删除掉(*.rdb,*.aof,nodes.conf)
redis能用shell脚本
1
| /usr/local/redis-cluster/7001/redis-cli -p 7001 -c --raw hdel content 89
|
mac os sed 扩展正则表达式, 和GNU不一样…
由于mac系统是原生于bsd系,sed命令和gnu不同
mac sed 正则表达式竟然不能用+号
还得使用扩展参数…略坑…-E
1
| echo "foobar" | sed -E -e "s/o+//"
|
参考:
https://stackoverflow.com/questions/4453760/how-to-escape-plus-sign-on-mac-os-x-bsd-sed
http://blog.csdn.net/cbbbc/article/details/50474947
mac自带的sed和linux表现不一致, 需要安装gnu-sed
http://blog.csdn.net/wk3368/article/details/50876808