rsync +1
介绍下偶们现在用的:
gogs 搭的 git 服务器,按上 push 钩子 -> jenkins 持续集成,自动化构建并做基础测试 -> 通过 rsync 部署到服务器上
#install
IS_REDO="NONE"
NODE_NUM=0
SERVER_IP=""
WORK_DIR=$(dirname "$0")
cd ${WORK_DIR}
if [ "X"${WORK_DIR} = "X" ] ; then
WORK_DIR=""
fi
while :
do
IS_REDO="NONE"
NODE_NUM=0
SERVER_IP=""
echo -n "请输入需要安装DataOS的服务器IP地址(单机格式:IP,集群格式:IP1,IP2,IP3) => "
read INSTALL_NODES_IPS
if [ "X"${INSTALL_NODES_IPS} = "X" ] ; then
echo -e "输入IP[33[31m"${i}"e[0m]信息无效,重新输入"
continue
fi
for i in `echo ${INSTALL_NODES_IPS} | sed 's/,/ /g'`
do
if ! echo ${i} | grep '[1-9][0-9]{0,2}[0-9]{1,3}[0-9]{1,3}[1-9][0-9]{0,2}' ; then
echo -e "输入IP[33[31m"${i}"e[0m]信息无效"
IS_REDO="REDO"
break
fi
SERVER_IP=$(echo $i | awk -F'' '{if((!($1 ~ /^0/) && !($4 ~ /^0/)) && ((length($2)>1 && !($2 ~ /^0/)) || length($2)==1) && ((length($3)>1 && !($3 ~ /^0/)) || length($3)==1)) printf "%d%d%d%d",$1,$2,$3,$4}' | awk -F'' '{if(($1>0 && $1=0 && $2=0 && $30 && $4<255)) printf "%d%d%d%d",$1,$2,$3,$4}')
if [ "X"${SERVER_IP} = "X" ] ; then
echo -e "输入IP[33[31m"${i}"e[0m]信息无效"
IS_REDO="REDO"
break
fi
NODE_NUM=$((${NODE_NUM}+1))
done
if [ "X"${IS_REDO} = "XNONE" ] ; then
if [ ${NODE_NUM} -ne 3 -a ${NODE_NUM} -ne 1 ] ; then
echo -e "输入IP信息校验通过,但不满足[33[31m3个节点e[0m]的DataOS集群初始化要求"
continue
fi
echo -e "输入IP信息校验通过,将初始化[33[32m"${NODE_NUM}"个节点e[0m]的DataOS集群"
rm -rf ${WORK_DIR}//nodes/
for i in `echo ${INSTALL_NODES_IPS} | sed 's/,/ /g'`
do
mkdir -p ${WORK_DIR}"//nodes/"${i}
done
break
else
continue
fi
done
#################检查DataOS集群各节点的软件环境,安装zookeeper服务
IDX=0
SERVER_IP=""
for SERVER_IP in `ls ${WORK_DIR}"//nodes/"`
do
let IDX=${IDX}+1 && touch ${WORK_DIR}//nodes/${SERVER_IP}/id=${IDX}
done
echo "请输入需要安装zookeeper服务的路径(例如:/data01) =>"
read zkPath
ZOOKEEPER_DATA_DIR=$zkPath/zookeeper/data
ZOOKEEPER_LOG_DIR=$zkPath/zookeeper/logs
tar -zxf ${WORK_DIR}//software/zookeepertargz -C /tmp
if [[ -n $(cat /tmp/zookeeper/conf/zoocfg |grep dataDir) ]] ;then
sed -i "s/^dataDir=/dataDir=${ZOOKEEPER_DATA_DIR/////}/g" /tmp/zookeeper/conf/zoocfg
else
echo "dataDir=${ZOOKEEPER_DATA_DIR}" >> /tmp/zookeeper/conf/zoocfg
fi
if [[ -n $(cat /tmp/zookeeper/conf/zoocfg |grep dataLogDir) ]] ;then
sed -i "s/^dataLogDir=/dataLogDir=${ZOOKEEPER_LOG_DIR/////}/g" /tmp/zookeeper/conf/zoocfg
else
echo "dataLogDir=${ZOOKEEPER_LOG_DIR}" >> /tmp/zookeeper/conf/zoocfg
fi
IDX=0
SERVER_IP=""
NodeIP1=""
NodeIP2=""
NodeIP3=""
for SERVER_IP in `ls ${WORK_DIR}//nodes//id= | sed 's/// /g' | sed 's/=/ /g' | awk '{printf "%s %s ",$(NF-2),$NF}' | sort -nk 2 | awk '{print $1}'`
do
let IDX=${IDX}+1
source ${WORK_DIR}"//scripts/initCluster" ${SERVER_IP} || exit 255
if [ ${IDX} -eq 1 ] ; then
NodeIP1=$SERVER_IP
elif [ ${IDX} -eq 2 ]; then
NodeIP2=$SERVER_IP
else
NodeIP3=$SERVER_IP
fi
done
echo "server1serverid=${NodeIP1}:2888:3888" >> /tmp/zookeeper/conf/zoocfg
echo "server2serverid=${NodeIP2}:2888:3888" >> /tmp/zookeeper/conf/zoocfg
echo "server3serverid=${NodeIP3}:2888:3888" >> /tmp/zookeeper/conf/zoocfg
IDX=0
SERVER_IP=""
for SERVER_IP in `ls ${WORK_DIR}//nodes//id= | sed 's/// /g' | sed 's/=/ /g' | awk '{printf "%s %s ",$(NF-2),$NF}' | sort -nk 2 | awk '{print $1}'`
do
let IDX=${IDX}+1
if [ ${IDX} -eq 1 ] ; then
echo 1 > /tmp/zookeeper/data/myid
sshpass -p "${SYSUSER_PASSWORD}" scp -o StrictHostKeyChecking=no -P ${SSH_PORT} /tmp/zookeeper ${SYSUSER_NAME}@${NodeIP1}:$zkPath
elif [ ${IDX} -eq 2 ]; then
echo 2 > /tmp/zookeeper/data/myid
sshpass -p "${SYSUSER_PASSWORD}" scp -o StrictHostKeyChecking=no -P ${SSH_PORT} /tmp/zookeeper ${SYSUSER_NAME}@${NodeIP2}:$zkPath
else
echo 3 > /tmp/zookeeper/data/myid
sshpass -p "${SYSUSER_PASSWORD}" scp -r -o StrictHostKeyChecking=no -P ${SSH_PORT} /tmp/zookeeper ${SYSUSER_NAME}@${NodeIP3}:$zkPath
fi
done
以上便是zookeeper集群的一键部署shell脚本,其中引用的initCluster脚本,将在后续更新。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)