原 GreenPlum配置开机启动
简介
在开机启动时持续并发 ping 各个主机,直到所有主机都可用,然后再执行 gpstart
。:
简易版(慎用)-- 适合单机环境
1 2 3 4 5 6 7 8 | cat >> /etc/rc.local <<"EOF" su - gpadmin -c "gpstart -a" su - gpadmin -c "gpcc start" EOF chmod +x /etc/rc.d/rc.local |
高级版--适合多主机环境
请修改hosts数组的值!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | cat > /home/gpadmin/start_gpdb.sh <<"EOF" #!/bin/bash # 定义主机数组 hosts=("mdw" "smdw" "sdw1" "sdw2" "sdw3") # Wait for the hosts to become available echo "$(date +'%Y%m%d %H:%M:%S') - Waiting for all gpdb hosts to become available...." # 定义一个数组来存储后台进程的 PID pids=() # 启动每个 ping 命令作为后台进程 for host in "${hosts[@]}"; do ( while ! ping -c 5 "$host" &>/dev/null; do sleep 1 done ) & # 保存后台进程的 PID pids+=($!) done # 等待所有主机都可用 while true; do all_up=true for host in "${hosts[@]}"; do if ! ping -c 5 "$host" &>/dev/null; then echo "$(date +'%Y%m%d %H:%M:%S') - Host $host is not reachable." all_up=false break fi done # 如果所有主机都可用,跳出循环 if $all_up; then break fi sleep 1 done echo "$(date +'%Y%m%d %H:%M:%S') - All gpdb hosts are now available." # Add your additional commands or scripts to execute here su - gpadmin -c "gpstart -a" su - gpadmin -c "gpcc start" exit 0 EOF chmod +x /home/gpadmin/start_gpdb.sh cat >> /etc/rc.local <<"EOF" sh /home/gpadmin/start_gpdb.sh > /tmp/start_gpdb.log EOF chmod +x /etc/rc.d/rc.local systemctl enable rc-local.service systemctl status rc-local.service |