Zookeeper集群环境搭建

来源:互联网 发布:c语言memset头文件 编辑:程序博客网 时间:2024/05/16 15:27

Zookeeper集群环境搭建

准备工作

  1. 四台centos虚拟机,一台主机控制其他三台
  2. 每台虚拟需要配置JDK ,免登录,由主机统一管理配置
  3. 需要安装的包
    1. 主机httpd服务 yum install -y httpd,方便其他机器下载资源
    2. 主机支持expect 命令 yum -y install expect
    3. 支持http下载 yum install -y wget
    4. 关闭防火墙非常重要 sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

开启自动部署

  1. 主机配置

    1. 配置了httpd服务之后 在var/www/目录下放入jdk
  2. 部署自动登录脚本

    #!/bin/bashSERVERS="192.168.23.41 192.168.23.42 192.168.23.43"PASSWORD=hadoop#遍历所有的 server,配置免登录ssh_copy_id_to_all(){for SERVER in $SERVERSdo auto_ssh_copy_id $SERVERS $PASSWORDdone}ssh_copy_id_to_all#具体实现auto_ssh_copy_id(){expect -c "set timeout -1;    spawn ssh_copy_id $1;    expect {        *(yes/no)* {send -- yes\r;exp_continue;}        *assword:* {send -- $2\r;exp_continue;}        eof         {exit 0;}    }";}#遍历serverfor SERVER in $SERVERSdo scp install.sh root@$SERVER:/rootssh root@$ERVER /root/install.shdone
  3. 自动化部署jdk 注意如果 你的jdk是32位,系统是64位需要yum install -y glibc.i686

    #!/bin/bashBASE_SERVER=192.168.23.4yum install -y wget #yum install -y glibc.i686 32位jdk配置wget $BASE_SERVER/jdk-7u72-linux-i586.gz#解压文件tar zxvf jdk-7u72-linux-i586.gz -C /usr/local#配置环境变量cat >> /etc/profile << EOFexport JAVA_HOME=/usr/local/jdk1.7.0_72export PATH=\SPATH:\$JAVA_HOME/binEOF
  4. 关闭防火墙,否则报host name not find

    sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

集群配置Zookeeper

  1. 配置conf/zoo.cfg

    dataDir=/root/zkData //配置数据存放的位置server.1=192.168.23.41:2888:3888//配置集群server.2=192.168.23.42:2888:3888server.3=192.168.23.43:2888:3888
  2. 在zkData下建立 myid 内容为1,三个主机都要建立,可以用脚本统一搭建

  3. 启动Zookeeper ,成功后可以看到服务器的的角色 leader or follower

    bin/zkServer.sh start  //启动服务器bin/zkServer.sh status //服务工作状态bin/zkServer.sh status //停止服务
0 0
原创粉丝点击