redis数据库笔记第8篇:配置机器2,数据验证

28 阅读1分钟

🚀🚀🚀本篇主要内容

配置机器2

* 在演示中,172.16.179.131为当前ubuntu机器的ip * 在172.16.179.131上进⼊Desktop⽬录,创建conf⽬录 * 在conf⽬录下创建⽂件7003.conf,编辑内容如下

port 7003
bind 172.16.179.131
daemonize yes
pidfile 7003.pid
cluster-enabled yes
cluster-config-file 7003_node.conf
cluster-node-timeout 15000
appendonly yes

* 在conf⽬录下创建⽂件7004.conf,编辑内容如下

port 7004
bind 172.16.179.131
daemonize yes
pidfile 7004.pid

# 创建集群
  
  


[文档连接](http://doc.redisfans.com/topic/cluster-tutorial.html)

* redis的安装包中包含了redis-trib.rb,⽤于创建集群
* 接下来的操作在172.16.179.130机器上进⾏
* 将命令复制,这样可以在任何⽬录下调⽤此命令

```python
sudo cp /usr/share/doc/redis-tools/examples/redis-trib.rb /usr/local/bin/

* 安装ruby环境,因为redis-trib.rb是⽤ruby开发的 > sudo apt-get install ruby

* 在提示信息处输⼊y,然后回⻋继续安装

* 运⾏如下命令创建集群



# 数据验证
  
  


* 根据上图可以看出,当前搭建的主服务器为700070017003,对应的从服务器是700470057002
* 在172.16.179.131机器上连接7002,加参数-c表示连接到集群
> 
redis-cli -h 172.16.179.131 -c -p 7002

* 写⼊数据
> 
set name itheima

* ⾃动跳到了7003服务器,并写⼊数据成功<br></br>![](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a424dc74258048c1a69d59ab8dee6838~tplv-k3u1fbpfcp-watermark.image#?w=612&h=73&s=11665&e=png&b=414624)

* 在7003可以获取数据,如果写入数据又重定向到7000(负载均衡)<br></br>![](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e77f7caa2ab7441e802ec918adeca5bd~tplv-k3u1fbpfcp-watermark.image#?w=539&h=102&s=11950&e=png&b=414624)