搜索
首页数据库mysql教程 codis实现redis分片和在线扩展

Codis是一个开源的分布式redis解决方案,由以下四个组件组成:codis-proxy:后端redis的代理,本事实现了redis协议。codis-config:是codis的管理配置工具,用于..

Codis是一个开源的分布式redis解决方案,由以下四个组件组成:

    codis-proxy:后端redis的代理,本事实现了redis协议。

    codis-config:是codis的管理配置工具,用于增删redis server、操作数据迁移。

    zookeeper:用来存放数据路由表和codis-proxy节点的元信息,codis-config发起的命令都会通过 zookeeper同步到各个存活的codis-proxy。

    codis-server:codis项目维护的一个 redis 分支, 基于 2.8.13 开发, 加入了 slot 的支持和原子的数据迁移指令,如果要使用codis的在线扩展迁移功能的话必须使用codis自带的codis-server,codis不支持对原生redis做在线的扩展和数据迁移。


节点规划:

codis-proxy
192.168.0.100:19000

codis-config
192.168.0.100

codis-server1
192.168.0.100:6381

codis-server2192.168.0.100:6382

codis-server3192.168.0.100:6380

codis-server4192.168.0.100:6383


1、安装配置

    a、首先安装golang  

## 解压下载好的go软件包 $ tar xf/opt/go1.4.2.linux-amd64.tar.gz  -C/usr/local/ ## 配置环境变量 在.bash_profile中加入go的相关环境变量,并使新的环境变量生效 PATH=$PATH:$HOME/bin exportGOROOT=/usr/local/go exportGOOS=linux exportGOARCH=amd64 exportGOBIN=$GOROOT/bin exportGOPATH=/opt/mygo PATH=$PATH:$GOBIN export PATH ##编写一个 测试程序验证go是否安装成功 $ cat hello.go package main import"fmt" func main() {     fmt.Printf("hello, world\n") } ## 运行测试程序,输出hello,word说明go已经安装成功 $ go  run hello.go hello, world

    b、安装codis

## 安装工具软件 $ yum install gccmake git  -y  ## 下载codis,会下载到环境变量GOPATH指定的目录 $ go get github.com/wandoulabs/codis#ssdb-server config packagegithub.com/wandoulabs/codis         imports github.com/wandoulabs/codis         imports github.com/wandoulabs/codis: nobuildable Go source files in /opt/mygo/src/github.com/wandoulabs/codis ## 下载完成后进入/opt/mygo/src/github.com/wandoulabs/codis $ cd /opt/mygo/src/github.com/wandoulabs/codis ## 执行安装命令 $ ./bootstrap.sh ## 这一步时间稍久,会下载一些文件目录到本地,耐心等待即可

    c、安装zookeeper

## 解压zookeeper $ tar xfzookeeper-3.4.6.tar.gz  -C /opt/ ## 进入zk的安装目录,修改配置文件 $ cd /opt/zookeeper-3.4.6 $ cp conf/zoo_sample.cfgconf/zoo.cfg $ vim conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/data/zookeeper dataLogDir=/opt/zookeeper-3.4.6/logs clientPort=2181 ## 创建所需要的目录 mkdir  /data/zookeeper   -p mkdir  /opt/zookeeper-3.4.6/logs ## 启动zk $ /opt/zookeeper-3.4.6/bin/zkServer.sh  start    JMX enabled bydefault Using config:/opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Starting zookeeper... STARTED   ## 验证是否启动成功,若2181端口被监听,则表示成功 $ netstat-alnut|grep 2181 tcp       0      0 :::2181                     :::*                        LISTEN

    d、配置codis

## codis中配置zk的信息 $ cd /opt/mygo/src/github.com/wandoulabs/codis/sample/ ## 修改config.ini $  vim config.ini zk=localhost:2181 product=codis_proxy proxy_id=proxy_1 net_timeout=5 dashboard_addr=localhost:18087 coordinator=zookeeper


2、启动codis

    a、

## 进入相关目录 $ cd /opt/mygo/src/github.com/wandoulabs/codis/sample/ ## 启动dashboard ./start_dashboard.sh ## 验证是否成功 $  netstat -alnut|grep 18087 tcp        0     0 :::18087                    :::*                        LISTE

    :

wKiom1UzsX2jZXyrAAHkBfk1YvA122.jpg

    b、初始化slots

##进入相关目录 $ cd  /opt/mygo/src/github.com/wandoulabs/codis/sample/ ## 执行初始化 $  ../bin/codis-config  slot init {  "msg": "OK",  "ret": 0 }

    c、启动codis-server

## codis自带有一个启动脚本,会启动两个codis-server,监听端口为6381和6382 [root@mgs02 sample]#./start_redis.sh  sleep 3s [6294] 09 Apr 14:28:02.796* Increased maximum number of open files to 10032 (it was originally set to1024).                 _._                                                             _.-``__ ''-._                                                   _.-``   `.  `_.  ''-._           Redis 2.8.13 (1e823fd3/1) 64 bit   .-`` .-```. ```\/    _.,_ ''-._                                    (   '      ,       .-` | `,    )     Running in stand alone mode  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6381  |   `-._   `._    /    _.-'    |     PID: 6294   `-._   `-._  `-./  _.-'   _.-'                                    |`-._`-._   `-.__.-'    _.-'_.-'|                                   |   `-._`-._        _.-'_.-'    |                    `-._   `-._`-.__.-'_.-'    _.-'                                    |`-._`-._   `-.__.-'    _.-'_.-'|                                   |   `-._`-._        _.-'_.-'    |                                    `-._   `-._`-.__.-'_.-'    _.-'                                          `-._   `-.__.-'    _.-'                                                 `-._        _.-'                                                         `-.__.-'                                                 [6294] 09 Apr14:28:02.814 # Server started, Redis version 2.8.13 [6294] 09 Apr14:28:02.814 # WARNING overcommit_memory is set to 0! Background save may failunder low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to/etc/sysctl.conf and then reboot or run the command 'sysctlvm.overcommit_memory=1' for this to take effect. [6294] 09 Apr14:28:02.814 * The server is now ready to accept connections on port 6381 [6295] 09 Apr14:28:02.795 * Increased maximum number of open files to 10032 (it wasoriginally set to 1024).                 _._                                                             _.-``__ ''-._                                                   _.-``   `.  `_.  ''-._           Redis 2.8.13 (1e823fd3/1) 64 bit   .-`` .-```. ```\/    _.,_ ''-._                                     (   '      ,       .-` | `,    )     Running in stand alone mode  |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6382  |   `-._   `._    /    _.-'    |     PID: 6295   `-._   `-._  `-./  _.-'   _.-'                                     |`-._`-._   `-.__.-'    _.-'_.-'|                                   |   `-._`-._        _.-'_.-'    |                    `-._   `-._`-.__.-'_.-'    _.-'                                    |`-._`-._   `-.__.-'    _.-'_.-'|                                   |   `-._`-._        _.-'_.-'    |                                    `-._   `-._`-.__.-'_.-'    _.-'                                         `-._   `-.__.-'    _.-'                                                 `-._       _.-'                                                         `-.__.-'                                                 [6295] 09 Apr14:28:02.811 # Server started, Redis version 2.8.13 [6295] 09 Apr14:28:02.811 # WARNING overcommit_memory is set to 0! Background save may failunder low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to/etc/sysctl.conf and then reboot or run the command 'sysctlvm.overcommit_memory=1' for this to take effect. [6295] 09 Apr 14:28:02.812 * The server is nowready to accept connections on port 6382
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
如何向新的MySQL用户授予权限如何向新的MySQL用户授予权限May 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

如何在MySQL中添加用户:逐步指南如何在MySQL中添加用户:逐步指南May 09, 2025 am 12:14 AM

toadduserInmysqleffectection andsecrely,theTheSepsps:1)USEtheCreateuserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNectalRevileSaryPrivilegesSustate,usiveleanttatement,AdheringTotheTeprinciplelastPrevilegege.3)

mysql:添加具有复杂权限的新用户mysql:添加具有复杂权限的新用户May 09, 2025 am 12:09 AM

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)创建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。3)GrantWriteAccessto'

mysql:字符串数据类型和coltrationsmysql:字符串数据类型和coltrationsMay 09, 2025 am 12:08 AM

MySQL中的字符串数据类型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序规则(Collations)决定了字符串的比较和排序方式。1.CHAR适合固定长度字符串,VARCHAR适合可变长度字符串。2.BINARY和VARBINARY用于二进制数据,BLOB和TEXT用于大对象数据。3.排序规则如utf8mb4_unicode_ci忽略大小写,适合用户名;utf8mb4_bin区分大小写,适合需要精确比较的字段。

MySQL:我应该在Varchars上使用什么长度?MySQL:我应该在Varchars上使用什么长度?May 09, 2025 am 12:06 AM

最佳的MySQLVARCHAR列长度选择应基于数据分析、考虑未来增长、评估性能影响及字符集需求。1)分析数据以确定典型长度;2)预留未来扩展空间;3)注意大长度对性能的影响;4)考虑字符集对存储的影响。通过这些步骤,可以优化数据库的效率和扩展性。

mysql blob:有什么限制吗?mysql blob:有什么限制吗?May 08, 2025 am 12:22 AM

mysqlblobshavelimits:tinyblob(255bytes),blob(65,535 bytes),中间布洛布(16,777,215个比例),andlongblob(4,294,967,967,295 bytes).tousebl观察性:1)考虑performance impactsandSandStorelargeblobsextern; 2)管理backbackupsandreplication carecration; 3)usepathsinst

MySQL:自动化用户创建的最佳工具是什么?MySQL:自动化用户创建的最佳工具是什么?May 08, 2025 am 12:22 AM

自动化在MySQL中创建用户的最佳工具和技术包括:1.MySQLWorkbench,适用于小型到中型环境,易于使用但资源消耗大;2.Ansible,适用于多服务器环境,简单但学习曲线陡峭;3.自定义Python脚本,灵活但需确保脚本安全性;4.Puppet和Chef,适用于大规模环境,复杂但可扩展。选择时需考虑规模、学习曲线和集成需求。

mysql:我可以在斑点内搜索吗?mysql:我可以在斑点内搜索吗?May 08, 2025 am 12:20 AM

是的,YouCansearchInIdeAblobInMysqlusingsPecificteChniques.1)转换theblobtoautf-8StringWithConvertFunctionWithConvertFunctionandSearchusiseLike.2)forCompresseBlyblobs,useuncompresseblobs,useuncompressbeforeconversion.3)acpperformance impperformance imperformance imptactsanddataEccoding.4)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。