14、codis的安装
1.基本信息
版本 | 2.0 |
---|---|
安装机器 | 三台机器 |
账号 | hadoop |
源路径 | /opt/software/codis-2.0.tar.gz |
目标路径 | /opt/codis -> opt/codis-2.0 |
依赖关系 | 无 |
2.安装过程
1).使用hadoop账号解压到/opt/目录下:
[hadoop @bgs -5p173-wangwenting software]$ tar -zxvf codis-${version}.tar.gz -C /opt |
设置软连接
[hadoop @bgs -5p173-wangwenting software]$ tar -zxvf codis.tar.gz -C /opt [hadoop @bgs -5p173-wangwenting opt]$ ln -s codis-${version} codis |
修改环境变量
[hadoop @bgs -5p173-wangwenting opt]$ vim /etc/profile 添加以下内容: export GOROOT=/opt/codis/go export PATH=${GOROOT}/bin:$PATH export GOPATH=/opt/codis/codis |
使环境变量生效:
[hadoop @bgs -5p173-wangwenting opt]$ source /etc/profile |
2).编译
[hadoop @bgs -5p173-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ mv bin/redis* ../ //把redis相关的conf文件移动到上一层,避免编译时被删除 注释bootstrap.sh文件中的go get开头的命令并编译: [hadoop @bgs -5p173-wangwenting codis]$ ./bootstrap.sh //编译 [hadoop @bgs -5p173-wangwenting codis]$ mv ../redis* bin/ //移回redis相关的conf文件 |
3).修改config.ini:
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis [hadoop @bgs -5p173-wangwenting codis]$ vim config.ini coordinator=zookeeper zk= 172.24 . 5.173 : 2181 , 172.24 . 5.174 : 2181 , 172.24 . 5.175 : 2181 product=baseline dashboard_addr=bgs-5p173-wangwenting: 18087 proxy_id=proxy_01 |
4).修改redis6479.conf:
[hadoop @bgs -5p173-wangwenting codis]$ vim bin/redis6479.conf pidfile "/opt/codis/codis/src/github.com/wandoulabs/codis/logs/redis6479.pid" port 6479 bind 172.24 . 5.173 logfile "/opt/codis/codis/src/github.com/wandoulabs/codis/logs/redis6479.log" dbfilename "dump6479.rdb" appendfilename "appendonly6479.aof" dir "/opt/codis/codis/src/github.com/wandoulabs/codis/data" |
5).修改redis6480.conf:
[hadoop @bgs -5p173-wangwenting codis]$ vim bin/redis6480.conf pidfile "/opt/codis/codis/src/github.com/wandoulabs/codis/logs/redis6480.pid" port 6480 bind 172.24 . 5.173 logfile "/opt/codis/codis/src/github.com/wandoulabs/codis/logs/redis6480.log" dbfilename "dump6480.rdb" appendfilename "appendonly6480.aof" dir "/opt/codis/codis/src/github.com/wandoulabs/codis/data" |
6).复制到其它两台机器:
[hadoop @bgs -5p173-wangwenting codis]$ scp -r /opt/codis-${version} hadoop @bgs -5p174-wangwenting:/opt/ [hadoop @bgs -5p174-wangwenting opt]$ln -s codis-${version} 0 codis [hadoop @bgs -5p173-wangwenting codis]$ scp -r /opt/codis-${version} hadoop @bgs -5p175-wangwenting:/opt/ [hadoop @bgs -5p175-wangwenting opt]$ln -s codis-${version} codis |
7).分别在另外两台机器上修改config.ini:
[hadoop @bgs -5p174-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis [hadoop @bgs -5p174-wangwenting opt]$ vim config.ini proxy_id=proxy_02 //bgs-5p174-wangwenting上修改 [hadoop @bgs -5p175-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis [hadoop @bgs -5p175-wangwenting opt]$ vim config.ini proxy_id=proxy_03 //bgs-5p175-wangwenting上修改 |
8).在bgs-5p174-wangwenting机器上修改redis6479.conf和redis6480.conf:
[hadoop @bgs -5p174-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/bin [hadoop @bgs -5p174-wangwenting opt]$ mv redis6479.conf redis6481.conf [hadoop @bgs -5p174-wangwenting opt]$ mv redis6480.conf redis6482.conf [hadoop @bgs -5p174-wangwenting opt]$ sed -i "s/6479/6481/g" /opt/codis/codis/src/github.com/wandoulabs/codis/bin/redis6481.conf [hadoop @bgs -5p174-wangwenting opt]$ sed -i "s/6480/6482/g" /opt/codis/codis/src/github.com/wandoulabs/codis/bin/redis6482.conf 并分别修改bind字段为bgs-5p174-wangwenting bind bgs-5p174-wangwenting |
9).在bgs-5p175-wangwenting机器上修改redis6479.conf和redis6480.conf:
[hadoop @bgs -5p175-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/bin [hadoop @bgs -5p175-wangwenting opt]$ mv redis6479.conf redis6483.conf [hadoop @bgs -5p175-wangwenting opt]$ mv redis6480.conf redis6484.conf [hadoop @bgs -5p175-wangwenting opt]$ sed -i "s/6479/6481/g" /opt/codis/codis/src/github.com/wandoulabs/codis/bin/redis6483.conf [hadoop @bgs -5p175-wangwenting opt]$ sed -i "s/6480/6482/g" /opt/codis/codis/src/github.com/wandoulabs/codis/bin/redis6484.conf 并分别修改bind字段为bgs-5p175-wangwenting bind bgs-5p175-wangwenting |
10).在bgs-5p173-wangwenting机器上启动dashboard并初始化slots:
[hadoop @bgs -5p175-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p175-wangwenting codis]$ nohup bin/codis-config dashboard & [hadoop @bgs -5p175-wangwenting codis]$ bin/codis-config slot init 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
11).分别在三台机器上启动Codis Redis:
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-server bin/redis6479.conf //bgs-5p173-wangwenting上 [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-server bin/redis6480.conf //bgs-5p173-wangwenting上 [hadoop @bgs -5p174-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p174-wangwenting codis]$ bin/codis-server bin/redis6481.conf //bgs-5p174-wangwenting上 [hadoop @bgs -5p174-wangwenting codis]$ bin/codis-server bin/redis6482.conf //bgs-5p174-wangwenting上 [hadoop @bgs -5p175-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p175-wangwenting codis]$ bin/codis-server bin/redis6483.conf //bgs-5p175-wangwenting上 [hadoop @bgs -5p175-wangwenting codis]$ bin/codis-server bin/redis6484.conf //bgs-5p175-wangwenting上 |
12).bgs-5p173-wangwenting机器,分别添加 Redis Server Group:
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 1 172.24 . 5.173 : 6479 master [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 1 172.24 . 5.173 : 6480 slave [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 2 172.24 . 5.174 : 6481 master [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 2 172.24 . 5.174 : 6482 slave [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 3 172.24 . 5.175 : 6483 master [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config server add 3 172.24 . 5.175 : 6484 slave 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
13).bgs-5p173-wangwenting机器,设置各个server group服务的slot范围(0-1024):
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config slot range-set 0 340 1 online [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config slot range-set 341 700 2 online [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config slot range-set 701 1023 3 online 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
14).查看cpu core数目:
[hadoop @bgs -5p173-wangwenting codis]$ cat /proc/cpuinfo | grep "cpu cores" |
15).三台机器分别启动 codis-proxy:
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ nohup bin/codis-proxy -c config.ini -L ./logs/proxy.log --cpu= 4 --addr=bgs-5p173-wangwenting: 19000 --http-addr=bgs-5p173-wangwenting: 11000 & //这里的4为cpu数目 [hadoop @bgs -5p174-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p174-wangwenting codis]$ nohup bin/codis-proxy -c config.ini -L ./logs/proxy.log --cpu= 4 --addr=bgs-5p174-wangwenting: 19000 --http-addr=bgs-5p174-wangwenting: 11000 & //这里的4为cpu数目 [hadoop @bgs -5p175-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p175-wangwenting codis]$ nohup bin/codis-proxy -c config.ini -L ./logs/proxy.log --cpu= 4 --addr=bgs-5p175-wangwenting: 19000 --http-addr=bgs-5p175-wangwenting: 11000 & //这里的4为cpu数目 |
16).bgs-5p173-wangwenting上设置 proxy 为 online 状态,提供服务:
[hadoop @bgs -5p173-wangwenting codis]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting codis]$ bin/codis-config -c config.ini proxy online proxy_01 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
17).bgs-5p174-wangwenting上设置 proxy 为 online 状态,提供服务:
[hadoop @bgs -5p174-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p174-wangwenting opt]$ bin/codis-config -c config.ini proxy online proxy_02 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
18).bgs-5p175-wangwenting上设置 proxy 为 online 状态,提供服务:
[hadoop @bgs -5p175-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p175-wangwenting opt]$ bin/codis-config -c config.ini proxy online proxy_03 输出以下内容代表成功 { "msg" : "OK" , "ret" : 0 } |
19).启动 codis-ha:
[hadoop @bgs -5p173-wangwenting opt]$ cd /opt/codis/codis/src/github.com/wandoulabs/codis/ [hadoop @bgs -5p173-wangwenting opt]$ nohup /opt/codis/codis-ha/codis-ha --codis-config= 172.24 . 5.173 : 18087 --productName=baseline & |
20).打开浏览器,访问以下网址:172.24.5.173:18087
输出以上内容,所有proxy status都是online说明codis集群搭建成功