工作需要搭建GlusterFS集群,简单写了一个自动化安装配置脚本,只需指出所有节点的ip地址列表以及需要配置的卷信息即可通过一台机器编译、安装、部署整个集群,远程操作通过sshpass完成。
#!/bin/bash # Author [email protected] ###############Initialization################ PKG_PATH=/opt/files/glusterfs-3.4.0.tar.gz ROOT_PASS=test # Gluster peers NODES=(192.168.64.87 192.168.64.88) # Gluster volumes vol_1=(nova_vol /opt/nova_vol 192.168.64.87,192.168.64.88) VOLUMES=(vol_1) ############################################# # Get MY_IP if [ "${MY_IP}" == "" ];then MY_IP=$(python -c "import socket;socket=socket.socket();socket.connect(('8.8.8.8',53));print socket.getsockname()[0];") fi # Step 1. Install sshpass apt-get install sshpass -y # Step 2. Compile and install glusterfs on each node. cd /tmp && tar xf ${PKG_PATH} cat > /tmp/tmp_install_gfs.sh << _wrtend_ #!/bin/bash apt-get -y --force-yes purge glusterfs-server glusterfs-common ps ax|grep gluster|grep -v grep|awk '{print $1}'|xargs -L 1 kill apt-get -y --force-yes install libssl-dev flex bison rm -rf /var/lib/glusterd || true if [ ! -x /usr/local/sbin/glusterd ];then cd /tmp/glusterfs-3.4.0 && ./configure && make && make install cd /tmp && rm -rf /tmp/glusterfs-3.4.0 ldconfig && update-rc.d -f glusterd defaults fi service glusterd restart sleep 5 rm -rf /tmp/glusterfs-3.4.0 rm /tmp/tmp_install_gfs.sh _wrtend_ for node in ${NODES[@]}; do if [ "${MY_IP}" != "$node" ];then echo $node install start sshpass -p ${ROOT_PASS} scp -o StrictHostKeyChecking=no -r /tmp/glusterfs-3.4.0 ${node}:/tmp/glusterfs-3.4.0 sshpass -p ${ROOT_PASS} scp -o StrictHostKeyChecking=no /tmp/tmp_install_gfs.sh ${node}:/tmp/ sshpass -p ${ROOT_PASS} ssh -o StrictHostKeyChecking=no root@${node} /bin/bash /tmp/tmp_install_gfs.sh echo $node install end fi done /bin/bash tmp_install_gfs.sh # Step 3. Attach peer for node in ${NODES[@]}; do if [ "${MY_IP}" != "$node" ];then /usr/local/sbin/gluster peer probe ${node} fi done sleep 15 # Step 4. Verify attach status and create volumes conn_peer_num=`/usr/local/sbin/gluster peer status | grep Connected | wc -l` conn_peer_num=`expr $conn_peer_num + 1` if [ ${conn_peer_num} -eq ${#NODES[@]} ];then echo "All peers have been attached." for vol in ${VOLUMES[@]};do eval vol_info=(\${$vol[@]}) eval vol_nodes=(${vol_info[2]//,/ }) vol_path="" for node in ${vol_nodes[@]};do vol_path=$vol_path$node:${vol_info[1]}" " done # create volume /usr/local/sbin/gluster volume create ${vol_info[0]} replica 2 ${vol_path} # start volume /usr/local/sbin/gluster volume start ${vol_info[0]} done else echo "Attach peers error" exit 0 fi
###############Initialization################ PKG_PATH=/opt/files/glusterfs-3.4.0.tar.gz ROOT_PASS=test # Gluster peers NODES=(192.168.64.87 192.168.64.88) # Gluster volumes vol_1=(nova_vol /opt/nova_vol 192.168.64.87,192.168.64.88) VOLUMES=(vol_1) #############################################
PKG_PATH是安装包路径
ROOT_PASS为各节点root密码(需要设置成一样的,后续需要ssh连接远程操作)
NODES指定了集群的节点IP地址列表(通过空格分隔)
vol_1指定一个需要创建的卷信息,包括卷名称(nova_vol),数据路径(/opt/nova_vol),bricks的IP地址列表(逗号分隔),可以填写多个卷信息,最后在VOLUMES中指定
读取集群信息之后,脚本会获取本机地址,解压缩源文件,生成本地安装脚本并分别拷贝到各节点的/tmp目录下并执行,在这里需要根据实际情况修改解压缩的目录名以及在本地安装脚本中指定glusterFS软件的文件名。
编译安装结束后,会attach peers,创建卷并启动,创建卷过程中的各项参数也请自行修改。
转载请注明来自http://blog.csdn.net/dysj4099
Good luck :)