一、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