Commit 5b2bd7ec authored by snkisuke's avatar snkisuke

Initial commit

parents
.env
mysql/data/
mysql/backups/
mysql/custom.cnf
mysql-slave/data/
mysql-slave/backups/
mysql-slave/custom.cnf
\ No newline at end of file
This diff is collapsed.
# MariaDB Replicated
## Steps
### On master
Copy or move mysql/config/custom.cnf (You can add custome configs for mysql in this file)
```bash
cp mysql/custom.cnf.exmaple mysql/config/custom.cnf
```
Start db container
```bash
docker-compose -f docker-compose-master.yml up -d
```
```bash
sudo docker-compose exec db sh -c "printf \"create user 'replicant'@'%%' identified by 'password';\ngrant replication slave on *.* to replicant;\nflush privileges;\nshow master status;\" | mysql -uroot -p\${MYSQL_ROOT_PASSWORD} \${MYSQL_DATABASE}"
```
### On slaves
```bash
cp mysql-slave/custom.cnf.exmaple mysql-slave/config/custom.cnf
```
```bash
sudo docker-compose exec db-slave sh -c "printf \"change master 'db' to master_host='db', master_user='replicant', master_password='password', master_port=3306, master_log_file='master-bin.000001', master_log_pos=62307428, master_connect_retry=10, master_use_gtid=slave_pos;\" | mysql -uroot -p\${MYSQL_ROOT_PASSWORD} \${MYSQL_DATABASE}"
```
Start db-slave container
```bash
docker-compose -f docker-compose-slave.yml up -d
```
### Notes:
- db is the name of master host
- change `"FILL_ME"` on `mysql/config/custom.cnf` and `mysql-slave/config/custom.cnf` with the name of the database that you need replicated
- change password
- replicant is the name of the replicator user
- master_log_file is a essential requirement and is the output of `show master status;` on master
- If you need up both master and slaver run `docker-compose -f docker-compose-master.yml -f docker-compose-slave.yml up -d`
\ No newline at end of file
version: '3'
services:
db:
image: mariadb
environment:
HOSTNAME: db
MYSQL_DATABASE:
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD:
MYSQL_USER:
restart: unless-stopped
volumes:
- ./mysql/data:/var/lib/mysql:rw
- ./mysql/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro
ports:
- 3306
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: unless-stopped
environment:
PMA_HOST: db
ports:
- 8080:80
version: '3'
services:
db-slave:
image: mariadb
environment:
MYSQL_DATABASE:
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD:
MYSQL_USER:
restart: unless-stopped
volumes:
- ./mysql-slave/data:/var/lib/mysql:rw
- ./mysql-slave/custom.cnf:/etc/mysql/conf.d/custom.cnf:ro
ports:
- 3306
MYSQL_DATABASE=redmine
MYSQL_PASSWORD=secret
MYSQL_ROOT_PASSWORD=supersecret
MYSQL_USER=redmine
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
log-bin=/var/log/mysql/slave-bin
log-bin-index=/var/log/mysql/slave-bin.index
binlog_format=mixed
server-id=02
replicate-do-db=FILL_ME
relay-log-index=/var/log/mysql/slave-relay-bin.index
relay-log=/var/log/mysql/slave-relay-bin
\ No newline at end of file
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
log-bin=/var/log/mysql/master-bin
log-bin-index=/var/log/mysql/master-bin.index
binlog_format=mixed
server-id=01
replicate-do-db=FILL_ME
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment