codis 新版本 CodisLabs 编译安装
codis 3.0 版本编译安装
# 首先安装 go 语言
wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
tar zxvf go1.4.2.linux-amd64.tar.gz
mv go /opt/local/
# 配置环境变量
vi /etc/profile
--------------------------------------
export GOROOT=/opt/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/opt/local/codis
--------------------------------------
source /etc/profile
# 执行
go version
# 安装codis
yum install -y git
go get -u -d github.com/CodisLabs/codis
cd /opt/local/codis/src/github.com/CodisLabs/codis
# 安装配置
make
提示如下错误:
-------------------------------------------------------
/bin/sh: godep: 未找到命令
/bin/sh: godep: 未找到命令
make: *** [godep] 错误 127
-------------------------------------------------------
cd /opt/local/codis/bin
复制 godep 到 go/bin 目录
cp godep /opt/local/go/bin
然后再执行 make 命令
Hint: It's a good idea to run 'make test' ;) 表示安装完成
执行 make test 测试
完成安装会在 codis/src/github.com/CodisLabs/codis/bin 生成
assets, codis-config, codis-proxy, codis-server 四个文件
# 复制文件 方便管理
mkdir -p /opt/local/codis/{logs,conf,data}/
cd /opt/local/codis/src/github.com/CodisLabs/codis/bin
cp -rf * /opt/local/codis/bin
cd /opt/local/codis/src/github.com/CodisLabs/codis/
cp config.ini /opt/local/codis/conf/
cd /opt/local/codis/src/github.com/CodisLabs/codis/extern/redis-2.8.21/src
cp redis-cli /opt/local/codis/bin/redis-cli-2.8.21
ln -s /opt/local/codis/bin/redis-cli-2.8.21 /opt/local/codis/redis-cli
# 修改配置文件
cd /opt/local/codis/conf
vi config.ini
# 修改IP,配置WEB管理 默认 18087 端口 多proxy 配置VIP地址,但只能启动一个dashboard ,程序掉线再启动其他
dashboard_addr
( zk 配置 zookeeper 地址,单机配置一个,群集配置多个~以,号隔开 )
proxy_id=codis_proxy_1 配置为唯一
product= # zookeeper 节点信息
# redis-server 配置文件
cd /opt/local/codis/src/github.com/CodisLabs/codis/extern/redis-test/conf
cp 6379.conf 6380.conf /opt/local/codis/conf/
# 修改里面的配置端口与配置 需要修改的配置如下:
daemonize yes #后台模式运行
pidfile var/run/redis_6379.pid #pid 文件
port 6379 #运行端口
timeout 50 #请求超时时间,默认0
logfile "/opt/local/codis/logs/codis_6379.log" #日志文件
maxmemory 20gb #最大内存设置
save 900 1 #打开保存快照的条件( 第一个*表示多长时间 , 第三个*表示执行多少次写操作 )
save 300 10
save 60 10000
dbfilename 6379.rdb #数据快照保存的名字
dir /opt/local/codis/data #数据快照的保存目录
appendfilename "6379_appendonly.aof" #Redis更加高效的数据库备份及灾难恢复方式。
appendfsync everysec # ( always: always表示每次有写操作都进行同步. everysec: 表示对写操作进行累积,每秒同步一次 )
# 创建 dashboard 启动脚本
vi /opt/local/codis/start_dashboard.sh
#!/bin/sh
nohup /opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini -L /opt/local/codis/logs/dashboard.log dashboard --addr=:18087 --http-log=/opt/local/codis/logs/requests.log &>/dev/null &
# 启动 dashboard
/opt/local/codis/start_dashboard.sh
# 初始化 slot , 该命令会在zookeeper上创建slot相关信息
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot init
# 启动codis-server服务
/opt/local/codis/bin/codis-server /opt/local/codis/conf/6379.conf
/opt/local/codis/bin/codis-server /opt/local/codis/conf/6380.conf
# 添加 Redis Server Group
( 每一个 Server Group 作为一个 Redis 服务器组存在, 只允许有一个 master, 可以有多个 slave, group id 仅支持大于等于1的整数 )
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 1 localhost:6379 master
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 1 localhost:6380 slave
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 1 172.16.32.78:6379 master
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 1 172.16.32.79:6380 slave
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 2 172.16.32.79:6379 master
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 2 172.16.32.78:6380 slave
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 3 172.16.32.80:6379 master
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 3 172.16.32.81:6380 slave
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 4 172.16.32.81:6379 master
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini server add 4 172.16.32.80:6380 slave
# 设置 server group 服务的 slot 范围
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot range-set 0 255 1 online
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot range-set 256 511 2 online
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot range-set 512 767 3 online
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot range-set 768 1023 4 online
# slot 数据迁移
Codis 支持动态的根据实例内存, 自动对slot进行迁移, 以均衡数据分布.
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot rebalance
执行此命令需要满足下列条件:
1. 所有的codis-server都必须设置了maxmemory参数
2. 所有的 slots 都应该处于 online 状态, 即没有迁移任务正在执行
3. 所有 server group 都必须有 Master
另外 codis 还支持比例迁移。
如: 将slot id 为 [0-511] 的slot的数据, 迁移到 server group 2 上, --delay 参数表示每迁移一个 key 后 sleep 的毫秒数, 默认是 0, 用于限速.
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini slot migrate 0 511 2 --delay=10
迁移的过程对于上层业务来说是安全且透明的, 数据不会丢失, 上层不会中止服务.
注意:迁移的过程中打断是可以的, 但是如果中断了一个正在迁移某个slot的任务, 下次需要先迁移掉正处于迁移状态的 slot, 否则无法继续 (即迁移程序会检查同一时刻只能有一个 slot 处于迁移状态).
# 创建 start_proxy.sh,启动codis-proxy服务
vi /opt/local/codis/start_proxy.sh
#!/bin/sh
echo "shut down codis_proxy_1.."
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini proxy offline codis_proxy_1
echo "done"
echo "start new proxy..."
nohup /opt/local/codis/bin/codis-proxy --log-level info -c /opt/local/codis/conf/config.ini -L /opt/local/codis/logs/proxy.log --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &>/dev/null &
echo "done"
# 启动 proxy
/opt/local/codis/start_proxy.sh
# 设置 proxy 为 online 状态
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini proxy online codis_proxy_1
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini proxy online codis_proxy_2
/opt/local/codis/bin/codis-config -c /opt/local/codis/conf/config.ini proxy online codis_proxy_3
# 访问dashboard
http://localhost:18087/admin/
# codis-server 主从切换配置
codis-ha 是一个通过 是一个通过 codis开放的 api 实现自动切换主从
配置如下:
go get github.com/ngaut/codis-ha
cd /opt/local/codis/src/github.com/ngaut/codis-ha
go build
启动:
cd /opt/local/codis/bin
./codis-ha --codis-config="127.0.0.1:18087" --productName="mycodis"
------------------------------------------------------------------------------
https://github.com/wlibo666/codis-ha
这个 codis-ha 添加了很多新功能,包括邮件报警,等功能。
codis 新版本 CodisLabs 编译安装的更多相关文章
- 基于源码编译安装openssh
最近的,openssl/openssh等相继漏洞的暴露,让暴露在公网的linux.沦陷为肉鸡的正营... 没办法,还是升级版本... 00.openssh简介 OpenSSH 是一组安全远程的连接工 ...
- centos源码编译安装新版本内核
在工作中,很多时候由于需要使用新的技术方案,需要较新版本的内核来支持新的功能,而centos系统自带的内核版本普遍都比较旧,因此我们需要对系统的内核进行升级,安装新版的内核.本文以centos7系 ...
- Linux下编译安装Vim8.0
什么是Vim? Vim 是经典的 UNIX 编辑器 Vi 的深度改良版本.它增加了许多功能,包括:多级撤销.格式高亮.命令行历史.在线帮助.拼写检查.文件名补完.块操作.脚本支持,等等.除了字符界面版 ...
- 编译安装 Zend Opcache 缓存Opcache,加速 PHP
Optimizer+ 是 Zend 开发的闭源但可以免费使用的 PHP 优化加速组件,是第一个也是最快的 opcode 缓存工具.现在,Zend 科技公司将 Optimizer+ 在 PHP Lice ...
- CentOS手动编译安装gcc
最近尝试了fedora.ubuntu.mint.debian.opensuse等多种linux发行版,与CentOS比较之后还是感觉之前用的CentOS比较熟悉,比较习惯.现在CentOS的最新版本为 ...
- 转-httpd 2.4.4 + mysql-5.5.28 + php-5.4.13编译安装过程
一.编译安装apache 1.解决依赖关系 httpd-2.4.4需要较新版本的apr和apr-util,因此需要事先对其进行升级.升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包.这 ...
- 源码编译安装 MySQL 5.5.x 实践
1.安装cmakeMySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具.因此,我们首先要在系统中源码编译安装cmake工具. # wget ht ...
- LAMP自定义编译安装
httpd 2.4.4 + mysql-5.5.28 + php-5.4.13编译安装过程: 一.编译安装apache 1.解决依赖关系 httpd-2.4.4需要较新版本的apr和apr-util, ...
- 源码编译安装gcc-5.3.0
系统环境:Amazon Linux AMI 2015.09.2 (HVM)---Fedora 23 Server 1.下载gcc-5.3.0安装包并将gcc-5.3.0.tar.gz放到/opt目录下 ...
随机推荐
- 笨方法学python--安装和准备
1 下载并安装python http://python.org/download 下载python2.7. python2.7并不是python3.5的旧版本. python2现在应用较广,网上资料较 ...
- Sublime console installation instructions install Package Control
instructions: import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1 ...
- MyEclipse 2015 运行tomcat 内存溢出的解决方法
内存溢出错误: 2016-3-16 11:19:55 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() ...
- zf-关于交换工具配置文件,交换的“列名字段”前面加个“0,1,2”的意思。
- OpenGL红宝书例3.1 -- glBufferSubData使用
代码实现 1.1 C++部分 GLFWwindow *window; GLuint shader_program; GLuint VAO; void init() { static const GLf ...
- MYSQL和ORACLE的触发器与存储过程语法差异
整改了一番脚本,遇到了一些两种数据库之间的差异,记录一下: 触发器: 差异 MYSQL ORACLE 说明 创建语句不同 create trigger `AA` BEFORE INSERT on `B ...
- jquery 简单的栏目切换
<style> ul{ list-style:none; padding:0px; margin:0px;} #nav_box{ width:502px; height:402px; ov ...
- css 7.30
1.外提到内联元素,我们会想到有个display的属性是display:inline;这个属性能够修复著名的IE双倍浮动边界(float时margin)问题 2.一般来说,可以为所有块级元素应用 te ...
- java 设计模式之单利模式以及代理模式(静态)
1:单利模式: public class Singleton { private static Singleton uniqueInstance = null; private Singleton() ...
- Mysql命令-求一列字段的总和
求和命令 mysql> select SUM(price) from order where create_time>'2016-03-12';+------------+| SUM(pr ...