工作需要搭建GlusterFS叢集,簡單寫了一個自動化安裝配置指令碼,只需指出所有節點的ip地址清單以及需要配置的卷資訊即可通過一台機器編譯、安裝、部署整個叢集,遠程操作通過sshpass完成。
#!/bin/bash# Author dysj4099@gmail.com###############Initialization################PKG_PATH=/opt/files/glusterfs-3.4.0.tar.gzROOT_PASS=test# Gluster peersNODES=(192.168.64.87 192.168.64.88)# Gluster volumesvol_1=(nova_vol /opt/nova_vol 192.168.64.87,192.168.64.88)VOLUMES=(vol_1)############################################## Get MY_IPif [ "${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 sshpassapt-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/bashapt-get -y --force-yes purge glusterfs-server glusterfs-commonps ax|grep gluster|grep -v grep|awk '{print $1}'|xargs -L 1 killapt-get -y --force-yes install libssl-dev flex bisonrm -rf /var/lib/glusterd || trueif [ ! -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 defaultsfiservice glusterd restartsleep 5rm -rf /tmp/glusterfs-3.4.0rm /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 fidone/bin/bash tmp_install_gfs.sh# Step 3. Attach peerfor node in ${NODES[@]}; do if [ "${MY_IP}" != "$node" ];then /usr/local/sbin/gluster peer probe ${node} fi donesleep 15# Step 4. Verify attach status and create volumesconn_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 0fi
指令碼很簡單,首先需要自己填寫叢集資訊:
###############Initialization################PKG_PATH=/opt/files/glusterfs-3.4.0.tar.gzROOT_PASS=test# Gluster peersNODES=(192.168.64.87 192.168.64.88)# Gluster volumesvol_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,建立卷並啟動,建立卷過程中的各項參數也請自行修改。