MariaDB Galera Replicationを使用してApache CloudStackフェールオーバー管理サーバーを構成する



Apache CloudStackに関する私の最初2番目の記事の後、ユーザーからGaleraを使用して高可用性ACS管理サーバーを編成する方法を尋ねられました。 以前は、このような展開トポロジを使用しませんでしたが、このため、このような構成を実行しようとすることにしました。







この記事では、MariaDB(Galera)マルチマスタークラスターと共にApache CloudStack管理サーバーのフェールオーバー構成を展開する方法について説明します。 このマニュアルの開発では、次のバージョンのソフトウェア製品が使用されました。







  1. Apache CloudStack 4.9.2
  2. CentOS 7
  3. MariaDB 5.5.52(CentOS 7のデフォルト)
  4. Ansible 2.3.1(CentOS 7のデフォルト)


UPD:記事の最初の発行後、アーキテクトのShapeBlueは、元のバージョンを完全に使用できないACSの制限に注意を喚起したため、特定された欠点を考慮して記事を修正しました。

ターゲットシステムの展開モデルを次の図に示します。













このモデルでは、各ACSサーバーは選択されたMariaDBサーバーにマスターとして接続され、残りのサーバーはスレーブとして割り当てられます。 一部の英語版マニュアルでは、中間HAProxyコンポーネントを使用してMariaDBへの接続の追加レイヤーを整理し、各ACSサーバーが障害発生時にDBMSサーバー間を透過的に切り替えることができるように提案していますが、設定可能なACSサーバー間の外部トラフィックスイッチングを整理するだけで十分ですnginxを使用します。







一般的な展開スキーム



システム全体の展開プロセスの一般的な概要と最初の仮定を考慮してください。







MariaDB



MariaDB構成を展開するには、Ansible Playbookを入手してください。

Github このアプローチにより、ACSのインストール方法に正確に集中できますが、Galeraクラスターの構成はできません。 上記のプレイブックはCentOS 7で使用するように設計されているため、それに応じてオペレーティングシステムが選択されます。 読者がACS 4.9.2と互換性のある別のオペレーティングシステムで同様の構成を実行する予定の場合、一般的なスキームは同じままです。







プレイブックは私のものではありません。 リポジトリには、フォークの作成元が表示されます。 オリジナルに比べて、eth0でネットワークをサポートするためにわずかに修正されています。


Apache CloudStack



奇妙に聞こえるかもしれませんが、ACS 4.9.2は動作中のGaleraクラスタにインストールできません。 この制限は、インストール中に管理サーバーがバージョン4.0のデータベースを作成し、それが一連​​の移行によってデータベースバージョン4.9.2に変換されるという事実により発生します。 初期インストールおよび移行プロセスでは、クラスタバージョンのGalera(以前のバージョンのACSで使用されていた)でサポートされていないデータベースエンジンを使用するため、プロセスは正常に完了しません。







この問題を克服するために、いくつかの段階でインストールを実行します。







  1. データベースダンプを削除して、通常のMySQLサーバーにACS 4.9.2をインストールします。
  2. データベースをGaleraクラスターにインポートします。
  3. 管理サーバーをGaleraクラスターに接続します。


出力は、最初の図に示されている作業トポロジになります。







テストベンチ



展開は4つのホストで実行されます。







  1. ac -ansibleがインストールされたCentOS 7ホスト。ここから残りのホストを構成し、Galeraを使用せずにACS 4.9.2の初期展開を実行します。
  2. h1h2h3 -ACS 4.9.2およびGaleraのクラスターバージョンがインストールされるCentOS 7ホスト。


Galera Cluster Deployment Playbookは、ホストがeth0ネットワークカードを介してアクセス可能な安全なネットワーク(単純化されたファイアウォール構成)上にあることを前提としています。 Playbookは、 firewalld



サービスが使用されていることを前提としています。







基本インストール(HAなし)



ACホストに基本コンポーネントをインストールします。







 # yum install epel-release # yum install net-tools git mariadb mariadb-server ansible
      
      





MariaDBを起動します。







 # systemctl start mariadb
      
      





MariaDBが機能することを確認します。







 # mysql -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
      
      





MariaDBサーバー設定(/etc/my.cnf.d/server.cnf)の[mysql]セクションに、推奨されるACSオプションを追加します。







 [mysql] innodb_rollback_on_timeout=1 innodb_lock_wait_timeout=600 max_connections=350 log-bin=mysql-bin binlog-format = 'ROW'
      
      





MariaDBの再起動:







 # systemctl restart mariadb
      
      





次の内容を使用して、Apache CloudStack /etc/yum.repos.d/cloudstack.repo



Yumリポジトリファイルを作成します。







 [cloudstack] name=cloudstack baseurl=http://cloudstack.apt-get.eu/centos/7/4.9/ enabled=1 gpgcheck=0
      
      





ACS管理サーバーパッケージをインストールします。







 # yum install cloudstack-management
      
      





Javaセキュリティファイルの編集:







 # grep -l '/dev/random' /usr/lib/jvm/java-*/jre/lib/security/java.security /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre/lib/security/java.security
      
      





乱数ジェネレーターを置き換えます(ACSで使用される暗号化ライブラリに必要):







 # sed -i 's#securerandom.source=file:/dev/random#securerandom.source=file:/dev/urandom#' /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre/lib/security/java.security
      
      





ファイルでSELinuxポリシーをpermissiveに変更します。







 # sed -i 's#SELINUX=enforcing#SELINUX=permissive#' /etc/selinux/config
      
      





rootユーザーからACSデータベースのインストールを開始します(MariaDBクラウド/シークレットへのアクセスを使用)(ローカルDBMSアクセスパスワードは必要ありません):







 # cloudstack-setup-databases cloud:secret@localhost --deploy-as=root Mysql user name:cloud [ OK ] Mysql user password:****** [ OK ] Mysql server ip:localhost [ OK ] Mysql server port:3306 [ OK ] Mysql root user name:root [ OK ] Mysql root user password:****** [ OK ] Checking Cloud database files ... [ OK ] Checking local machine hostname ... [ OK ] Checking SELinux setup ... [ OK ] Detected local IP address as 176.120.25.66, will use as cluster management server node IP[ OK ] Preparing /etc/cloudstack/management/db.properties [ OK ] Applying /usr/share/cloudstack-management/setup/create-database.sql [ OK ] Applying /usr/share/cloudstack-management/setup/create-schema.sql [ OK ] Applying /usr/share/cloudstack-management/setup/create-database-premium.sql [ OK ] Applying /usr/share/cloudstack-management/setup/create-schema-premium.sql [ OK ] Applying /usr/share/cloudstack-management/setup/server-setup.sql [ OK ] Applying /usr/share/cloudstack-management/setup/templates.sql [ OK ] Processing encryption ... [ OK ] Finalizing setup ... [ OK ] CloudStack has successfully initialized database, you can check your database configuration in /etc/cloudstack/management/db.properties
      
      





管理サーバーのインストールを開始します。







 # cloudstack-setup-management --tomcat7 Starting to configure CloudStack Management Server: Configure Firewall ... [OK] Configure CloudStack Management Server ...[OK] CloudStack Management Server setup is Done!
      
      





数秒後にサーバーの可用性を確認します( http:// ac:8080 / client ):







 # LANG=C wget -O /dev/null http://ac:8080/client 2>&1 | grep '200 OK' HTTP request sent, awaiting response... 200 OK
      
      





ブラウザを使用してURLにアクセスし、サーバーが機能していることと、管理者とパスワードのペアを使用した認証が許可されていることを確認することをお勧めします。 すべてがうまくいけば、管理サーバーは正常にインストールされています。







次に、データベースダンプを保存して、Galeraクラスタにさらにインポートします。







 # mysqldump -uroot cloud >cloud.sql # mysqldump -uroot cloud_usage >cloud_usage.sql
      
      





すべてのテーブルがInnoDB形式であることを確認します。







 # grep ENGINE *.sql | grep -v InnoDB | grep -v -c '*/' 0
      
      





Galera複製環境を構成する



Galeraクラスタの展開は、Ansibleを使用して実行されます。 AnsibleはSSHで実行されるため、ホストacのホストh1、h2、h3にSSHキーの公開部分を配置する必要があります。







ホストacでSSHキーを生成します。







 # ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 30:81:f7:90:f0:4f:e0:d4:8a:74:ca:40:ba:d9:c7:8e root@ac The key's randomart image is: +--[ RSA 2048]----+ | .. .o+o | | .. o+=o. | |. + ==+. | | + .+ .=. | |o . o S | | + | | E . | | | | | +-----------------+
      
      





すべてのホストにキーを配布します。







 # ssh-copy-id h1 The authenticity of host 'h1 (XYZC)' can\'t be established. ECDSA key fingerprint is 27:f7:34:23:ea:b4:d2:61:8c:ec:d8:13:c2:9f:8a:ef. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@h1\'s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'h1'" and check to make sure that only the key(s) you wanted were added.
      
      





ホストh2とh3についても同じことを行います。







ここで、Ansibleプレイブックを使用してGitリポジトリのクローンを作成する必要があります。







 # git clone https://github.com/bwsw/mariadb-ansible-galera-cluster.git Cloning into 'mariadb-ansible-galera-cluster'... remote: Counting objects: 194, done. remote: Compressing objects: 100% (5/5), done. remote: Total 194 (delta 0), reused 2 (delta 0), pack-reused 188 Receiving objects: 100% (194/194), 29.91 KiB | 0 bytes/s, done. Resolving deltas: 100% (68/68), done.
      
      





ディレクトリをmariadb-ansible-galera-cluster



変更しmariadb-ansible-galera-cluster









 # cd mariadb-ansible-galera-cluster # pwd /root/mariadb-ansible-galera-cluster
      
      





galera.hosts



ファイルを編集します。ここで、h1、h2、h3サーバーを示します。







 [galera_cluster] h[1:3] ansible_user=root
      
      





設定が正しいことを確認します。







 # ansible -i galera.hosts all -m ping h3 | SUCCESS => { "changed": false, "ping": "pong" } h2 | SUCCESS => { "changed": false, "ping": "pong" } h1 | SUCCESS => { "changed": false, "ping": "pong" }
      
      





必要な依存関係を設定します。







 # ansible -i galera.hosts all -m raw -s -a "yum install -y epel-release firewalld ntpd"
      
      





システム時刻を更新します。







 # ansible -i galera.hosts all -m raw -s -a "chkconfig ntpd on && service ntpd stop && ntpdate 165.193.126.229 0.ru.pool.ntp.org 1.ru.pool.ntp.org 2.ru.pool.ntp.org 3.ru.pool.ntp.org && service ntpd start"
      
      





以下の説明に従って、ansible設定ファイル(/etc/ansible/ansible.cfg)に必要な変更を加えます。

プレイブックのREADME.md







 [defaults] gathering = smart fact_caching = jsonfile fact_caching_connection = ~/.ansible/cache
      
      





README.mdプレイブックに従ってGaleraクラスターのインストールを進めましょう。







 # ansible-playbook -i galera.hosts galera.yml --tags setup
      
      





実装の結果によると、これには数分かかります。クラスターアセンブリなしでh1、h2、h3ホストにインストールされたMariaDBサーバーを取得します。 次のステップは、プレイブックの残りのステップを開始することです。







 # ansible-playbook -i galera.hosts galera.yml --skip-tags setup
      
      





最後のステップは、クラスターを開始することです。







 # ansible-playbook -i galera.hosts galera_bootstrap.yml
      
      





クラスタの状態を確認してください。 これを行うには、ホストh1、h2、h3に移動して、mysqlコンソールで次を実行します。







 # mysql -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.1.25-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW GLOBAL STATUS LIKE 'wsrep_%'; +------------------------------+------------------------------------------------------------+ | Variable_name | Value | +------------------------------+------------------------------------------------------------+ | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 0.000000 | | wsrep_causal_reads | 0 | | wsrep_cert_deps_distance | 0.000000 | | wsrep_cert_index_size | 0 | | wsrep_cert_interval | 0.000000 | | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | 230ed410-6b9b-11e7-8aa5-4b041fceb486 | | wsrep_cluster_status | Primary | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 0.000000 | | wsrep_connected | ON | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_recv | 0 | | wsrep_flow_control_sent | 0 | | wsrep_gcomm_uuid | 230d9f4f-6b9b-11e7-ba99-fab39514a7e8 | | wsrep_incoming_addresses | 111.120.25.96:3306,111.120.25.229:3306,111.120.25.152:3306 | | wsrep_last_committed | 0 | | wsrep_local_bf_aborts | 0 | | wsrep_local_cached_downto | 18446744073709551615 | | wsrep_local_cert_failures | 0 | | wsrep_local_commits | 0 | | wsrep_local_index | 0 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_avg | 0.000000 | | wsrep_local_recv_queue_max | 1 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_local_state_uuid | 230ed410-6b9b-11e7-8aa5-4b041fceb486 | | wsrep_protocol_version | 7 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 25.3.20(r3703) | | wsrep_ready | ON | | wsrep_received | 10 | | wsrep_received_bytes | 769 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_thread_count | 2 | +------------------------------+------------------------------------------------------------+ 58 rows in set (0.01 sec) MariaDB [(none)]>
      
      





wsrep_incoming_addresses



フィールドに注意してください。3つのサーバーh1、h2、h3のIPアドレスがあるはずです。







Galera複製環境用の管理サーバーをインストールする



次のステップは、 cloud.sql



およびcloud_usage.sql



をクラスターにインポートすることcloud.sql









コピーダンプ:







 # scp ../*.sql h1: cloud.sql 100% 1020KB 1.0MB/s 00:00 cloud_usage.sql 100% 33KB 32.7KB/s 00:00
      
      





ホストh1へのSSH接続を開いて、すべてのデータベースインポート操作を実行します。







 # ssh h1
      
      





データベースを作成し、ユーザーに権限を付与して、ダンプをインポートしましょう。







 [root@h1 ~]# echo "CREATE DATABASE cloud;" | mysql -uroot [root@h1 ~]# echo "CREATE DATABASE cloud_usage;" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud.* TO cloud@'localhost' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud_usage.* TO cloud@'localhost' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud.* TO cloud@'h1' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud_usage.* TO cloud@'h1' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud.* TO cloud@'h2' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud_usage.* TO cloud@'h2' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud.* TO cloud@'h3' identified by 'secret'" | mysql -uroot [root@h1 ~]# echo "GRANT ALL PRIVILEGES ON cloud_usage.* TO cloud@'h3' identified by 'secret'" | mysql -uroot [root@h1 ~]# cat cloud.sql | mysql -uroot cloud [root@h1 ~]# cat cloud_usage.sql | mysql -uroot cloud_usage
      
      





クラウドのcloud_usageデータベースがh2およびh3サーバーに複製されていることを確認する価値があります。

次に、ACS管理サーバーをインストールします。 最初に、 ACホストからACSリポジトリ設定をコピーします。







 # ansible -i galera.hosts all -m copy -a "src=/etc/yum.repos.d/cloudstack.repo dest=/etc/yum.repos.d/cloudstack.repo"
      
      





次に、Apache CloudStack管理サーバーパッケージをインストールします。







 # ansible -i galera.hosts all -m raw -s -a "yum install -y cloudstack-management"
      
      





既知のJavaセキュリティ設定を変更します。







 # ansible -i galera.hosts all -m raw -s -a "sed -i 's#securerandom.source=file:/dev/random#securerandom.source=file:/dev/urandom#' /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre/lib/security/java.security"
      
      





ホストh1上のDBMSへのACS管理サーバーの接続を設定しましょう。







 # ansible -i galera.hosts all -m raw -s -a "cloudstack-setup-databases cloud:secret@h1"
      
      





これで、すべてのサーバーがh1ホストをメインDBMSサーバーとして使用します。 次に、補助サーバーの追加構成を実行します。







MySQLへのアクセス性の高いApache CloudStack接続のパッケージをインストールします(何らかの理由で、CentOS 7にはありません)。







 # ansible -i galera.hosts all -m raw -s -a "rpm -i http://packages.shapeblue.com.s3-eu-west-1.amazonaws.com/cloudstack/upstream/centos7/4.9/cloudstack-mysql-ha-4.9.2.0-shapeblue0.el7.centos.x86_64.rpm"
      
      





サーバーの管理を開始します。







 # ansible -i galera.hosts all -m raw -s -a "cloudstack-setup-management --tomcat7"
      
      





すべてが稼働していることを確認します。







 # ansible -i galera.hosts all -m raw -s -a "ps xa | grep java"
      
      





現在、 http:// h1:8080 / clienthttp:// h2:8080 / clienthttp:// h3:8080 / clientのアドレスで、高可用性を確保するためにnginxによって閉じることができるフォールトトレラント制御サーバーが実行されています。 同時に、/ /var/log/cloudstack/management/management-server.log



log / /var/log/cloudstack/management/management-server.log



ログで、サーバーが相互に認識しているレコードを確認できます。







 # cat /var/log/cloudstack/management/management-server.log | grep 'management node' 2017-07-18 17:05:27,209 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-b1d64593) (logid:18f29c84) Detected management node joined, id:7, nodeIP:111.120.25.96 2017-07-18 17:05:27,231 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-b1d64593) (logid:18f29c84) Detected management node joined, id:12, nodeIP:111.120.25.152 2017-07-18 17:05:27,231 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-b1d64593) (logid:18f29c84) Detected management node joined, id:17, nodeIP:111.120.25.229 2017-07-18 17:05:33,195 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-76484aea) (logid:b7416e7b) Detected management node left and rejoined quickly, id:7, nodeIP:111.120.25.96 2017-07-18 17:07:22,582 INFO [cccClusterManagerImpl] (localhost-startStop-1:null) (logid:) Detected that another management node with the same IP 111.120.25.229 is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node 2017-07-18 17:07:33,292 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-8880f35d) (logid:037a1c4d) Detected management node joined, id:7, nodeIP:111.120.25.96 2017-07-18 17:07:33,312 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-8880f35d) (logid:037a1c4d) Detected management node joined, id:12, nodeIP:111.120.25.152 2017-07-18 17:07:33,312 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-8880f35d) (logid:037a1c4d) Detected management node joined, id:17, nodeIP:111.120.25.229 2017-07-18 17:12:41,927 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-7e3e2d82) (logid:e63ffa72) Detected management node joined, id:7, nodeIP:111.120.25.96 2017-07-18 17:12:41,935 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-7e3e2d82) (logid:e63ffa72) Detected management node joined, id:12, nodeIP:111.120.25.152 2017-07-18 17:12:41,935 DEBUG [cccClusterManagerImpl] (Cluster-Heartbeat-1:ctx-7e3e2d82) (logid:e63ffa72) Detected management node joined, id:17, nodeIP:111.120.25.229
      
      





構成の最後に、追加のGalera(h2、h3)サーバーをスレーブサーバーとして使用するようにACS制御サーバーを構成し、ACS制御サーバーを再起動します。







 # ansible -i galera.hosts all -m raw -s -a "service cloudstack-management stop" # ansible -i galera.hosts all -m raw -s -a "sed -i 's#db.ha.enabled=false#db.ha.enabled=true#' /etc/cloudstack/management/db.properties" # ansible -i galera.hosts all -m raw -s -a "sed -i 's#db.cloud.slaves=.*#db.cloud.slaves=h2,h3#' /etc/cloudstack/management/db.properties" # ansible -i galera.hosts all -m raw -s -a "sed -i 's#db.usage.slaves=.*#db.usage.slaves=h2,h3#' /etc/cloudstack/management/db.properties" # ansible -i galera.hosts all -m raw -s -a "service cloudstack-management start"
      
      





おわりに



セットアップは非常に簡単で、問題を引き起こすことはありません。 インストール後にレプリケートされていない環境からレプリケートされた環境への転送手順を実行せずに、Galeraクラスターにすぐにインストールすることは不可能であることは、やや不満です。








All Articles