此文只写zookeeper的搭建。
----------------------
1、三台CentOS虚机
2、配好hostname分别为focuson1,focuson2,focuson3
//在这个里面修改会永久生效
vi /etc/sysconfig/network
//下面通过hostname命令修改之后重启会失效
hostname focuson1
...
3、并分别配好hosts文件
vi /etc/hosts
192.168.67.99 focuson3
192.168.67.61 focuson2
192.168.67.97 focuson1
4、安装好jdk1.7,并配置好环境变量
vi /etc/profile
#set java environment
JAVA_HOME=/usr/local/src/java/jdk1.7.0_51
exportHADOOP_HOME=/usr/local/src/hadoop/hadoop-2.6.0
exportZOOKEEPER_HOME=/usr/local/src/zookeeper/zookeeper-3.4.12
exportSPARK_HOME=/usr/local/src/spark/spark-1.5.1-bin-hadoop2.6
JAVA_BIN=/usr/local/src/java/jdk1.7.0_51/bin
PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$ZOOKEEPER_HOME/bin:$SPARK_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
5、关闭防火墙(先全部关闭,后期整理出需要关闭的端口,按端口关闭)
vi /etc/selinux/config
SELINUX=disabled
6、配置好互信
6.1、三台服务器分别执行下面,生成密钥文件:
ssh-keygen -t rsa
6.2、然后在家目录的.ssh下会生成id_rsa.pub,把三台服务器的这个文件写入到authorized_keys,然后考到每一个机器家目录的.ssh目录下
执行命令参考如下(在focuson1上执行):
scp focuson3:~/.ssh/id_rsa.pub id_rsa.pub_focuson3
scp focuson2:~/.ssh/id_rsa.pub id_rsa.pub_focuson2
cp ~/.ssh/id_rsa.pub id_rsa.pub_focuson1
cat id_rsa.pub* >> authorized_keys
cp authorized_keys ~/.ssh/
scp authorized_keys focuson3:~/.ssh/
scp authorized_keys focuson2:~/.ssh/
6.3、验证
例如:在focuson1上,ssh另外两台机器,如果能直接登录,证明成功。
Ssh root@focuson2
Ssh root@focuson3
*注意家目录、authorized_keys的权限问题,否则不能成功。配置完之后也不能更改权限。
1、压缩包上传到focuson1家目录
cd /usr/local/src/
mkdir zookeeper
mv ~/zookeeper-3.4.12.tar.gz .
tar -xvf zookeeper-3.4.12.tar.gz
rm -f zookeeper-3.4.12.tar.gz
2、修改配置文件
cd/usr/local/src/zookeeper/zookeeper-3.4.12
cp conf/zoo_sample.cfg conf/zoo.cfg
vi conf/zoo.cfg
dataDir=/usr/local/src/zookeeper/tmp
server.1=focuson1:2888:3888
server.2=focuson2:2888:3888
server.3=focuson3:2888:3888
保存,退出
3、建立文件夹/usr/local/src/zookeeper/tmp(即zoo.cfg的dataDir)
mkdir -p /usr/local/src/zookeeper/tmp
4、拷贝项目到另外两台机器
scp -r /usr/local/src/zookeeperfocuson2:/usr/local/src/
scp -r /usr/local/src/zookeeperfocuson3:/usr/local/src/
5、分别在三台的/usr/local/src/zookeeper/tmp(即zoo.cfg的dataDir)下,建一个名为myid,内容分别为1/2/3的文件(跟server.1/server.2/server.3分别对应)
echo 1 >/usr/local/src/zookeeper/tmp/myid
echo 2 >/usr/local/src/zookeeper/tmp/myid
echo 3 >/usr/local/src/zookeeper/tmp/myid
6、启动,在三台机器分别启动,分别执行下面命令即可
cd/usr/local/src/zookeeper/zookeeper-3.4.12/
bin/zkServer.sh start
*把ZOOKEEPER_HOME加入环境变量后,不在该路径也可以启动,但是会在启动目录生成一个zookeeper.out的日志文件,建议在安装路径启动,方便查看日志。
然后就启动成功,分别查看状态 bin/zkServer.sh sttus,发现一个是leader,另外两个是follower。
jps查看进程显示:QuorumPeerMain
完成!