mariadb容器安装部署

拉取基础镜像:
[root@node2 mariadb]# docker pull mariadb

使用基础镜像创建容器:
[root@node2 mariadb]# docker run -d --name mariadb -v /etc/localtime:/etc/localtime:ro -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 --restart=always mariadb:1.0
a27867510c64da40d7a80331b39fa614175213a02daf2a05eab5851b535e40a6

拷贝容器的my.cnf到/data/mariadb/conf目录下:
[root@node2 mariadb]# docker cp a27867510c64:/etc/mysql/my.cnf conf/

进入容器,删除my.cnf配置文件:
[root@node2 mariadb]# docker exec -it a27 /bin/bash
[root@a27867510c64:/# rm /etc/mysql/my.cnf


再次开启另外一个窗口,把容器封装成镜像:
[root@node2 mariadb]#docker commit a27867510c64 mariadb:2.0


删除之前创建的镜像,使用新的镜像创建容器:
[root@node2 mariadb]#docker run -d --name mariadb -v /etc/localtime:/etc/localtime:ro \
-v /data/mariadb/data:/var/lib/mysql \
-v /data/mariadb/conf/my.cnf:/etc/mysql/my.cnf \
-v /data/mariadb/bin-log:/opt \
-e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 --restart=always mariadb:2.0

把新创建的镜像上传到harbor(192.168.2.141)中:
[root@node2 mariadb]# docker login 192.168.2.141
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

查看当前的镜像:
[root@node2 mariadb]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb 2.0 afe5d9c91a5f 12 minutes ago 363MB
mariadb 1.0 199cc294e316 5 days ago 363MB
192.168.1.150/frp/frp 1.0 dc20d57a38fd 2 weeks ago 20.5MB
nginx 1.0 be455741af4b 4 weeks ago 107MB
192.168.2.141/mysql/mysql_base 3.0 d9a63f521233 4 weeks ago 372MB
mysql_base 3.0 d9a63f521233 4 weeks ago 372MB
prom/prometheus latest 0915a968017e 2 months ago 119MB
hyperapp/frp latest 24f93938c62c 2 months ago 20.4MB
vmware/registry-photon v2.6.2-v1.4.0 8920f621ddd1 7 months ago 198MB
vmware/nginx-photon v1.4.0 20c8a01ac6ab 7 months ago 135MB
vmware/harbor-log v1.4.0 9e818c7a27ab 7 months ago 200MB
vmware/harbor-jobservice v1.4.0 29c14d91b043 7 months ago 191MB
vmware/harbor-ui v1.4.0 6cb4318eda6a 7 months ago 209MB
vmware/harbor-adminserver v1.4.0 8145970fa013 7 months ago 182MB
vmware/harbor-db v1.4.0 c38da34727f0 7 months ago 521MB

[root@node2 mariadb]# docker tag afe5d9c91a5f 192.168.2.141/mariadb/mariadb:2.0

推送镜像到harbor:
[root@node2 mariadb]# docker push 192.168.2.141/mariadb/mariadb:2.0
The push refers to repository [192.168.2.141/mariadb/mariadb]
4be3068b7f27: Pushed
72b5bdabe22d: Pushed
de7942c83091: Pushed
29c5d51c9813: Pushed
27bc198b99d7: Pushed
20267b2cbb6f: Pushed
febbbb557a99: Pushed
f7b4db57c16a: Pushed
470f8b79cb02: Pushed
6505a7752b85: Pushed
b89366174e09: Pushed
8d7ea83e3c62: Pushed
6a061ee02432: Pushed
f73b2816c52a: Pushed
6267b420796f: Pushed
a30b835850bf: Pushed
2.0: digest: sha256:cb8d8e28ecfba8b9844c7bbb156b4a3bb9e4103eb2d6e392020cf5f9954f9f1f size: 3654

退出:
docker logout 192.168.2.141

拉取harbor上的镜像:
[root@node2 mariadb]# docker stop mariadb
mariadb
[root@node2 mariadb]# docker rm mariadb
mariadb

删除之前的数据:
[root@node2 mariadb]# rm -rf data/*

再次重新创建容器:
[root@node2 mariadb]#docker run -d --name mariadb -v /etc/localtime:/etc/localtime:ro \
-v /data/mariadb/data:/var/lib/mysql \
-v /data/mariadb/conf/my.cnf:/etc/mysql/my.cnf \
-v /data/mariadb/bin-log:/opt \
-e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 --restart=always 192.168.2.141/mariadb/mariadb:2.0

查看:
[root@node2 mariadb]# docker ps |grep mariadb
42007b4e26d4 192.168.2.141/mariadb/mariadb:2.0 "docker-entrypoint.s…" 25 seconds ago Up 22 seconds 0.0.0.0:3307->3306/tcp

修改my.cnf配置文件内容:
[root@node2 mariadb]# cat conf/my.cnf
# MariaDB database server configuration file.
#
# You can copy this file to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set=utf8


# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
#
# * Basic Settings
#
#user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
skip-external-locking
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=2000
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
connect_timeout = 5
wait_timeout = 600
max_allowed_packet = 16M
thread_cache_size = 128
sort_buffer_size = 4M
bulk_insert_buffer_size = 16M
tmp_table_size = 32M
max_heap_table_size = 32M
collation-server = utf8_unicode_ci
init-connect=’SET NAMES utf8’
character-set-server = utf8
#
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover_options = BACKUP
key_buffer_size = 128M
#open-files-limit = 2000
table_open_cache = 400
myisam_sort_buffer_size = 512M
concurrent_insert = 2
read_buffer_size = 2M
read_rnd_buffer_size = 1M
#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit = 128K
query_cache_size = 64M
# for more write intensive setups, set to DEMAND or OFF
#query_cache_type = DEMAND
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# we do want to know about network errors and such
#log_warnings = 2
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log[={0|1}]
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit = 1000
#log_slow_verbosity = query_plan

#log-queries-not-using-indexes
#log_slow_admin_statements
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#report_host = master1
#auto_increment_increment = 2
#auto_increment_offset = 1
#log_bin = /var/log/mysql/mariadb-bin
#log_bin_index = /var/log/mysql/mariadb-bin.index
# not fab for performance, but safer
#sync_binlog = 1
expire_logs_days = 10
max_binlog_size = 100M
# slaves
#relay_log = /var/log/mysql/relay-bin
#relay_log_index = /var/log/mysql/relay-bin.index
#relay_log_info_file = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only
#
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
default_storage_engine = InnoDB
# you can't just change log file size, requires special procedure
#innodb_log_file_size = 50M
innodb_buffer_pool_size = 256M
innodb_log_buffer_size = 8M
innodb_file_per_table = 1
innodb_open_files = 400
innodb_io_capacity = 400
innodb_flush_method = O_DIRECT
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completion

[isamchk]
key_buffer = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!include /etc/mysql/mariadb.cnf
!includedir /etc/mysql/conf.d/

重启容器:
docker restart mariadb

进入容器查看字符集:
[root@node2 mariadb]# docker exec -it 5a3 /bin/bash

[root@5a3cd2e5691d:/# mysql -uroot -p ##密码为123456
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.9-MariaDB-1:10.3.9+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \s
--------------
mysql Ver 15.1 Distrib 10.3.9-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.3.9-MariaDB-1:10.3.9+maria~bionic mariadb.org binary distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 35 sec

Threads: 7 Questions: 4 Slow queries: 0 Opens: 17 Flush tables: 1 Open tables: 11 Queries per second avg: 0.114

posted @ 2018-09-11 10:11  求其在我  阅读(521)  评论(0)    收藏  举报