CentOS 7 虚拟机搭建zookeeper集群

    xiaoxiao2021-03-25  120

    物理机网络打通 在虚拟网络编辑器中,将VMnet8的“将主机虚拟适配器连接到此网络”勾选上 在物理机的网络适配器中将VMnet8网卡的ipv4中的ip和子网掩码修改为虚拟网络编辑器中的网关 至此,网络连接完毕!设置ssh无密码登陆 设置ip和hostname映射 使用hostnamectl set-hostname vm01修改hostname,修改完成后可使用hostnamectl –static查看静态hostname,hostname也行建立ip和hostname的映射。 su - rootvi /etc/hosts,映射格式为:ip hostname注意:对于本机应该有三个记录,分贝为127.0.0.1和服务器ip对应的localhost,以及该服务器在集群中的hostname 为防止有旧文件影响,先删除~/.ssh(不存在该文件的跳过)mkdir ~/.ssh,并进行授权chmod 755 ~/.sshcd ~/.ssh/,执行ssh-keygen -t rsa,一直按回车键(共三次),生成私钥id_rsa和公钥id_rsa.pub文件,查看id_rsa.pub结尾是以设置的本机hostname结尾,如果不是请删掉重来 将公钥发送到需要登陆到这台服务器上的服务器 scp id_rsa.pub xieyw@vm03:/home/xieyw/.ssh/authorized_keys_from_vm02 scp id_rsa.pub xieyw@vm01:/home/xieyw/.ssh/authorized_keys_from_vm02在vm01、vm03上生成各自的密钥文件。然后使用>>将密钥追加到自己的密钥文件中。 如果三台机器需要互相访问,则最后三台机器上的密钥文件应该包含这三台机器的公钥 同步完authorized_keys文件后,需要对.ssh目录下的所有文件进行授权,我这里的授权为:chmod 600 ~/.ssh/*验证:ssh vm01,第一次需要进行连接确认操作,如果不需要密码直接登陆,则设置至此完成,如果失败,请按照上述重新操作。配置jdk环境 CentOS自带一个openJDK,我们一般使用j2se的jdk,所以先进行卸载: 首先查看其安装源: rpm -qa | grep java卸载:rpm -e –nodeps java-1.4.2-gcj-c*安装jdk 为当前用户安装:vim ~/.bashrc 为所有用户安装:vim /etc/profile export JAVA_HOME=/home/xieyw/jdk1.8.0_111 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JRE_HOME=$JAVA_HOME/jre 3. 检查

    4. 设置zookeeper启动参数 1. 准备工作 这里将zookeeper解压在zookeeper下 新建两个文件夹,后面用 mkdir data mkdir dataLog cd zookeeper-3.4.6/conf/ 可以看到里面有三个文件,我们将zoo_sample.cfg进行复制。 cp zoo_sample.cfg zoo.cfg,注意名字需要一致,zookeeper会自动解析zoo.cfg文件 2. vim zoo.cfg

    #tickTime是时间的单位,这里的意思是指后面的时间单位为2s tickTime=2000 # The number of ticks that the initial # synchronization phase can take #启动时间最长20s initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement #响应最长时间10s syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #指向上面新建的data文件夹的路径,存放zk数据 dataDir=/home/xieyw/zookeeper/data #指向上面新建的dataLog文件夹的路径,存放zk日志 dataLogDir=/home/xieyw/zookeeper/dataLog # the port at which the clients will connect #客户端端口 clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 #配置zk集群的主机路径。1表示主机的唯一标识,要求唯一,可以随便设置 server.1=vm01:2888:3888 server.2=vm02:2888:3888 server.3=vm03:2888:3888

    回到zookeeper下的data目录,新建myid文件,并赋值为2(当前主机为vm02),myid的值需要和zoo.cfg里面配置的zk集群主机的server后面的值对应,zk通过扫描dataDir路径下的myid文件来确定当前主机的身份 5. 关闭防火墙 CentOS的防火墙不是iptables,而是firewall,所以需要对防火墙进行关闭需要执行以下命令: systemctl stop firewalld.service 关闭开机启动防火墙: systemctl disable firewalld.service 6. 启动zk集群 在bin下,执行./zkServer.sh start启动zk 查看状态./zkServer.sh status 注意这里三台机器zk的启动需要在20s(initLimit=10)内完成

    complete!

    转载请注明原文地址: https://ju.6miu.com/read-9596.html

    最新回复(0)