tech:cluster_script_de_test_stonith_fencing
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:cluster_script_de_test_stonith_fencing [2025/11/11 19:25] – Jean-Baptiste | tech:cluster_script_de_test_stonith_fencing [2026/06/30 20:36] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Script de test STONITH fencing cluster | ||
| + | |||
| + | Voir : | ||
| + | * [STONITH](https:// | ||
| + | * [Fencing](https:// | ||
| + | * [Fencing Redhat](https:// | ||
| + | |||
| + | Voir aussi : | ||
| + | * [Script pour VirtualBox](http:// | ||
| + | * [Script en Python](https:// | ||
| + | |||
| + | Source : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Ce script permet d' | ||
| + | Compatible cman, pacemaker et pcs | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | #!/bin/sh | ||
| + | |||
| + | # A fence agent for cman and pacemaker, using ssh. | ||
| + | # The only required argument is nodename. | ||
| + | # Author: | ||
| + | # klwang (http:// | ||
| + | # Note: | ||
| + | # authorized_keys configuration are required | ||
| + | # just for test, enjoy it! | ||
| + | # Source : https:// | ||
| + | |||
| + | |||
| + | SSH_COMMAND="/ | ||
| + | # | ||
| + | REBOOT_COMMAND=" | ||
| + | nodename= | ||
| + | action=reboot | ||
| + | |||
| + | usage () { | ||
| + | /bin/echo " | ||
| + | /bin/echo | ||
| + | /bin/echo " -n NODENAME" | ||
| + | /bin/echo " | ||
| + | /bin/echo " | ||
| + | /bin/echo " -o ACTION" | ||
| + | /bin/echo " | ||
| + | /bin/echo | ||
| + | exit 0 | ||
| + | } | ||
| + | |||
| + | arg_cmd() { | ||
| + | while getopts ": | ||
| + | case " | ||
| + | n|p) | ||
| + | nodename=$OPTARG | ||
| + | ;; | ||
| + | o) | ||
| + | action=$OPTARG | ||
| + | ;; | ||
| + | h) | ||
| + | action=" | ||
| + | ;; | ||
| + | *) | ||
| + | usage | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | } | ||
| + | |||
| + | arg_stdin() { | ||
| + | eval $(cat -) | ||
| + | if [ " | ||
| + | nodename=$port | ||
| + | fi | ||
| + | } | ||
| + | |||
| + | metadata() { | ||
| + | |||
| + | cat <<EOF | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | The style come from fence_pcmk, http:// | ||
| + | Some functions references external/ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <getopt mixed=" | ||
| + | <content type=" | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | <getopt mixed=" | ||
| + | <content type=" | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | <getopt mixed=" | ||
| + | <content type=" | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | <getopt mixed=" | ||
| + | <content type=" | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | <action name=" | ||
| + | <action name=" | ||
| + | <action name=" | ||
| + | <action name=" | ||
| + | <action name=" | ||
| + | <action name=" | ||
| + | </ | ||
| + | </ | ||
| + | EOF | ||
| + | |||
| + | exit 0 | ||
| + | } | ||
| + | |||
| + | get_usable_ip() { | ||
| + | |||
| + | for ip in `/ | ||
| + | if ping -w1 -c1 $ip > /dev/null 2>&1 | ||
| + | then | ||
| + | echo $ip | ||
| + | return 0 | ||
| + | fi | ||
| + | done | ||
| + | return 1 | ||
| + | |||
| + | } | ||
| + | |||
| + | is_host_up() { | ||
| + | |||
| + | for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do | ||
| + | if | ||
| + | ping -w1 -c1 " | ||
| + | then | ||
| + | sleep 1 | ||
| + | else | ||
| + | return 1 | ||
| + | fi | ||
| + | done | ||
| + | return 0 | ||
| + | |||
| + | } | ||
| + | |||
| + | reboot() { | ||
| + | |||
| + | local node=$1 | ||
| + | ip=`get_usable_ip $node` | ||
| + | if [ $? -ne 0 ];then | ||
| + | /bin/echo " | ||
| + | exit 0 # in case power lose | ||
| + | fi | ||
| + | |||
| + | if ! ping -c1 -w1 $ip >/ | ||
| + | exit 0 # in case the node have been fenced | ||
| + | fi | ||
| + | |||
| + | $SSH_COMMAND $ip "echo $(date +' | ||
| + | $SSH_COMMAND $ip " | ||
| + | |||
| + | if `is_host_up $ip`; then | ||
| + | exit 1 | ||
| + | else | ||
| + | exit 0 | ||
| + | fi | ||
| + | |||
| + | } | ||
| + | |||
| + | #main | ||
| + | |||
| + | if [ $# -gt 0 ]; then | ||
| + | arg_cmd $* | ||
| + | else | ||
| + | arg_stdin | ||
| + | fi | ||
| + | |||
| + | |||
| + | case " | ||
| + | |||
| + | metadata) | ||
| + | metadata | ||
| + | ;; | ||
| + | usage) | ||
| + | usage | ||
| + | ;; | ||
| + | on|off) | ||
| + | exit 0 # ssh can not turn on a node | ||
| + | # so avoiding turn it down | ||
| + | ;; | ||
| + | reset|reboot) | ||
| + | reboot $nodename | ||
| + | ;; | ||
| + | monitor) | ||
| + | exit 0 # just for pacemaker | ||
| + | ;; | ||
| + | help) | ||
| + | usage | ||
| + | ;; | ||
| + | *) | ||
| + | /bin/echo " | ||
| + | exit 1 | ||
| + | ;; | ||
| + | esac | ||
| + | ~~~ | ||
| + | |||
| + | Configuration | ||
| + | ~~~bash | ||
| + | pcs stonith create fencessh_node1 fence_ssh nodename=node1 pcmk_host_list=node1 | ||
| + | pcs stonith create fencessh_node2 fence_ssh nodename=node2 pcmk_host_list=node2 | ||
| + | pcs stonith level add 1 node1 fencessh_node1 | ||
| + | pcs stonith level add 1 node2 fencessh_node2 | ||
| + | |||
| + | # Interdire le fence de soi-même | ||
| + | pcs constraint location fencessh_node1 avoids node1 | ||
| + | pcs constraint location fencessh_node2 avoids node2 | ||
| + | ~~~ | ||
| + | |||
| + | Test | ||
| + | ~~~bash | ||
| + | pcs stonith fence node2 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | Lister | ||
| + | ~~~bash | ||
| + | pcs stonith list | ||
| + | stonith_admin -I | ||
| + | ~~~ | ||
| + | |||
| + | |||
