lc_hb.in
来自「lustre 1.6.5 source code」· IN 代码 · 共 645 行 · 第 1/2 页
IN
645 行
echo >&2 "${TARGET_SRVNAMES[i]}" return 1 fi done return 0}# create_template## Create the templates for ha.cf and authkeys filescreate_template() { /bin/mkdir -p ${TMP_DIR} # Create the template for ha.cf if [ "${HBVER_OPT}" = "${HBVER_HBV1}" ]; then cat >${HACF_TEMP} <<EOFdebugfile /var/log/ha-debuglogfile /var/log/ha-loglogfacility local0keepalive 2deadtime 30initdead 120auto_failback offEOF elif [ "${HBVER_OPT}" = "${HBVER_HBV2}" ]; then cat >${HACF_TEMP} <<EOFuse_logd yeskeepalive 1deadtime 10initdead 60crm yesEOF fi # Create the template for authkeys if [ ! -s ${AUTHKEYS_TEMP} ]; then cat >${AUTHKEYS_TEMP} <<EOFauth 11 sha1 HelloLustre!EOF fi return 0}# create_hacf## Create the ha.cf file and scp it to each node's /etc/ha.d/create_hacf() { HACF_PRIMNODE=${TMP_DIR}$"/ha.cf."${PRIM_NODENAME} HACF_LUSTRE=${TMP_DIR}$"/ha.cf"${FILE_SUFFIX} declare -i idx if [ -e ${HACF_PRIMNODE} ]; then # The ha.cf file for the primary node has already existed. verbose_output "${HACF_PRIMNODE} already exists." return 0 fi /bin/cp -f ${HACF_TEMP} ${HACF_LUSTRE} for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do echo "node ${NODE_NAMES[idx]}" >> ${HACF_LUSTRE} done # scp ha.cf file to all the nodes for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do touch ${TMP_DIR}$"/ha.cf."${NODE_NAMES[idx]} scp ${HACF_LUSTRE} ${NODE_NAMES[idx]}:${HA_DIR}/ if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to scp ha.cf file"\ "to node ${NODE_NAMES[idx]}!" return 1 fi done return 0}# create_haresources## Create the haresources file and scp it to the each node's /etc/ha.d/create_haresources() { HARES_PRIMNODE=${TMP_DIR}$"/haresources."${PRIM_NODENAME} HARES_LUSTRE=${TMP_DIR}$"/haresources"${FILE_SUFFIX} declare -i idx local res_line if [ -s ${HARES_PRIMNODE} ]; then # The haresources file for the primary node has already existed if [ -n "`/bin/grep ${TARGET_DEVNAMES[0]} ${HARES_PRIMNODE}`" ]; then verbose_output "${HARES_PRIMNODE} already exists." return 0 fi fi # Add the resource group line into the haresources file res_line=${PRIM_NODENAME} for ((idx = 0; idx < ${#TARGET_DEVNAMES[@]}; idx++)); do res_line=${res_line}" "${LUSTRE_SRV}::${TARGET_DEVNAMES[idx]}::${TARGET_MNTPNTS[idx]}::${FS_TYPE} if [ "${HBVER_OPT}" = "${HBVER_HBV1}" ]; then res_line=${res_line}" "${TARGET_SRVNAMES[idx]}"-mon" fi done echo "${res_line}" >> ${HARES_LUSTRE} # Generate the cib.xml file if [ "${HBVER_OPT}" = "${HBVER_HBV2}" ]; then # Add group haclient and user hacluster [ -z "`grep haclient /etc/group`" ] && groupadd haclient [ -z "`grep hacluster /etc/passwd`" ] && useradd -g haclient hacluster CIB_LUSTRE=${TMP_DIR}$"/cib.xml"${FILE_SUFFIX} python ${CIB_GEN_SCRIPT} --stdout \ ${HARES_LUSTRE} > ${CIB_LUSTRE} if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to generate cib.xml file"\ "for node ${PRIM_NODENAME}!" return 1 fi fi # scp the haresources file or cib.xml file for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do /bin/cp -f ${HARES_LUSTRE} ${TMP_DIR}$"/haresources."${NODE_NAMES[idx]} scp ${HARES_LUSTRE} ${NODE_NAMES[idx]}:${HA_DIR}/ if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to scp haresources file"\ "to node ${NODE_NAMES[idx]}!" return 1 fi if [ "${HBVER_OPT}" = "${HBVER_HBV2}" ]; then scp ${CIB_LUSTRE} ${NODE_NAMES[idx]}:${CIB_DIR}/ if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to scp cib.xml"\ "file to node ${NODE_NAMES[idx]}!" return 1 fi fi done return 0}# create_authkeys## Create the authkeys file and scp it to the each node's /etc/ha.d/create_authkeys() { AUTHKEYS_PRIMNODE=${TMP_DIR}$"/authkeys."${PRIM_NODENAME} declare -i idx if [ -e ${AUTHKEYS_PRIMNODE} ]; then verbose_output "${AUTHKEYS_PRIMNODE} already exists." return 0 fi # scp the authkeys file to all the nodes chmod 600 ${AUTHKEYS_TEMP} for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do touch ${TMP_DIR}$"/authkeys."${NODE_NAMES[idx]} scp -p ${AUTHKEYS_TEMP} ${NODE_NAMES[idx]}:${HA_DIR}/ if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to scp authkeys file"\ "to node ${NODE_NAMES[idx]}!" return 1 fi done return 0}# create_moncf## Create the mon.cf file and scp it to the each node's /etc/mon/create_moncf() { MONCF_PRIMNODE=${TMP_DIR}$"/mon.cf."${PRIM_NODENAME} MONCF_LUSTRE=${TMP_DIR}$"/mon.cf"${FILE_SUFFIX} local srv_name params= declare -i idx declare -a OLD_TARGET_SRVNAMES # targets in other nodes # in this failover group # Initialize the OLD_TARGET_SRVNAMES array unset OLD_TARGET_SRVNAMES if [ -s ${MONCF_PRIMNODE} ]; then if [ -n "`/bin/grep ${TARGET_SRVNAMES[0]} ${MONCF_PRIMNODE}`" ] then verbose_output "${MONCF_PRIMNODE} already exists." return 0 else # Get the Lustre target service names # from the previous mon.cf file idx=0 for srv_name in `grep hostgroup ${MONCF_PRIMNODE}\ |awk '$2 ~ /-mon/ {print $2}'|xargs` do OLD_TARGET_SRVNAMES[idx]=`echo ${srv_name}\ |sed 's/-mon//g'` idx=$(( idx + 1 )) done fi fi # Construct the parameters to mon.cf generation script for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do params=${params}" -n "${NODE_NAMES[idx]} done for ((idx = 0; idx < ${#OLD_TARGET_SRVNAMES[@]}; idx++)); do params=${params}" -o "${OLD_TARGET_SRVNAMES[idx]} done for ((idx = 0; idx < ${#TARGET_SRVNAMES[@]}; idx++)); do params=${params}" -o "${TARGET_SRVNAMES[idx]} done ${SCRIPT_GEN_MONCF} ${params} if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to generate mon.cf file"\ "by using ${SCRIPT_GEN_MONCF}!" return 1 fi /bin/mv *-mon.cfg ${MONCF_LUSTRE} # scp the mon.cf file to all the nodes for ((idx = 0; idx < ${#NODE_NAMES[@]}; idx++)); do /bin/cp -f ${MONCF_LUSTRE} ${TMP_DIR}$"/mon.cf."${NODE_NAMES[idx]} scp ${MONCF_LUSTRE} ${NODE_NAMES[idx]}:${MON_DIR}/ if [ $? -ne 0 ]; then echo >&2 "`basename $0`: Failed to scp mon.cf file"\ "to node ${NODE_NAMES[idx]}!" return 1 fi done return 0}# generate_config## Generate the configuration files for Heartbeat and scp them to all the nodesgenerate_config() { if [ "${HBVER_OPT}" = "${HBVER_HBV1}" ]; then # Get server names of Lustre targets if ! get_srvnames; then return 1 fi fi if ! create_template; then return 1 fi verbose_output "Creating and remote copying ha.cf${FILE_SUFFIX} file to"\ "${PRIM_NODENAME} failover group hosts..." if ! create_hacf; then return 1 fi verbose_output "OK" verbose_output "Creating and remote copying haresources${FILE_SUFFIX} file"\ "to ${PRIM_NODENAME} failover group hosts..." if ! create_haresources; then return 1 fi verbose_output "OK" verbose_output "Creating and remote copying authkeys${FILE_SUFFIX} file to" \ "${PRIM_NODENAME} failover group hosts..." if ! create_authkeys; then return 1 fi verbose_output "OK" if [ "${HBVER_OPT}" = "${HBVER_HBV1}" ]; then verbose_output "Creating and remote copying mon.cf${FILE_SUFFIX} file to" \ "${PRIM_NODENAME} failover group hosts..." if ! create_moncf; then return 1 fi verbose_output "OK" fi return 0}# Main flow# Get all the node namesif ! get_nodenames; then exit 1fi# Check heartbeat servicesverbose_output "Checking heartbeat service in the ${PRIM_NODENAME}"\ "failover group hosts..."check_heartbeatrc=$?if [ "$rc" -eq "2" ]; then verbose_output "OK" exit 0elif [ "$rc" -eq "1" ]; then exit 1fiverbose_output "OK"# Generate configuration filesif ! generate_config; then exit 1fiexit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?