主にLinuxサーバー設定記録をメモします

CentOSで5.5系をインストールする

 # rpm -ivh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
 # rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
 # yum --enablerepo=remi install mysql mysql-server

mysql-community-serverをインストールする

# yum install -y http://repo.mysql.com/mysql-community-release-el6-...
Loaded plugins: fastestmirror, security
Determining fastest mirrors
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Setting up Install Process
mysql-community-release-el6-5.noarch.rpm                 | 5.7 kB     00:00
Examining /var/tmp/yum-root-r6jh9l/mysql-community-release-el6-5.noarch.rpm: mysql-community-release-el6-5.noarch
Marking /var/tmp/yum-root-r6jh9l/mysql-community-release-el6-5.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-release.noarch 0:el6-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package               Arch   Version
                                    Repository                             Size
================================================================================
Installing:
 mysql-community-release
                       noarch el6-5 /mysql-community-release-el6-5.noarch 4.3 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total size: 4.3 k
Installed size: 4.3 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-release-el6-5.noarch                         1/1
  Verifying  : mysql-community-release-el6-5.noarch                         1/1

Installed:
  mysql-community-release.noarch 0:el6-5

Complete!
# yum install -y mysql-community-server
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
mysql-connectors-community                               | 2.5 kB     00:00
mysql-connectors-community/primary_db                    | 6.2 kB     00:00
mysql-tools-community                                    | 2.5 kB     00:00
mysql-tools-community/primary_db                         |  13 kB     00:00
mysql56-community                                        | 2.5 kB     00:00
mysql56-community/primary_db                             |  40 kB     00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.6.19-2.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.6.19-2.el6 for package: mysql-community-server-5.6.19-2.el6.x86_64
--> Processing Dependency: mysql-community-client(x86-64) = 5.6.19-2.el6 for package: mysql-community-server-5.6.19-2.el6.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.19-2.el6.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.6.19-2.el6 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.19-2.el6 for package: mysql-community-client-5.6.19-2.el6.x86_64
---> Package mysql-community-common.x86_64 0:5.6.19-2.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.6.19-2.el6 will be obsoleting
---> Package mysql-libs.x86_64 0:5.1.73-3.el6_5 will be obsoleted
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.6.19-2.el6 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                      Arch    Version          Repository          Size
================================================================================
Installing:
 mysql-community-libs         x86_64  5.6.19-2.el6     mysql56-community  1.9 M
     replacing  mysql-libs.x86_64 5.1.73-3.el6_5
 mysql-community-libs-compat  x86_64  5.6.19-2.el6     mysql56-community  1.6 M
     replacing  mysql-libs.x86_64 5.1.73-3.el6_5
 mysql-community-server       x86_64  5.6.19-2.el6     mysql56-community   52 M
Installing for dependencies:
 mysql-community-client       x86_64  5.6.19-2.el6     mysql56-community   18 M
 mysql-community-common       x86_64  5.6.19-2.el6     mysql56-community  298 k
 perl-DBI                     x86_64  1.609-4.el6      base               705 k

Transaction Summary
================================================================================
Install       6 Package(s)

Total download size: 74 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): mysql-community-client-5.6.19-2.el6.x86_64.rpm    |  18 MB     00:02
(2/6): mysql-community-common-5.6.19-2.el6.x86_64.rpm    | 298 kB     00:00
(3/6): mysql-community-libs-5.6.19-2.el6.x86_64.rpm      | 1.9 MB     00:00
(4/6): mysql-community-libs-compat-5.6.19-2.el6.x86_64.r | 1.6 MB     00:00
(5/6): mysql-community-server-5.6.19-2.el6.x86_64.rpm    |  52 MB     00:06
(6/6): perl-DBI-1.609-4.el6.x86_64.rpm                   | 705 kB     00:00
--------------------------------------------------------------------------------
Total                                           7.1 MB/s |  74 MB     00:10
警告: rpmts_HdrFromFdno: V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
 Package: mysql-community-release-el6-5.noarch (@/mysql-community-release-el6-5.noarch)
 From   : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-community-common-5.6.19-2.el6.x86_64                   1/7
  Installing : mysql-community-libs-5.6.19-2.el6.x86_64                     2/7
  Installing : mysql-community-client-5.6.19-2.el6.x86_64                   3/7
  Installing : perl-DBI-1.609-4.el6.x86_64                                  4/7
  Installing : mysql-community-server-5.6.19-2.el6.x86_64                   5/7
  Installing : mysql-community-libs-compat-5.6.19-2.el6.x86_64              6/7
  Erasing    : mysql-libs-5.1.73-3.el6_5.x86_64                             7/7
  Verifying  : mysql-community-server-5.6.19-2.el6.x86_64                   1/7
  Verifying  : mysql-community-libs-compat-5.6.19-2.el6.x86_64              2/7
  Verifying  : perl-DBI-1.609-4.el6.x86_64                                  3/7
  Verifying  : mysql-community-common-5.6.19-2.el6.x86_64                   4/7
  Verifying  : mysql-community-libs-5.6.19-2.el6.x86_64                     5/7
  Verifying  : mysql-community-client-5.6.19-2.el6.x86_64                   6/7
  Verifying  : mysql-libs-5.1.73-3.el6_5.x86_64                             7/7

Installed:
  mysql-community-libs.x86_64 0:5.6.19-2.el6
  mysql-community-libs-compat.x86_64 0:5.6.19-2.el6
  mysql-community-server.x86_64 0:5.6.19-2.el6

Dependency Installed:
  mysql-community-client.x86_64 0:5.6.19-2.el6
  mysql-community-common.x86_64 0:5.6.19-2.el6
  perl-DBI.x86_64 0:1.609-4.el6

Replaced:
  mysql-libs.x86_64 0:5.1.73-3.el6_5

Complete!

初期設定

# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8 ← 追加(MySQLサーバーの文字コードをUTF-8にする)
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.

Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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] 
 ... 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] 
 ... Success!

By default, MySQL 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] 
 - 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] 
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't existが出力された場合

MySQL データを初期化し、システムテーブルを作成する
# mysql_install_db

レプリケーション設定

マスター(192.168.0.9)とスレイブ(192.168.0.10)間でレプリケーションを行う
マスター側にスレイブからアクセスできるユーザーを作成する
mysql> grant replication slave on *.* to 'repl'@'192.168.0.10' identified by 'xxxxxxxx';
マスター側のmy.cnfに設定を追加する
# vi /etc/my.cnf
[mysqld]
log-bin = mysql-bin
server-id = 101
# /etc/init.d/mysqld restart
スレイブ側のmy.cnfに設定を追加する
# vi /etc/my.cnf
[mysqld]
server-id = 102
# /etc/init.d/mysqld restart
確認用データベースとテーブルデータの作成(マスター側)
mysql> create database repltest;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| repltest           |
+--------------------+
4 rows in set (0.00 sec)

mysql> connect repltest;
Connection id:    3
Current database: repltest

mysql> create table test(id int(8),title varchar(32));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into test values(1,'test');
Query OK, 1 row affected (0.01 sec)

mysql> insert into test values(2,'cloudstack.jp');
Query OK, 1 row affected (0.01 sec)

mysql> select * from test;
+------+---------------+
| id   | title         |
+------+---------------+
|    1 | test          |
|    2 | cloudstack.jp |
+------+---------------+
2 rows in set (0.00 sec)
マスター側の位置情報を取得する
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      829 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
マスター側のDBダンプを取得する
# mysqldump --events -uroot -p --add-drop-database --all-databases --lock-all-tables --flush-privileges > 101_dump.sql
DBダンプをスレイブ側にコピーする
# scp 101_dump.sql root@192.168.0.10:/root
スレイブ側のDBを確認する(インポート前)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
スレイブ側にDBをインポートする
# mysql -u root -p < 101_dump.sql
スレイブ側のDBを確認する(インポート後)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| repltest           |
+--------------------+
4 rows in set (0.00 sec)

mysql> use repltest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------+
| Tables_in_repltest |
+--------------------+
| test               |
+--------------------+
1 row in set (0.00 sec)

mysql> select * from test;
+------+---------------+
| id   | title         |
+------+---------------+
|    1 | test          |
|    2 | cloudstack.jp |
+------+---------------+
2 rows in set (0.00 sec)
マスター側の情報を登録(スレイブ側)
マスター側で取得した位置情報(ポジション)を利用する
mysql> change master to master_host='192.168.0.9',master_user='repl',master_password='xxxxxxxx',master_log_file='mysql-bin.000001',master_log_pos=829;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
マスター側を更新してみる
mysql> insert into test values(3,'Replication Start!');
Query OK, 1 row affected (0.01 sec)

mysql> select * from test;
+------+-------------------+
| id   | title             |
+------+-------------------+
|    1 | test              |
|    2 | cloudstack.jp     |
|    3 | Hello CloudStack! |
+------+-------------------+
3 rows in set (0.00 sec)
スレイブ側で更新を確認する
mysql> use repltest
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+-------------------+
| id   | title             |
+------+-------------------+
|    1 | test              |
|    2 | cloudstack.jp     |
|    3 | Hello CloudStack! |
+------+-------------------+
3 rows in set (0.00 sec)
スレイブ情報を確認する
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.0.9
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 1701
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 358
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1701
              Relay_Log_Space: 532
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 101
                  Master_UUID: 43581662-0723-11e4-b6bc-080027860fad
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

Menu

メニュー

アプリケーション

アプリケーション

その他

【メニュー編集】

管理人/副管理人のみ編集できます