搭建Storm高可用集群
此文以Storm 2.2.0版本为例!
如未指定,下述命令在所有节点执行!
系统资源及组件规划
节点名称 | 系统名称 | CPU/内存 | 网卡 | 磁盘 | IP地址 | OS | 节点角色 |
---|
Nimbus1 | nimbus1 | 2C/4G | ens33 | 128G | 192.168.0.11 | CentOS7 | Nimbus | Nimbus2 | nimbus2 | 2C/4G | ens33 | 128G | 192.168.0.12 | CentOS7 | Nimbus | Supervisor1 | supervisor1 | 2C/4G | ens33 | 128G | 192.168.0.21 | CentOS7 | Supervisor、LogViewer、ZooKeeper | Supervisor2 | supervisor2 | 2C/4G | ens33 | 128G | 192.168.0.22 | CentOS7 | Supervisor、LogViewer、ZooKeeper | Supervisor3 | supervisor3 | 2C/4G | ens33 | 128G | 192.168.0.23 | CentOS7 | Supervisor、LogViewer、ZooKeeper |
二、系统软件安装与设置
1、安装基本软件
yum -y install vim lrzsz bash-completion
2、设置名称解析
echo 192.168.0.11 nimbus1 >> /etc/hosts
echo 192.168.0.12 nimbus2 >> /etc/hosts
echo 192.168.0.21 supervisor1 >> /etc/hosts
echo 192.168.0.22 supervisor2 >> /etc/hosts
echo 192.168.0.23 supervisor3 >> /etc/hosts
3、设置NTP
yum -y install chrony
systemctl start chronyd
systemctl enable chronyd
systemctl status chronyd
chronyc sources
4、设置SELinux、防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
三、搭建Storm高可用集群
1、安装JDK
下载JDK文件:
参考地址:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
解压JDK安装文件:
tar -xf /root/jdk-8u291-linux-x64.tar.gz -C /usr/local/
设置环境变量:
export JAVA_HOME=/usr/local/jdk1.8.0_291/
export PATH=$PATH:/usr/local/jdk1.8.0_291/bin/
添加环境变量至/etc/profile文件:
export JAVA_HOME=/usr/local/jdk1.8.0_291/
PATH=$PATH:/usr/local/jdk1.8.0_291/bin/
查看Java版本:
java -version
2、安装ZooKeeper
下载ZooKeeper文件:
参考地址:https://downloads.apache.org/zookeeper/stable/
在Supervisor节点上(ZooKeeper节点)解压ZooKeeper安装文件:
tar -xf /root/apache-zookeeper-3.6.3-bin.tar.gz -C /usr/local/
在Supervisor节点上(ZooKeeper节点)设置环境变量:
export PATH=$PATH:/usr/local/apache-zookeeper-3.6.3-bin/bin/
在Supervisor节点上(ZooKeeper节点)添加环境变量至/etc/profile文件:
PATH=$PATH:/usr/local/apache-zookeeper-3.6.3-bin/bin/
在Supervisor节点上(ZooKeeper节点)创建ZooKeeper数据目录:
mkdir /usr/local/apache-zookeeper-3.6.3-bin/data/
在Supervisor节点上(ZooKeeper节点)创建ZooKeeper配置文件:
mv /usr/local/apache-zookeeper-3.6.3-bin/conf/zoo_sample.cfg /usr/local/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
在Supervisor节点上(ZooKeeper节点)修改ZooKeeper配置文件:
vim /usr/local/apache-zookeeper-3.6.3-bin/conf/zoo.cfg
添加数据目录:
dataDir=/usr/local/apache-zookeeper-3.6.3-bin/data/
添加ZooKeeper节点:
server.1=supervisor1:2888:3888
server.2=supervisor2:2888:3888
server.3=supervisor3:2888:3888
ZooKeeper配置参数解读
Server.A=B:C:D。
A是一个数字,表示这个是第几号服务器;
B是这个服务器的IP地址;
C是这个服务器与集群中的Leader服务器交换信息的端口;
D是当集群中的Leader服务器故障,需要一个端口来重新进行选举,选出一个新的Leader,而端口D就是用来执行选举时服务器相互通信的端口。
集群模式下配置一个文件myid,这个文件在dataDir目录下,这个文件里面有一个数据就是A的值,Zookeeper启动时读取此文件,拿到里面的数据与zoo.cfg里面的配置信息比较从而判断到底是哪个server。
在Supervisor1节点上(ZooKeeper节点)创建myid文件,并添加A值:
touch /usr/local/apache-zookeeper-3.6.3-bin/data/myid
echo 1 > /usr/local/apache-zookeeper-3.6.3-bin/data/myid
在Supervisor2节点上(ZooKeeper节点)创建myid文件,并添加A值:
touch /usr/local/apache-zookeeper-3.6.3-bin/data/myid
echo 2 > /usr/local/apache-zookeeper-3.6.3-bin/data/myid
在Supervisor3节点上(ZooKeeper节点)创建myid文件,并添加A值:
touch /usr/local/apache-zookeeper-3.6.3-bin/data/myid
echo 3 > /usr/local/apache-zookeeper-3.6.3-bin/data/myid
在Supervisor节点上(ZooKeeper节点)启动ZooKeeper:
zkServer.sh start
在Supervisor节点上(ZooKeeper节点)查看ZooKeeper状态:
zkServer.sh status
3、安装Storm集群
下载Storm文件:
参考地址:http://storm.apache.org/downloads.html
解压Storm安装文件:
tar -xf /root/apache-storm-2.2.0.tar.gz -C /usr/local/
设置环境变量:
export PATH=$PATH:/usr/local/apache-storm-2.2.0/bin/
添加环境变量至/etc/profile文件:
PATH=$PATH:/usr/local/apache-storm-2.2.0/bin/
Nimbus节点/etc/profile文件:
Supervisor节点/etc/profile文件:
查看Storm版本:
storm version
4、配置Storm集群
修改/usr/local/apache-storm-2.2.0/conf/storm.yaml文件:
storm.zookeeper.servers:
- "supervisor1"
- "supervisor2"
- "supervisor3"
nimbus.seeds: ["nimbus1", "nimbus2"]
storm.local.dir: "/usr/local/apache-storm-2.2.0/workdir"
supervisor.slots.ports:
- 6700
- 6701
- 6702
5、启动Storm集群
在Nimbus节点上启动Nimbus:
nohup storm nimbus &
在Nimbus节点上启动UI:
nohup storm ui &
在Supervisor节点上启动Supervisor:
nohup storm supervisor &
在Supervisor节点上启动LogViewer:
nohup storm logviewer &
在各类节点上查看Storm进程:
jps
登录Nimbus:
http://192.168.0.11:8080
http://192.168.0.12:8080
6、Storm集群故障演示
在任意Nimbus节点上查看Nimbus状态:
Nimbus1节点故障,主从节点已切换
关闭Nimbus1节点
在Nimbus2节点上查看Nimbus状态:
恢复Nimbus1节点,启动Nimbus与UI
在任意Nimbus节点上查看Nimbus状态:
Nimbus1节点恢复,主从节点未切换
|