复古 护眼 海天 深邃 暗黑 默认
Logo
快速搭建示例集群

快速搭建示例集群 #

这部分指导用户如何使用 SphereEx-Boot 快速建立一个本地示例集群。

服务器规划

  • 部署机IP:127.0.0.1
  • 登录账号:root
  • 密码:root

说明:操作时需要替换为自己的 IP 地址、登录账号和密码。

前提条件

主控机和部署机需要通过 sshpass 进行 SSH 账号密码登录互信授权。

验证主控机是否可以使用账号和密码登录到部署机。

$ ssh root@127.0.0.1
[root@centos71 .ssh]# ssh root@127.0.0.1
Last login: Tue Dec 21 15:33:32 2021 from 127.0.0.1

操作步骤

假设集群名称为 demo。

  1. 创建集群。
$ mkdir demo 
$ cd demo
$ spex cluster init --name demo --download all
$ ls -l
total 126672
-rw-r--r-- 1 spex-demo  48M 12 9 14:46 apache-shardingsphere-5.0.0-shardingsphere-proxy-bin.tar.gz
-rw-r--r-- 1 spex-demo  12M 12 9 14:46 apache-zookeeper-3.6.3-bin.tar.gz
-rw-r--r-- 1 spex-demo  741B 12 9 14:47 cluster-config.yaml
drwxr-xr-x 9 spex-demo  288B 12 9 14:54 conf
-rw-r--r-- 1 spex-demo  984K 12 9 14:47 mysql-connector-java-5.1.47.jar
-rw-r--r-- 1 spex-demo  1.1K 12 9 14:47 zoo.cfg
  1. 添加集群配置文件到 SphereEx-Boot 工具管理环境。
[root@centos71 demo]# spex config add -f cluster-config.yaml 
Successfully add cluster
  1. 安装集群。
$ spex cluster install --name demo 
Operation ShardingSphere-Proxy
check proxy install dir exist!          
Completed....... 
Operation ShardingSphere-Proxy
create install directory          
127.0.0.1 : 3307 => success
install proxy          
127.0.0.1 : 3307 => success
copying shell file          
127.0.0.1 : 3307 => success
copying config file          
127.0.0.1 : 3307 => success
copying agent config file          
skipped host:127.0.0.1 item : None
copying depend file          
127.0.0.1 : 3307 => success
Completed......
  1. 启动集群。
$ spex cluster start --name demo  
Operation ShardingSphere-Proxy
start proxy          
127.0.0.1 : 3307 => success
The port is 3307
The classpath is /root/shardingsphere-proxy/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin/conf:.:/root/sharding-proxy/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin/lib/*:/root/sharding-proxy/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin/ext-lib/*
Please check the STDOUT file: /root/sharding-proxy/apache-shardingsphere-5.0.0-shardingsphere-proxy-bin/logs/stdout.log
Completed......
  1. 查看集群运行状态。
$ spex cluster status --name demo  
Operation ShardingSphere-Proxy
proxy status          
127.0.0.1 : 3307 => success
PID:6355 PORT:3307 %CPU:20.6 %MEM:10.1 START:00:33 TIME:0:03
Results summary
+--------------+------+------+------+------+-------+------+
|     HOST     | PORT | PID  | %CPU | %MEM | START | TIME |
+--------------+------+------+------+------+-------+------+
| 127.0.0.1    | 3307 | 6355 | 20.6 | 10.1 | 00:33 | 0:03 |
+--------------+------+------+------+------+-------+------+
Completed......
Operation ZooKeeper
zookeeper status          
127.0.0.1 : 2181 => success
/usr/bin/java
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Results summary
+--------------+------+------------------+
|     HOST     | PORT |      STATUS      |
+--------------+------+------------------+
| 127.0.0.1    | 2181 | Mode: standalone |
+--------------+------+------------------+
Completed......
  1. 卸载集群。

当用户需要卸载安装的 demo 集群时,执行命令 $ spex cluster uninstall --name demo 卸载相应的集群。

$ spex cluster uninstall --name demo 
Are you sure to uninstall demo cluster ? [y/N]: y
Operation ShardingSphere-Proxy
stop proxy          
127.0.0.1 : 3307 => success
ShardingSphere-Proxy does not started!
remove install directory          
127.0.0.1 : 3307 => success
Completed......
Operation ZooKeeper
stop zookeeper          
127.0.0.1 : 2181 => success
/usr/bin/java
Stopping zookeeper ... no zookeeper to stop (could not find file /root/zookeeper/data/zookeeper_server.pid)
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
remove zookeeper data directory          
127.0.0.1 : 2181 => success
remove zookeeper install directory          
127.0.0.1 : 2181 => success
Completed......