ここからはDocker上のコンテナに対して実施していきます

なので基本的にはコンテナ上でのコマンドです

 

1.Dockerのコンテナを起動し接続する

# docker run --name db --hostname db -id -t docker.io/centos /bin/bash
# docker exec -it db /bin/bash

2.yum によるインストール(MySQL / MongoDB)

MySQL5.7をインストールしたいのでリポジトリを追加
# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# yum install mysql mysql-server
MongoDBをインストールしたいのでリポジトリを追加します
# vi /etc/yum.repos.d/mongodb-org-3.4.repo 

[mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

# yum install mongodb-org

4.MySQL 設定

systemctl を利用できる状態で起動させる。
初期パスワードはログに出力されているのでそれを利用する
パスワード関連でいろいろ怒られるのでvalidate_password
Dockerコンテナからの
# docker stop db
# docker commit db pug_docker/db
# docker run --name db --hostname db -p 3306:3306 -id -t --privileged pug_docker/db /sbin/init
# systemctl enable mysqld
# systemctl start mysqld
# vi /etc/my.cnf

character_set_server=utf8 skip-character-set-client-handshake

# cat /var/log/mysqld.log | grep "temporary password" 2017-12-05T14:02:42.368471Z 1 [Note] A temporary password is generated for root@localhost: ******
# mysql -u root -p
mysql> uninstall plugin validate_password;
mysql> set password for root@localhost=password('*********');


DBコンテナに接続してWordPress向けの設定をします
接続元はコンテナのIPレンジとローカルネットのIPレンジを指定しておきます
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"172.17.%" IDENTIFIED BY "********";
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"192.168.0.%" IDENTIFIED BY "********"; Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "********"; Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> EXIT

# ホストのCentOSからリモート接続してみる
# mysql -u wordpress -p -h 172.17.0.3 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Zabbix向け設定 
https://www.zabbix.com/documentation/3.4/manual/appendix/install/db_scripts#mysql
# mysql -uroot -p<password>
> create database zabbix character set utf8 collate utf8_bin;
> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
> grant all privileges on zabbix.* to "zabbix"@"172.17.%" identified by '<password>';
> grant all privileges on zabbix.* to "zabbix"@"192.168.0.%" identified by '<password>';
> FLUSH PRIVILEGES;


JIRA向け設定
# mysql -uroot -p<password>
> create database jira default character set utf8;
> grant all privileges on jira.* to jira@localhost identified by '<password>';
> grant all privileges on jira.* to "jira"@"172.17.%" identified by '<password>';
> grant all privileges on jira.* to "jira"@"192.168.0.%" identified by '<password>';
> FLUSH PRIVILEGES;

Redmine向け設定
# mysql -uroot -p<password>
> CREATE DATABASE redmine CHARACTER SET utf8mb4;
> grant all privileges on redmine .* to redmine @localhost identified by '<password>';
> grant all privileges on redmine .* to "redmine "@"172.17.%" identified by '<password>';
> grant all privileges on redmine .* to "redmine "@"192.168.0.%" identified by '<password>';
> FLUSH PRIVILEGES;

5.MongoDB 設定

未執筆
# 未執筆
# 


5.イメージの保存


# docker stop db
# docker commit db pug_docker/db
# docker run  -v /conteiner_share:/conteiner_share --net=mynetwork --name db --hostname db -p 3306:3306 -id -t --privileged pug_docker/db /sbin/init -e "TZ=Asia/Tokyo"