一、linux配置ntp时间同步
(一)确认ntp的安装,保证安装好ntp
1、查看ntp是否存在
rpm –qa | grep ntp
2、如果出现则删除原有的ntp(如果没有出现,此步省略)
yum –y remove ntpdate-....
3、下载ntp
yum –y install ntp
(二)配置ntp文件
1、修改所有节点的/etc/ntp.conf
vi /etc/ntp.conf
打开之后是这个样子,然后添加两行代码
restrict 192.168.6.3 nomodify notrap nopeer noquery //当前节点IP地址
restrict 192.168.6.2 mask 255.255.255.0 nomodify notrap //集群所在网段的网关(Gateway),子网掩码(Genmask)
网关不知道可以用cmd命令查找ipconfig
2、选择一个作为主节点,修改其/etc/ntp.conf
注:选择作为主节点的机器不一定是hadoop的主节点,这可以随意自定,但是选择之前要去查看作为主节点的机器时间是否正确,输入date查看。
如果集群机器时间都不正确可以选择一台进行修改:date -s 填写当前的时间
把原先server注掉,在server部分下面添加如下语句
server 127.127.1.0
Fudge 127.127.1.0 stratum 10 ---每10秒更新一次
3、剩下的机器,修改其/etc/ntp.conf
把原先server注掉,在server部分下面添加如下语句
server 192.168.222.121 --当前主机ip地址
Fudge 192.168.222.121 stratum 10--当前主机ip地址
(三)启动ntp服务、查看状态
1、启动ntp服务
service ntpd start
2、查看ntp服务器有无和上层ntp连通
ntpstat
然后可以输入date进行查看
3、查看ntp服务器与上层ntp的状态
ntpq -p
(四)还可以通过配置设置配置文件让硬件与系统时间同步
vim /etc/sysconfig/ntpd
-----------------------
# 增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
重新启动ntpd
service ntpd status
service ntpd start
chkconfig ntpd on
其他机器配置
crontab -e
----------------
*/10 * * * * /usr/sbin/ntpdate hadoop2
二、zookeeper的安装
安装须知
1.单机不能配置zookeeper
2.配置zookeeper不能配置双数台,只能配置三台、五台这样的hadoop集群。
1、将安装包拖放在相应的位置,解压到想要的文件夹
解压命令:tar -zxvf zookeeper-3.4.6.tar.gz -C /opt
这里是解压到/opt目录下的
为了方便还可以进行改名操作:mv zookeeper-3.4.6/ zookpr
2、修改配置文件
进入zookpr/conf文件夹中,配置zoo.cfg文件
注:里面可能没有zoo.cfg文件此时需要修改文件名,也可以选择复制一份。
# The number of milliseconds of each tick
tickTime=2000
maxClientCnxns=0
# The number of ticks that the initial
# synchronization phase can take
initLimit=50
# 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/hadoop/zookprdata--这值修改数据存放的地方,可以不做修改,但是建议改到hadoop下面
# 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=hadoop101:2888:3888 --hadoop101是主机名
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
将配置文件改名,并传输到其他机器的相应位置
mv zoo_sample.cfg zoo.cfg --将配置文件改名
scp zoo.cfg root@192.168.222.122:/opt/zookpr/conf/ --将改名后的配置文件传输到其他机器相应的位置,并删除其他文件原有的文件
rm -rf zoo_sample.cfg --删除其他机器上原有的文件
刚刚在配置文件的时候设置了数据存放位置要在hadoop下新建相应的文件夹
cd /opt/hadoop --进入hadoop文件,这里的hadoop是被改过名字的
mkdir zookprdata -新建zookeeper数据存放位置
进入zookprdata中,新建myid文件
cd zookprdata/ --进入zookprdata文件夹
vi myid --新建myid文件
在其中写入刚刚配置文件中server后配置的server.的数。
对应机器是几就写几
3、 启动zookeeper
在各zookeeper节点上运行zkServer.sh start。
cd /opt/zookpr--进入zookpr
./bin/zkServer.sh start --启动zookpr
tail zookeeper.out--查看