一, NTP 配置时间服务器 1.1, 检查当前系统时区 1.2, 同步时间 1.3, 检查软件包 1.4, 修改 ntp 配置文件 1.5, 重启 ntp 服务 1.6, 设置定时同步任务二, Linux 集群服务群起脚本 2.1, 介绍 2.2, 编写脚本三, CentOS6.8 升级到 python 到 2.73.1, 环境准备 3.2, 安装 Python2.7
一, NTP 配置时间服务器
当集群中各个节点的时间不同步, 误差超过某个范围时, 会导致一些集群的服务无法正常进行, 这时我们应该想办法做一个定时同步集群所有节点时间的任务.
1.1, 检查当前系统时区
选择某台机器, 作为集群中时间服务器的主节点, 然后其他机器同步该机器的时间即可. 但是在开始这步操作之前, 我们需要确保所有节点的时区是统一的:
# date -R
显示类似如下格式:
Sat, 07 Oct 2017 12:44:58 +0800
尖叫提示: 如果显示的时区不是 + 0800, 你可以删除 localtime 文件夹后, 再关联一个正确时区的软链接过去:
- # rm -rf /etc/localtime
- # ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
1.2, 同步时间
如果怀疑自己本地机器的时间与标准时间相差很多, 建议使用时间服务器的主节点同步一下网络时间:
# ntpdate pool.ntp.org
1.3, 检查软件包
1) 后边我们要使用 ntp 服务, 所以在使用该服务之前, 建议检查一下 ntp 服务是否正确安装
# rpm -qa | grep ntp
显示如下:
- ntp-4.2.6p5-10.el6.CentOS.x86_64
- fontpackages-filesystem-1.41-1.1.el6.noarch
- ntpdate-4.2.6p5-10.el6.CentOS.x86_64
2) 如果没有 ntp 服务, 可使用 yum 命令进行安装
# yum -y install ntp
1.4, 修改 ntp 配置文件
我们需要修改 ntp 服务的配置文件, 关闭网络时间的同步:
# VIM /etc/ntp.conf
对如下内容做出修改:
- # Hosts on local network are Less restricted.
- # 授权 192.168.25.0 网段上的所有机器可以从这台机器上查询和同步时间
- restrict 192.168.25.0 mask 255.255.255.0 nomodify notrap
- # 当该节点丢失网络连接, 依然可以作为时间服务器为集群中的其他节点提供时间同步
- server 127.127.1.0
- fudge 127.127.1.0 stratum 10
- # Please consider joining the pool (http://www.pool.ntp.org/join.html).
- # 集群在局域网中, 不使用其他的网络时间
- #server 0.CentOS.pool.ntp.org iburst
- #server 1.CentOS.pool.ntp.org iburst
- #server 2.CentOS.pool.ntp.org iburst
- #server 3.CentOS.pool.ntp.org iburst
尖叫提示:
nomodify: 客户端不能使用 ntpc 与 ntpq 修改服务器的时间参数
notrap: 不提供 trap 远程时间登录的功能
1.5, 重启 ntp 服务
- CentOS6:
- # service ntpd restart
- # chkconfig ntpd on
- CentOS7:
- # systemctl restart ntpd.service
- # systemctl enable ntpd.service
1.6, 设置定时同步任务
1) 首先在其他节点上关闭 ntp 服务
- CentOS6:
- # service ntpd stop
- # chkconfig ntpd off
- CentOS7:
- # systemctl stop ntpd.service
- # systemctl disable ntpd.service
查看 ntp 进程 id:
# pgrep ntpd
2) 其他节点手动同步第一台时间服务器的时间进行测试
# ntpdate hadoop102
3) 其他节点制定计划任务, 周期性同步时间
- # crontab -e
- # .------------------------------------------minute(0~59)
- # | .----------------------------------------hours(0~23)
- # | | .--------------------------------------day of month(1~31)
- # | | | .------------------------------------month(1~12)
- # | | | | .----------------------------------day of week(0~6)
- # | | | | | .--------------------------------command
- # | | | | | |
- # | | | | | |
- */10 * * * * /usr/sbin/ntpdate hadoop102
4) 重启定时任务
- CentOS6:
- # service crond restart
- CentOS7:
- # systemctl restart crond.service
5) 查看任务
# crontab -l
二, Linux 集群服务群起脚本
2.1, 介绍
写这个脚本, 纯粹是为了偷懒, 方便, 不然用 Linux 干嘛?
目的: 在一台服务器上执行一个脚本, 启动所有集群节点上的相关进程.
描述: Resourcemanager,HMaster 和 Zookeeper 等节点可能需要登录到节点所在机器启动.
在开始之前呢, 我们先了解一些概念:
登录 Shell: 粗放来讲, 就是你手动使用 CRT 登录 Linux 的时候. 此种情形, 系统环境信息的读取顺序:/etc/profile,~/.bash_profile,~/.bash_login,~/.profile
非登录 Shell: 粗放来讲, 就是你使用 SSH 登录某台机器的时候. 此种情形, 系统环境信息的读取顺序:/etc/bash.bashrc,~/.bashrc
解决方案: 了解完 Shell 这个小知识之后, 你应该明白 SSH 到远程节点启动的对应服务的时候, 其实是没有 JDK 配置的环境的, 所以, 在每台机器中先执行:
$ cat /etc/profile >> ~/.bashrc
将我们配置的 profile 变量追加到 .bashrc 中即可.
2.2, 编写脚本
1) 启动脚本: start-cluster.sh
- #!/bin/bash
- echo "================ 开始启动所有节点服务 ==========="
- echo "================ 正在启动 Zookeeper ==========="
- for i in atguigu@hadoop102 atguigu@hadoop103 atguigu@hadoop104
- do
- SSH $i 'source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh start'
- done
- echo "================ 正在启动 HDFS ==========="
- SSH atguigu@hadoop102 '/opt/module/hadoop-2.7.2/sbin/start-dfs.sh'
- echo "================ 正在启动 YARN ==========="
- SSH atguigu@hadoop103 '/opt/module/hadoop-2.7.2/sbin/start-yarn.sh'
- echo "================ hadoop102 节点正在启动 JobHistoryServer ==========="
- SSH atguigu@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh start historyserver'
2) 停止脚本: stop-cluster.sh
- #!/bin/bash
- echo "================ 开始停止所有节点服务 ==========="
- echo "================ hadoop102 节点正在停止 JobHistoryServer ==========="
- SSH atguigu@hadoop102 '/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh stop historyserver'
- echo "================ 正在停止 YARN ==========="
- SSH atguigu@hadoop103 '/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh'
- echo "================ 正在停止 HDFS ==========="
- SSH atguigu@hadoop102 '/opt/module/hadoop-2.7.2/sbin/stop-dfs.sh'
- echo "================ 正在停止 Zookeeper ==========="
- for i in atguigu@hadoop102 atguigu@hadoop103 atguigu@hadoop104
- do
- SSH $i 'source /etc/profile;/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop'
- done
3) 查看进程脚本: util.sh
- #!/bin/bash
- for i in atguigu@hadoop102 atguigu@hadoop103 atguigu@hadoop104
- do
- echo "================ $i 的所有进程 ==========="
- SSH $i '/opt/module/jdk1.8.0_144/bin/jps'
- done
尖叫提示: 脚本学会之后, 如果后续再有新的节点需要添加到群起任务中, 可以自行解决之.
尖叫提示: 启动与停止注意脚本的执行顺序, 而且停止脚本的停止过程应该是启动过程的倒序.
三, CentOS6.8 升级到 python 到 2.7
由于 HUE 框架依赖 python2.7, 而 CentOS7 以下的系统使用的都是 python2.6, 并且 CentOS6.8 的 yum 也是依赖 2.6, 所以升级过程会稍微繁琐, 特此予以讲解.
3.1, 环境准备
1) 查看 python 版本
# python -v
2) 安装 GCC 与 wget, 用于编译源码包与资源下载
- # yum install gcc gcc-c++
- # yum install wget
3) 安装 xz 工具, 用于解压 tar.xz 格式文件
- # wget http://down1.chinaunix.net/distfiles/xz-5.0.3.tar.bz2
- # cd xz-5.0.3
- # ./configure
- # make
- # make install
3.2, 安装 Python2.7
1) 下载解压 Python 安装包
- # wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
- # xz -d Python-2.7.11.tar.xz
- # tar -xf Python-2.7.11.tar
2) 编译安装 python
- # cd Python-2.7.11
- # ./configure
- # make
- # make install
3) 将系统指向的 python 从 2.6 修改到 2.7 版本
- # /usr/local/bin/python2.7 -V
- # mv /usr/bin/python /usr/bin/python.bak
- # ln -s /usr/local/bin/python2.7 /usr/bin/python
4) 将 yum 对 python 的引用重新指向 python2.6 (即: yum 使用 2.6, 系统用 2.7)
# vi /usr/bin/yum
修改:
!/usr/bin/python
改为:
!/usr/bin/python2.6
5) 检查 python 版本, 检查 yum 是否可用
# python -V
来源: https://www.cnblogs.com/chenmingjun/p/10545638.html