您好,登錄后才能下訂單哦!
作為Hadoop初學者,自然要從安裝入手。而hadoop的優勢就是分布式,所以,也一定要安裝分布式的系統。
整體安裝步驟,包括Zookeeper+HDFS+Hbase,為了文章簡潔,我會分三篇blog記錄我的安裝步驟。
本文記錄的是集群環境準備,zookeeper的安裝步驟。
~~~~~~~~~~~環境準備部分~~~~~~~~~~~~~~~~~
IP部署規劃(準備了三個虛擬機,操作系統是Centos6.7)
Zookeeper主機分配
192.168.67.101 c6701 192.168.67.102 c6702 192.168.67.103 c6703
HDFS主機分配
192.168.67.101 c6701 --Namenode+datanode 192.168.67.102 c6702 --datanode 192.168.67.103 c6703 --datanode
Hbase主機分配
192.168.67.101 c6701 --Master + region 192.168.67.102 c6702 --region 192.168.67.103 c6703 --region
1. 為了分別管理各個服務,我為每個服務,都單獨創建了用戶.
創建的用戶有:
zk hdfs hbase
2. 為每一個用戶創建ssh免密,并分發到全部節點,這樣,我就只在C6701上執行命令,通過遠程的方式安裝C6702和C6703
ssh-keygen -t rsa -f ~/.ssh/id_rsa
拷貝密鑰到全部節點即可(只有c6701訪問02和03不需要密碼,反向訪問是需要密碼的)
ssh-copy-id c6701 ssh-copy-id c6702 ssh-copy-id c6703
3. 強調一下,/etc/hosts 需要設置
[root@c6701 ~]# more /etc/hosts 192.168.67.101 c6701.org c6701 192.168.67.102 c6702.org c6702 192.168.67.103 c6703.org c6703
4. 下面在C6701執行,中間會調用ssh遠程執行一些命令,驗證ssh免密是否生效
ssh c6702 "cat /proc/cpuinfo" ssh c6702 "hostname"
5. 下載安裝軟件(內網地址)
cd /tmp/software wget http://192.21.104.48/deploy/jdk-8u144-linux-x64.tar.gz wget http://192.21.104.48/deploy/zookeeper-3.4.6.tar.gz wget http://192.21.104.48/deploy/hbase-1.1.3.tar.gz wget http://192.21.104.48/deploy/hadoop-2.6.0-EDH-0u2.tar.gz wget http://192.21.104.48/deploy/hadoop-2.7.1.tar.gz
6. 安裝JDK,全部節點都要安裝
#tar -xzvf jdk-8u144-linux-x64.tar.gz -C /usr/local
7. 添加下面信息到.bash_profile
export JAVA_HOME=/usr/local/jdk1.8.0_144 export JRE_HOME=/usr/local/jdk1.8.0_144/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$PATH source /etc/profile
8. 檢查版本信息
# java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
~~~~~~~~~~~zookeeper的安裝部分~~~~~~~~~~~~~~~~~
1. 在C6701安裝Zookeeper
useradd zk echo "zk:zk" | chpasswd su - zk mkdir zk tar -zxvf /tmp/software/zookeeper-3.4.6.tar.gz -C /home/zk/zk
~~~~~~~~~~~~~zoo.cfg的配置~~~~~~~~~~~~~~~ $ pwd /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg $ cat /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg |grep -v '^#' tickTime=2000 initLimit=10 syncLimit=5 dataDir=/data/zookeeper/data dataLogDir=/data/zookeeper/log clientPort=2181 autopurge.snapRetainCount=3 autopurge.purgeInterval=6 server.1=c6701:2888:3888 server.2=c6702:2888:3888 server.3=c6703:2888:3888 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2. 根據zoo.cfg創建data和log兩個文件夾
#mkdir -p /data/zookeeper/data #mkdir -p /data/zookeeper/log #chown -R zk:zk /data/zookeeper #chown -R zk:zk /data/zookeeper/data #chown -R zk:zk /data/zookeeper/log
3.在zookeeper的目錄中,創建上述兩個文件夾。進入zkdata文件夾,創建文件myid,填入1。這里寫入的1,是在zoo.cfg文本中的server.1中的1。當我們把所有文件都配置完畢,我們把hadoop1中yarn目錄復制到其它機器中,我們在修改每臺機器中對應的myid文本,hadoop2中的myid寫入2。其余節點,安照上面配置,依此寫入相應的數字。Zkdatalog文件夾,是為了指定zookeeper產生日志指定相應的路徑。
# su - zk -c "echo 1 > /data/zookeeper/data/myid"
4. 添加環境變量,在/etc/profile目錄中,將ZOOKEEPER_HOME/bin在原有的PATH后面加入":$ZOOKEEPER_HOME/bin"
關于環境變量修改/etc目錄下的profile文件,也可以在根目錄下的.bashrc目錄下添加環境變量。這兩者有什么區別:.bashrc是對當前目錄用戶的環境變量,profile文件是對所有用戶都開放的目錄。當系統加載文件中,先從profile找相應的路勁,如果沒有會在.bashrc文件中找對應的環境變量路徑。這兩者大家稍至了解。
然后 source /etc/profile
5. 安裝c6702的zookeeper
#ssh c6702 "useradd zk" #ssh c6702 "echo "zk:zk" | chpasswd"
為zk用戶ssh免密
#ssh-copy-id zk@c6702
拷貝軟件
#scp -r /tmp/software/hadoop-* root@c6702:/tmp/software #ssh c6702 "chmod 777 /tmp/software/*"
創建目錄,解壓軟件
#ssh zk@c6702 "mkdir zk" #ssh zk@c6702 "tar -zxvf /tmp/software/zookeeper-3.4.6.tar.gz -C /home/zk/zk" #ssh zk@c6702 "ls -al zk" #ssh zk@c6702 "ls -al zk/zookeeper*" #ssh zk@c6702 "rm /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg" #scp -r /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg zk@c6702:/home/zk/zk/zookeeper-3.4.6/conf/. #ssh zk@c6702 "cat /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg |grep -v '^#'" 根據zoo.cfg創建目錄 #ssh c6702 "mkdir -p /data/zookeeper/data" #ssh c6702 "chown -R zk:zk /data/zookeeper" #ssh c6702 "chown -R zk:zk /data/zookeeper/data" #ssh c6702 "mkdir -p /data/zookeeper/log" #ssh c6702 "chown -R zk:zk /data/zookeeper/log" 創建文件myid,填入2 ssh zk@c6702 "echo 2 > /data/zookeeper/data/myid"
6. 安裝c6703的zookeeper
#ssh c6703 "useradd zk" #ssh c6703 "echo "zk:zk" | chpasswd"
為zk用戶ssh免密
ssh-copy-id zk@c6703
拷貝軟件
#scp -r /tmp/software/hadoop-* root@c6703:/tmp/software #ssh c6703 "chmod 777 /tmp/software/*"
創建目錄,解壓軟件
#ssh zk@c6703 "mkdir zk" #ssh zk@c6703 "tar -zxvf /tmp/software/zookeeper-3.4.6.tar.gz -C /home/zk/zk" #ssh zk@c6703 "ls -al zk" #ssh zk@c6703 "ls -al zk/zookeeper*" #ssh zk@c6703 "rm /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg" #scp -r /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg zk@c6703:/home/zk/zk/zookeeper-3.4.6/conf/. #ssh zk@c6703 "cat /home/zk/zk/zookeeper-3.4.6/conf/zoo.cfg |grep -v '^#'"
根據zoo.cfg創建目錄
#ssh c6703 "mkdir -p /data/zookeeper/data" #ssh c6703 "chown -R zk:zk /data/zookeeper" #ssh c6703 "chown -R zk:zk /data/zookeeper/data" #ssh c6703 "mkdir -p /data/zookeeper/log" #ssh c6703 "chown -R zk:zk /data/zookeeper/log" 創建文件myid,填入3 ssh zk@c6703 "echo 3 > /data/zookeeper/data/myid"
7. 啟動ZK
/home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh start /home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh status
遠程啟動命令
ssh zk@c6702 "/home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh\ start" ssh zk@c6703 "/home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh\ start" ssh zk@c6702 "/home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh\ status" ssh zk@c6703 "/home/zk/zk/zookeeper-3.4.6/bin/zkServer.sh\ status"
8. 沒有全部啟動三個ZK前的狀態
[vagrant@c7003 bin]$ ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/vagrant/zookeeper-3.4.10/bin/../conf/zoo.cfg Error contacting service. It is probably not running.
9. 需要將三個ZK全啟動之后,才能選舉出leader
$ ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/vagrant/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: follower [vagrant@c7002 bin]$ ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/vagrant/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: leader
=======2018.1.13更新==========
客戶端連接方式
客戶端是隨機順序的方式連接server的,無法指定,或者優先讀哪個一個zookeeper server。
./zkCli.sh -server c6701:2181,c6702:2181,c6703:2181
輸出如下:
第一次連接,連接到c6701上
[zookeeper@c6702 bin]$ /usr/local/hadoop/zookeeper-3.4.6/bin/zkCli.sh -server c6701:2181,c6702:2181,c6703:2181 Connecting to c6701:2181,c6702:2181,c6703:2181 ...... 2018-01-11 21:07:30,797 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=c6701:2181,c6702:2181,c6703:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@4b4bc1e Welcome to ZooKeeper! 2018-01-11 21:07:30,830 [myid:] - INFO [main-SendThread(c6701.python279.org:2181):ClientCnxn$SendThread@975] - Opening socket connection to server c6701.python279.org/192.168.67.101:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2018-01-11 21:07:30,873 [myid:] - INFO [main-SendThread(c6701.python279.org:2181):ClientCnxn$SendThread@852] - Socket connection established to c6701.python279.org/192.168.67.101:2181, initiating session 2018-01-11 21:07:30,916 [myid:] - INFO [main-SendThread(c6701.python279.org:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server c6701.python279.org/192.168.67.101:2181, sessionid = 0x160e70285f70001, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null
第二次連接,連接到c6702上
Connecting to c6701:2181,c6702:2181,c6703:2181 ...... 2018-01-11 21:10:18,442 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=c6701:2181,c6702:2181,c6703:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@4b4bc1e Welcome to ZooKeeper! 2018-01-11 21:10:18,489 [myid:] - INFO [main-SendThread(c6702.python279.org:2181):ClientCnxn$SendThread@975] - Opening socket connection to server c6702.python279.org/192.168.67.102:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2018-01-11 21:10:18,508 [myid:] - INFO [main-SendThread(c6702.python279.org:2181):ClientCnxn$SendThread@852] - Socket connection established to c6702.python279.org/192.168.67.102:2181, initiating session 2018-01-11 21:10:18,561 [myid:] - INFO [main-SendThread(c6702.python279.org:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server c6702.python279.org/192.168.67.102:2181, sessionid = 0x260e70284650002, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null
至此,基礎環境部署完。并且zookeeper也安裝完成。下面我們會在下一篇文章中,繼續安裝HDFS。
系列文章,請參考
Hadoop集群(一) Zookeeper搭建
Hadoop集群(二) HDFS搭建
Hadoop集群(三) Hbase搭建
Hadoop集群(四) Hadoop升級
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。