搭建memcached repcached

简介:

近期因为生产环境需要调整memcached的缓存模式,之前也考虑换redis,因为可能会涉及到应用程序的调整,所以暂时先考虑上memcached repcached模式。

主节点:10.10.10.164    CentOS6.7_x64

从节点:10.10.10.165    CentOS6.7_x64

1)安装依赖关系(时间服务器也要检查下)

1
[root@tomcat01 src] # yum -y install install g++ make libevent-devel

2)配置memcached(主从节点,同样的操作)

1
2
3
4
5
6
[root@tomcat01 ~] # cd /usr/local/src
[root@tomcat01 src] # tar -xf memcached-1.4.24.tar.gz 
[root@tomcat01 memcached-1.4.24] # cd ..
[root@tomcat01 src] # cd memcached-1.4.24
[root@tomcat01 memcached-1.4.24] # make
[root@tomcat01 memcached-1.4.24] # make install

3)配置memcached-repcached(主从节点,同样的操作)

上传memcached-repached包到/usr/local/src下

1
2
3
4
5
[root@tomcat01 src] # tar xf memcached-1.2.8-repcached-2.2.tar.gz 
[root@tomcat01 src] # cd memcached-1.2.8-repcached-2.2
[root@tomcat01 memcached-1.2.8-repcached-2.2] # ./configure --enable-replication
[root@tomcat01 memcached-1.2.8-repcached-2.2] # make
[root@tomcat01 memcached-1.2.8-repcached-2.2] # make install

4)启动主节点

1
2
3
[root@tomcat01 ~] # memcached -v -d -p 11211 -l 10.10.10.164 -u root -P /tmp/memcached1.pid 
[root@tomcat01 ~] # replication: listen
说明:accept为启动正常的状态

5)启动从节点

1
2
3
4
5
[root@tomcat02 ~] # memcached -v -d -p 11211 -l 10.10.10.165 -u root -x 10.10.10.164 -P
  /tmp/memcached1 .pid 
[root@tomcat02 ~] # replication: connect (peer=10.10.10.164:11212)
replication: marugoto copying
replication: start

6)telnet进行验证

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
[root@tomcat01 ~] # telnet 10.10.10.164 11211
Trying 10.10.10.164...
Connected to 10.10.10.164.
Escape character is  '^]' .
set  userId 0 0 5
12345
STORED
[root@tomcat01 ~] # telnet 10.10.10.164 11211
Trying 10.10.10.164...
Connected to 10.10.10.164.
Escape character is  '^]' .
get userId
VALUE userId 0 5
12345
END
[root@tomcat02 src] # replication: connect (peer=10.10.10.164:11212)
replication: marugoto copying
replication: start
replication: close
replication: listen
replication: accept
replication: marugoto start
replication: marugoto 1
replication: marugoto owari
replication: close
replication: listen
说明:以上为连接状态
[root@tomcat02 ~] # telnet 10.10.10.165 11211
Trying 10.10.10.165...
Connected to 10.10.10.165.
Escape character is  '^]' .
get userId
VALUE userId 0 5
12345
END
说明:根据上面的输出结果,可以判断userId的键值为12345

7)模拟故障(如主memcached服务挂掉了)

a、检查从节点上的,memcached储值状态

1
2
3
4
5
6
7
8
9
[root@tomcat02 ~] # telnet 10.10.10.165 11211
Trying 10.10.10.165...
Connected to 10.10.10.165.
Escape character is  '^]' .
get userId    
VALUE userId 0 5
12345
END
说明:从节点的键值仍旧存在

b、在从节点上添加新键值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@tomcat02 ~] # telnet 10.10.10.165 11211
Trying 10.10.10.165...
Connected to 10.10.10.165.
Escape character is  '^]' .
get userId    
VALUE userId 0 5
12345
END
set  userId2 0 0 6
123456
STORED
get userId2
VALUE userId2 0 6
123456
END
说明:添加userId2的新键值,userId2的值为123456

c、恢复主有的节点

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
[root@tomcat01 ~] # memcached -v -d -p 11211 -l 10.10.10.164 -u root -x 10.10.10.165 -P 
/tmp/memcached .pid 
[root@tomcat01 ~] # replication: connect (peer=10.10.10.165:11212)
replication: marugoto copying
replication: start
[root@tomcat01 ~] # telnet 10.10.10.165 11211
Trying 10.10.10.165...
Connected to 10.10.10.165.
Escape character is  '^]' .
get userId
VALUE userId 0 5
12345
END
get userId2
VALUE userId2 0 6
123456
END
# 然后我们在此节点上添加一个新的键值userId3
set  userId3 0 0 7
7654321
STORED
get userId3
VALUE userId3 0 7
7654321
END

d、在另外一台节点上进行验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@tomcat02 ~] # telnet 10.10.10.165 11211
Trying 10.10.10.165...
Connected to 10.10.10.165.
Escape character is  '^]' .
get userId    
VALUE userId 0 5
12345
END
set  userId2 0 0 6
123456
STORED
get userId2
VALUE userId2 0 6
123456
END
get userId3
VALUE userId3 0 7
7654321
END
说明:新添加的键值在此节点上,仍旧存在

e、在10.10.10.165上,设置新键值wanwan

1
2
3
4
5
6
7
set  wanwan 0 0 8
wan08wan
STORED
get wanwan
VALUE wanwan 0 8
wan08wan
END

f、在10.10.10.164上进行查看

1
2
3
4
5
6
7
8
[root@tomcat01 ~] # telnet 10.10.10.164 11211
Trying 10.10.10.164...
Connected to 10.10.10.164.
Escape character is  '^]' .
get wanwan
VALUE wanwan 0 8
wan08wan
END

8)memcached小结:

1
2
a、Repcached 的 Memcached 主从,主从之间可以相互读写
b、由于memcached的主/从没有抢占功能,因此主恢复之后,只能作为现有主节点的从节点









本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1956420,如需转载请自行联系原作者
目录
相关文章
|
9天前
|
数据采集 人工智能 安全
|
5天前
|
机器学习/深度学习 人工智能 前端开发
构建AI智能体:七十、小树成林,聚沙成塔:随机森林与大模型的协同进化
随机森林是一种基于决策树的集成学习算法,通过构建多棵决策树并结合它们的预测结果来提高准确性和稳定性。其核心思想包括两个随机性:Bootstrap采样(每棵树使用不同的训练子集)和特征随机选择(每棵树分裂时只考虑部分特征)。这种方法能有效处理大规模高维数据,避免过拟合,并评估特征重要性。随机森林的超参数如树的数量、最大深度等可通过网格搜索优化。该算法兼具强大预测能力和工程化优势,是机器学习中的常用基础模型。
314 164
|
4天前
|
机器学习/深度学习 自然语言处理 机器人
阿里云百炼大模型赋能|打造企业级电话智能体与智能呼叫中心完整方案
畅信达基于阿里云百炼大模型推出MVB2000V5智能呼叫中心方案,融合LLM与MRCP+WebSocket技术,实现语音识别率超95%、低延迟交互。通过电话智能体与座席助手协同,自动化处理80%咨询,降本增效显著,适配金融、电商、医疗等多行业场景。
320 155
|
5天前
|
编解码 人工智能 自然语言处理
⚽阿里云百炼通义万相 2.6 视频生成玩法手册
通义万相Wan 2.6是全球首个支持角色扮演的AI视频生成模型,可基于参考视频形象与音色生成多角色合拍、多镜头叙事的15秒长视频,实现声画同步、智能分镜,适用于影视创作、营销展示等场景。
359 4
|
12天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
891 6

热门文章

最新文章