zookeeper的安装使用

 准备三台服务器(虚拟机)

修改静态IP

[root@server2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.238.133
PREFIX=24
GATEWAY=192.168.238.1
DNS1=114.114.114.114
DNS2=172.16.2.229

 重启网络

service network restart

 

如果修改静态IP后使用SecureCRT,winscp,xshell等ssh远程连接Linux系统时会发现连接速度十分缓慢,有时需要等待几十秒的时间

编辑sshd_config文件

[root@server2 ~]# vim /etc/ssh/sshd_config
UseDNS no
#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See

重启SSHD服务

service sshd restart

 

修改主机名

[root@localhost .ssh]# vim /etc/sysconfig/network 

如下

NETWORKING=yes
HOSTNAME=server1

IP地址映射

[root@localhost .ssh]# vim /etc/hosts

填入如下(三台一致)

192.168.238.128 server1
192.168.238.133 server2
192.168.238.132 server3

 本地win10系统也需要添加进入host文件里(具体百度)

 

三台集群机器关闭selinux

 

[root@localhost conf]# vim /etc/selinux/config

 

修改如下

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled #关闭selinux
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

创建用户

[root@server1 ~]# useradd hadoop

修改密码

[root@server1 ~]# passwd hadoop
Changing password for user hadoop.
New password:

授权

复制代码
chown hadoop:hadoop /opt/software /opt/servers /opt/module
[root@server1 ~]# ll /opt
total 0
drwxr-xr-x. 3 hadoop hadoop 60 Nov 28 15:34 module
drwxr-xr-x  4 hadoop hadoop 79 Dec  3 15:35 servers
drwxr-xr-x. 2 hadoop hadoop 74 Nov 29 15:03 software
复制代码

把用户加载到sudoers

[root@server1 ~]# vim /etc/sudoers
## Allow root to run any commands anywhere 
root    ALL=(ALL)     ALL
hadoop  ALL=(ALL)      NOPASSWD:ALL

切换到用户

[root@server1 ~]# su hadoop

三台机器的SSH免密登录

 生成密钥(三台服务器都要执行)

ssh-keygen -t rsa

拷贝公钥到第一台(三台都要依次执行

ssh-copy-id server1

根据提示填写yes 然后输入密码即可

[hadoop@server1 .ssh]$ ssh-copy-id server1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoop/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@server1's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'server1'"
and check to make sure that only the key(s) you wanted were added.

 三台机器执行完毕后把公钥拷贝到其它两台(这样三台机器都有所有公钥)

在第一台机器上执行

 拷贝给第二台

[hadoop@server1 .ssh]$ scp /home/hadoop/.ssh/authorized_keys server2:/home/hadoop/.ssh
The authenticity of host 'server2 (192.168.238.133)' can't be established.
ECDSA key fingerprint is SHA256:fFbDpouHRJnuai5Vlp8/tdN2yBhLICOo2lVsxRKAAWE.
ECDSA key fingerprint is MD5:39:23:03:a1:06:a6:a3:e4:74:7e:38:6d:a1:40:59:99.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server2,192.168.238.133' (ECDSA) to the list of known hosts.
root@server2's password: 
authorized_keys 

同理拷贝给第三台

[hadoop@server1 .ssh]$ scp /home/hadoop/.ssh/authorized_keys server3:/home/hadoop/.ssh

验证是否可以免密登录其它机器

[root@server1 .ssh]# ssh server2
Last login: Fri Nov 29 11:08:47 2019 from 192.168.238.188
[root@server2 ~]# 

 时间同步

下载ntp

[root@server3 ~]# yum install -y ntp

设置定时服务

[root@server1 .ssh]# crontab -e

[root@server1 .ssh]# crontab -e
no crontab for root - using an empty one

*/1 * * * * /usr/sbin/ntpdate ntp4.aliyun.com;

 

下载zookeeper

http://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/

 

上传到/opt/servers

解压

[root@localhost servers]# tar -zxvf zookeeper-3.4.9.tar.gz

进入/opt/servers/zookeeper-3.4.9/conf

拷贝一份

[root@localhost conf]# cp zoo_sample.cfg zoo.cfg

建立新文件夹

[root@localhost conf]# mkdir -p /opt/servers/zookeeper-3.4.9/zkdatas

配置zoo.cfg

[root@localhost conf]# vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/servers/zookeeper-3.4.9/zkdatas
# 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

server.1=server1:2888:3888
server.2=server2:2888:3888
server.3=server3:2888:3888

 

 创建myid文件,server1机器的内容为:1

[root@localhost conf]# echo 1 > /opt/servers/zookeeper-3.4.9/zkdatas/myid

 分发配置内容给其它服务器

[root@server1 ~]# scp -r /opt/servers/zookeeper-3.4.9/ server2:/opt/servers

第二台跟第三台的myid内容设置为2 和3

启动

[root@server1 zookeeper-3.4.9]# bin/zkServer.sh start

查看启动状态

[root@server3 zookeeper-3.4.9]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/servers/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader

 

posted @ 2019-11-29 09:35  丹尼伯夷  阅读(212)  评论(0编辑  收藏  举报