---
title: "MaxScale を CentOS 7 にインストール"
publish_date: 2019-07-09
updated_date: 2023-10-12
author: "MariaDB"
tags:
  - name: "MaxScale"
    url: "/ja/resources/blog/tag/maxscale-ja.md"
---

# MaxScale を CentOS 7 にインストール

MariaDB MaxScale は非常に高機能な DB Proxy で，[BSL(Business Source License) 1.1](https://www.s-style.co.jp/blog/2019/01/3050/) でライセンスされており，主に以下のような機能を備えています。

- Read/Write Splitting
- レプリケーションクラスタ[自動フェイルオーバー](https://www.s-style.co.jp/blog/2018/05/1877/)
- [transaction\_replay](https://www.s-style.co.jp/blog/2019/02/3380/)
- マスキング・フィルター
- firewall

今回は MaxScale 最新版 を CentOS 7 にインストールする手順を解説いたします。

### 実行環境

- CentOS 7.6.1810
- MaxScale 2.3.8

### レポジトリ設定

以下のワンライナーを実行することで，MariaDB Server / MaxScale / Tools のレポジトリ設定を行うことができます。

```
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

```

ref: <https://staging-mdb.com/kb/en/library/mariadb-package-repository-setup-and-usage/>

/etc/yum.repos.d/mariadb.repo が以下のように生成されます。

```
[mariadb-main]
name = MariaDB Server
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.4/yum/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-maxscale]
name = MariaDB MaxScale
baseurl = https://downloads.mariadb.com/MaxScale/2.3/centos/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-tools]
name = MariaDB Tools
baseurl = https://downloads.mariadb.com/Tools/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1

```

### MaxScale のインストール

以下の yum コマンドで MaxScale をインストールできます。

```
sudo yum -y install maxscale

```

### サンプル設定 : /etc/maxscale.cnf

MaxScale の設定ファイルはデフォルトでは /etc/maxscale.cnf となります。3インスタンスでPrimary-Replicaレプリケーションを行う場合の設定例を以下に記載します。

```
[maxscale]
threads=auto

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=maxuser
password=maxpwd
auto_failover=true
auto_rejoin=true

[Splitter-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxuser
password=maxpwd
# 2.3
master_failure_mode=error_on_write
master_reconnection=true
transaction_replay=true
causal_reads=false

[Splitter-Listener]
type=listener
service=Splitter-Service
protocol=mariadbclient
port=3306

[server1]
type=server
address=192.168.2.101
port=3306
protocol=mariadbbackend

[server2]
type=server
address=192.168.2.102
port=3306
protocol=mariadbbackend

[server3]
type=server
address=192.168.2.103
port=3306
protocol=mariadbbackend

```

この設定では Primary x1, Replica x2 のレプリケーションクラスタにおいて，以下の機能を有効にしています。

- MariaDB Monitor : [auto\_failover](https://www.s-style.co.jp/blog/2018/05/1877/)(自動フェイルオーバー) / auto\_rejoin
- Read/Write split : [transaction\_replay](https://staging-mdb.com/ja/resources/blog/maxscale-2-3-transaction-replay/) / [causal\_reads](https://staging-mdb.com/ja/resources/blog/maxscale-2-3-causal-reads/)

MaxScale がバックエンドの MariaDB Server にアクセスするために必要なユーザ名(maxuser)/パスワード(maxpwd)は，プロダクション環境では適宜安全なものに変更願います。  
この管理用ユーザは各 MariaDB Server インスタンス上で作成しておく必要があります。レプリケーション開始後であれば，Primary でユーザ作成すれば，Replica にもユーザが複製されます。

### MaxScale の起動

MaxScale のサービス maxscale.service を有効化/開始するには以下のコマンドを実行します。

```
systemctl enable maxscale
systemctl start maxscale

```

### 動作確認

MaxScale では，maxctrl というCLIベースの管理コマンドが提供されています。

<https://staging-mdb.com/kb/en/mariadb-maxscale-23-maxctrl/>

よく利用される maxctrl のサブコマンドの例を以下に記載します。

```
# maxctrl list servers
┌─────────┬───────────────┬──────┬─────────────┬─────────────────┬─────────┐
│ Server  │ Address       │ Port │ Connections │ State           │ GTID    │
├─────────┼───────────────┼──────┼─────────────┼─────────────────┼─────────┤
│ server1 │ 192.168.2.101 │ 3306 │ 0           │ Master, Running │ 0-101-4 │
├─────────┼───────────────┼──────┼─────────────┼─────────────────┼─────────┤
│ server2 │ 192.168.2.102 │ 3306 │ 0           │ Slave, Running  │ 0-101-4 │
├─────────┼───────────────┼──────┼─────────────┼─────────────────┼─────────┤
│ server3 │ 192.168.2.103 │ 3306 │ 0           │ Slave, Running  │ 0-101-4 │
└─────────┴───────────────┴──────┴─────────────┴─────────────────┴─────────┘

```

MariaDB Monitor(Galera Clusterの場合は [Galera Monitor](https://staging-mdb.com/kb/en/mariadb-maxscale-23-galera-monitor/)) でモニタリングされている各 MariaDB インスタンスのステータスを確認することが可能です。

```
# maxctrl list monitors
┌─────────────────┬─────────┬───────────────────────────┐
│ Monitor         │ State   │ Servers                   │
├─────────────────┼─────────┼───────────────────────────┤
│ MariaDB-Monitor │ Running │ server1, server2, server3 │
└─────────────────┴─────────┴───────────────────────────┘

```

MaxScale の各モニタのステータスが確認できます。

```
# maxctrl list services
┌──────────────────┬────────────────┬─────────────┬───────────────────┬───────────────────────────┐
│ Service          │ Router         │ Connections │ Total Connections │ Servers                   │
├──────────────────┼────────────────┼─────────────┼───────────────────┼───────────────────────────┤
│ Splitter-Service │ readwritesplit │ 1           │ 1                 │ server1, server2, server3 │
└──────────────────┴────────────────┴─────────────┴───────────────────┴───────────────────────────┘

```

MaxScale の各サービスの利用状況を確認できます。

### ライセンス

MaxScale 2.x は Business Source License [BSL 1.1](https://www.s-style.co.jp/blog/2019/01/3050/) でライセンスされており，MaxScale 2.3 であれば，2022-01-01 に GPL v2 に移行します。

<https://github.com/mariadb-corporation/MaxScale/blob/2.3/LICENSE.TXT>

2022-01-01 以前は MariaDB Server / ColumnStore インスタンス数が 2 以下であれば，プロダクション環境においてもライセンス購入は不要です。

例: Primary x1 – Replica x 1 でのレプリケーション

MariaDB Server / ColumnStore インスタンス数が 3 以上となると MariaDB Platform X3 サブスクリプションの購入が必要となります。

### まとめ

MariaDB Corporation で開発されている高機能DB Proxy, MaxScale の基本的なインストール/設定を解説させて頂きました。下記の MaxScale タグで過去の MaxScale 関連のブログ投稿がご覧いただけますので，こちらもあわせて参考にして頂ければと存じます。