転載・引用について

ユーザ用ツール

サイト用ツール


サイドバー

Site Contents Index

転載・引用について

RSS

serverapp:database:mariadb:initial-config

MariaDBの初期設定

Last Update: 2015/11/19

  1. 起動の準備
    • CentOS
      • /etc/my.cnf.d/server.cnfを修正。
    • FreeBSD
      • /usr/local/etc/my.cnfを作成。CentOSと同じように、my.cnf.dをつくってmy.cnfから読むようにしても良い
    • [mysqld]セクションにcharacter-set-server=utf8をとにかく足す
  2. MariaDB Serverを起動する
    • CentOS
      • service mysql start
      • service mariadb では無いことに注意
    • FreeBSD
      • vi /etc/rc.conf
        • mysql_enable="YES"
          mysql_limits="NO"
          mysql_dbdir="any/where"
      • default以外の場所にDBのDirを切るなら、mkdir して、permissionをmysql:mysqlにしておくこと
        • 細かいDirも作成し、permissionを変更すること
      • service mysql-server start
    • 立ち上がったら、mysql_secure_installationを実行して、root password等の設定を行う
      • もし立ち上がらなかったら、mysql_install_db scriptを実行すること。
        • FreeBSDの場合、/usr/local/bin/mysql_install_db –basedir=/usr/local –datadir=…
        • もしかすると、mysql.sockを/tmpにsymlinkする必要があるかもしれない。
    • [foo@bar ~]$ sudo mysql_secure_installation
      /usr/bin/mysql_secure_installation: line 379: find_mysql_client: コマンドが見つかりません
      
      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
            SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
      
      In order to log into MariaDB to secure it, we'll need the current
      password for the root user.  If you've just installed MariaDB, and
      you haven't set the root password yet, the password will be blank,
      so you should just press enter here.
      
      Enter current password for root (enter for none): 
      OK, successfully used password, moving on...
      
      Setting the root password ensures that nobody can log into the MariaDB
      root user without the proper authorisation.
      
      Set root password? [Y/n] y
      New password: ****************
      Re-enter new password: ****************
      
      Password updated successfully!
      Reloading privilege tables..
       ... Success!
      
      
      By default, a MariaDB installation has an anonymous user, allowing anyone
      to log into MariaDB without having to have a user account created for
      them.  This is intended only for testing, and to make the installation
      go a bit smoother.  You should remove them before moving into a
      production environment.
      
      Remove anonymous users? [Y/n] y
       ... Success!
      
      Normally, root should only be allowed to connect from 'localhost'.  This
      ensures that someone cannot guess at the root password from the network.
      
      Disallow root login remotely? [Y/n] y
       ... Success!
      
      By default, MariaDB comes with a database named 'test' that anyone can
      access.  This is also intended only for testing, and should be removed
      before moving into a production environment.
      
      Remove test database and access to it? [Y/n] y
       - Dropping test database...
       ... Success!
       - Removing privileges on test database...
       ... Success!
      
      Reloading the privilege tables will ensure that all changes made so far
      will take effect immediately.
      
      Reload privilege tables now? [Y/n] y
       ... Success!
      
      Cleaning up...
      
      All done!  If you've completed all of the above steps, your MariaDB
      installation should now be secure.
      
      Thanks for using MariaDB!
      [foo@bar ~]$ 
  3. これで、MariaDBに繋いでみて、問題が無ければOK
    • mysql -u root -p (コマンド名がmysqlなので注意すること)
    • とにかく、初期状態を確認
      • MariaDB [(none)]> \s
        --------------
        mysql  Ver 15.1 Distrib 5.5.34-MariaDB, for Linux (x86_64) using readline 5.1
        
        Connection id:		10
        Current database:	
        Current user:		root@localhost
        SSL:			Not in use
        Current pager:		stdout
        Using outfile:		''
        Using delimiter:	;
        Server:			MariaDB
        Server version:		5.5.34-MariaDB MariaDB Server
        Protocol version:	10
        Connection:		Localhost via UNIX socket
        Server characterset:	utf8
        Db     characterset:	utf8
        Client characterset:	utf8
        Conn.  characterset:	utf8
        UNIX socket:		/var/lib/mysql/mysql.sock
        Uptime:			18 min 7 sec
        
        Threads: 1  Questions: 28  Slow queries: 0  Opens: 1  Flush tables: 2  Open tables: 27  Queries per second avg: 0.025
        --------------
        
        MariaDB [(none)]> 
    • ついでに、Pluginも確認しておく。
      • MariaDB [(none)]> show plugins;
        +--------------------------------+----------+--------------------+---------+---------+
        | Name                           | Status   | Type               | Library | License |
        +--------------------------------+----------+--------------------+---------+---------+
        | binlog                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | mysql_native_password          | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
        | mysql_old_password             | ACTIVE   | AUTHENTICATION     | NULL    | GPL     |
        | CSV                            | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | MEMORY                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | MyISAM                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | MRG_MYISAM                     | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | BLACKHOLE                      | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | InnoDB                         | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | INNODB_RSEG                    | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_UNDO_LOGS               | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_TRX                     | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_LOCKS                   | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_LOCK_WAITS              | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_CMP                     | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_CMP_RESET               | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_CMPMEM                  | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_CMPMEM_RESET            | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_TABLES              | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_TABLESTATS          | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_INDEXES             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_COLUMNS             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_FIELDS              | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_FOREIGN             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_FOREIGN_COLS        | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_SYS_STATS               | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_TABLE_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_INDEX_STATS             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_POOL_PAGES       | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_POOL_PAGES_INDEX | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_POOL_PAGES_BLOB  | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | XTRADB_ADMIN_COMMAND           | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_CHANGED_PAGES           | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_PAGE             | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_PAGE_LRU         | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | INNODB_BUFFER_POOL_STATS       | ACTIVE   | INFORMATION SCHEMA | NULL    | GPL     |
        | FEDERATED                      | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | ARCHIVE                        | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | PERFORMANCE_SCHEMA             | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | Aria                           | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        | FEEDBACK                       | DISABLED | INFORMATION SCHEMA | NULL    | GPL     |
        | partition                      | ACTIVE   | STORAGE ENGINE     | NULL    | GPL     |
        +--------------------------------+----------+--------------------+---------+---------+
        42 rows in set (0.00 sec)
        
        MariaDB [(none)]> 
      • なお、MySQLと同じ方法で、Semisync Pluginsも入る。

追加の設定

ここまでできたら、MariaDBは動作している状態になる。

  • 追加設定をいくつか。
    • /etc/my.cnf.d/server.cnf[mysqld] セクションに以下を追加
      • plugin-load = handlersocket.so;semisync_master.so;semisync_slave.so
        • ;の前後に (スペース)等を入れてはいけません。(はまる)
        • handlersocket: 高速化Plugin.(正確には、ストレージエンジンへの直接のアクセスを提供するものらしい)
        • semisync_master: SemiSynchronas Replication用のPlugin。Master側
        • semisync_slave: SemiSynchronas Replication用のPlugin。Slave側

DB管理者アカウントを追加

  1. 必要なAccountを作成すればOK
    • 特権管理者を作成する
      • $ mysql -u root -p
        MariaDB [(none)]> grant all privileges on *.* to foo@localhost identified by 'DB Ultra Secret';
        Query OK, 0 rows affected (0.00 sec)
        
        MariaDB [(none)]> grant all privileges on *.* to foo@127.0.0.1 identified by 'DB Ultra Secret';
        Query OK, 0 rows affected (0.00 sec)
        
        MariaDB [(none)]> grant all privileges on *.* to foo@::1 identified by 'DB Ultra Secret';
        Query OK, 0 rows affected (0.00 sec)
        
        MariaDB [(none)]> flush privileges;
        Query OK, 0 rows affected (0.00 sec)
      • これで、rootでDBを触る必要がなくなる。
        • 但し、これは、単にrootに匹敵する特権アカウントを作っただけなので、管理には十分に注意すること
        • 本来であれば、権限をちゃんと分離するべきなので、そこに十分に注意すること
        • GRANT権限まで付与する場合には、WITH GRANT OPTIONを追加すること

起動時にMaridDBが動作するようにする

再起動時にMariaDBが動作するようにする。

  • CentOS
    • chkconfig mysql on
  • FreeBSD
    • /etc/rc.confに以下を設定
      • mysql_enable="YES"
        mysql_limits="NO"
        mysql_dbdir="/var/db/mysql"

MariaDBの設定ファイル

server.cnf
#
# /etc/my.cnf.d/server.cnf
#
# Configuration for MariaDB server.
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
user=mysql
datadir=/var/lib/mysql/DB
# datadir=/var/db/mysql
bind-address=127.0.0.1
character-set-server=utf8
#skip-character-set-client-handshake
skip-name-resolve

expire_logs_days=7
#log_output="NONE"
log_output="FILE"
#log_output="FILE,TABLE"
#general-log=0
general-log=1
general-log-file=/var/lib/mysql/log/mysql
#general-log-file=/var/db/mysql/log/mysql
log_error=/var/lib/mysql/log/mysql-error
#log_error=/var/db/mysql/log/mysql-error
#slow_query_log=0
slow_query_log=1
slow_query_log_file = /var/lib/mysql/log/mysql-slow.log
#slow_query_log_file = /var/db/mysql/log/mysql-slow.log
max_binlog_size=100M
sync_binlog=1
binlog_format=mixed
log_bin=/var/lib/mysql/log/mysql-bin
#log_bin=/var/db/mysql/log/mysql-bin
relay_log=/var/lib/mysql/log/mysql-relay
relay_log=/var/db/mysql/log/mysql-relay
log_slave_updates

key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
thread_concurrency = 8

innodb_buffer_pool_size = 768M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_support_xa=1
innodb_log_files_in_group = 7
innodb_autoextend_increment=64
innodb_file_per_table

plugin-load = handlersocket.so;semisync_master.so;semisync_slave.so

#rpl_semi_sync_master_enabled =1
#rpl_semi_sync_slave_enabled = 1
#rpl_semi_sync_master_timeout=30

# this is only for embedded server
[embedded]

# This group is only read by MariaDB-5.5 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mysqld-5.5]

# These two groups are only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

[mariadb-5.5]

なお、この設定では、SQL Queryのlogや、slow logも収集するようになっているので、必要に応じてOffにすること。 このままでは性能が劣化します。
slow-logを取得する際には、mysql-slow をtouchすること

加えて、うかつにinnodb_log_buffer_sizeやinnodb_log_files_in_groupを書き換えると起動しなくなります。 そういう場合には、http://gitpub.hatenablog.com/entry/2013/08/02/001600を参照して作業すること。

このウェブサイトはクッキーを使用しています。 Webサイトを使用することで、あなたはあなたのコンピュータにクッキーを保存することに同意します。 また、あなたはあなたが私たちのプライバシーポリシーを読んで理解したことを認めます。 同意しない場合はウェブサイトを離れてください。クッキーに関する詳細情報
serverapp/database/mariadb/initial-config.txt · 最終更新: 2015/11/20 16:21 (外部編集)