第二十六章 Centos7下Docker安装Mariadb(Chapter XXVI installation of docker and MariaDB under centos7)

一、查找Mariadb镜像

[root@staging ~]# docker search  mariadb:10.0.26

二、拉取Mariadb镜像

[root@staging ~]# docker pull mariadb:10.0.26

三、运行Mariadb

[root@staging ~]# docker run \
 -itd  \
 -p 13306:3306 \
 -v /data2/mariadb/conf:/etc/mysql/conf.d \
 -v /data2/mariadb/data:/var/lib/mysql \
 -v /data2/mariadb/log:/var/log/mysql \
 -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
 -e MYSQL_ROOT_PASSWORD=123456 \
 --restart always \
 --privileged=true \
 --name mariadb \
 mariadb:10.0.26

四、验证Mariadb容器

[root@staging data2]# docker ps |grep mariadb
8f71d895b3f1   mariadb:10.0.26       "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes           0.0.0.0:13306->3306/tcp, :::13306->3306/tcp

五、配置Mariadb

[root@staging ~]# cd /data2/mariadb/conf/
[root@staging conf]# cat client.cnf 
#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#

[client]
# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
[root@staging conf]# cat mysql-clients.cnf 
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#

[mysql]
[mysql_upgrade]
[mysqladmin]
[mysqlbinlog]
[mysqlcheck]
[mysqldump]
[mysqlimport]
[mysqlshow]
[mysqlslap
[root@staging conf]# cat tokudb.cnf 
[mariadb]
# See https://mariadb.com/kb/en/how-to-enable-tokudb-in-mariadb/
# for instructions how to enable TokuDB
#
# See https://mariadb.com/kb/en/tokudb-differences/ for differences
# between TokuDB in MariaDB and TokuDB from http://www.tokutek.com/

#plugin-load-add=ha_tokudb.so
[root@staging conf]# cat server.cnf 
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

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

# this is only for the mysqld standalone daemon
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character_set_server=utf8
slow_query_log=on
slow_query_log_file=/var/log/mysql/slow_query_log.log
long_query_time=2
explicit_defaults_for_timestamp = 1
innodb_large_prefix=on
max_connections=3000
innodb_file_format = BARRACUDA
# this is only for embedded server
[embedded]

# This group is 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]

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

六、重启Mariadb

#1.重启MySQL
[root@staging conf]# docker  restart  mariadb
mariadb

#2.查看MySQL日志,发现MySQL正常启动,日志时间也与系统时间保持一致
[root@staging ~]# docker logs -f  mariadb
220112 15:01:55 [Note] Server socket created on IP: '::'.
220112 15:01:55 [Warning] 'proxies_priv' entry '@% root@cf6ad44a4433' ignored in --skip-name-resolve mode.
220112 15:01:55 [Note] mysqld: ready for connections.
Version: '10.0.26-MariaDB-1~jessie'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  mariadb.org binary distribution
————————

一、查找Mariadb镜像

[root@staging ~]# docker search  mariadb:10.0.26

二、拉取Mariadb镜像

[root@staging ~]# docker pull mariadb:10.0.26

三、运行Mariadb

[root@staging ~]# docker run \
 -itd  \
 -p 13306:3306 \
 -v /data2/mariadb/conf:/etc/mysql/conf.d \
 -v /data2/mariadb/data:/var/lib/mysql \
 -v /data2/mariadb/log:/var/log/mysql \
 -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
 -e MYSQL_ROOT_PASSWORD=123456 \
 --restart always \
 --privileged=true \
 --name mariadb \
 mariadb:10.0.26

四、验证Mariadb容器

[root@staging data2]# docker ps |grep mariadb
8f71d895b3f1   mariadb:10.0.26       "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes           0.0.0.0:13306->3306/tcp, :::13306->3306/tcp

五、配置Mariadb

[root@staging ~]# cd /data2/mariadb/conf/
[root@staging conf]# cat client.cnf 
#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#

[client]
# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
[root@staging conf]# cat mysql-clients.cnf 
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#

[mysql]
[mysql_upgrade]
[mysqladmin]
[mysqlbinlog]
[mysqlcheck]
[mysqldump]
[mysqlimport]
[mysqlshow]
[mysqlslap
[root@staging conf]# cat tokudb.cnf 
[mariadb]
# See https://mariadb.com/kb/en/how-to-enable-tokudb-in-mariadb/
# for instructions how to enable TokuDB
#
# See https://mariadb.com/kb/en/tokudb-differences/ for differences
# between TokuDB in MariaDB and TokuDB from http://www.tokutek.com/

#plugin-load-add=ha_tokudb.so
[root@staging conf]# cat server.cnf 
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

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

# this is only for the mysqld standalone daemon
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character_set_server=utf8
slow_query_log=on
slow_query_log_file=/var/log/mysql/slow_query_log.log
long_query_time=2
explicit_defaults_for_timestamp = 1
innodb_large_prefix=on
max_connections=3000
innodb_file_format = BARRACUDA
# this is only for embedded server
[embedded]

# This group is 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]

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

六、重启Mariadb

#1.重启MySQL
[root@staging conf]# docker  restart  mariadb
mariadb

#2.查看MySQL日志,发现MySQL正常启动,日志时间也与系统时间保持一致
[root@staging ~]# docker logs -f  mariadb
220112 15:01:55 [Note] Server socket created on IP: '::'.
220112 15:01:55 [Warning] 'proxies_priv' entry '@% root@cf6ad44a4433' ignored in --skip-name-resolve mode.
220112 15:01:55 [Note] mysqld: ready for connections.
Version: '10.0.26-MariaDB-1~jessie'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  mariadb.org binary distribution