Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
d47f0664
Commit
d47f0664
authored
Mar 02, 2021
by
nuxer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DBMS single init
parent
d0ce9280
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
312 additions
and
0 deletions
+312
-0
README.md
DBMS/DOCKER/README.md
+312
-0
No files found.
DBMS/DOCKER/README.md
0 → 100644
View file @
d47f0664
[
![logo
](
https://www.hongsnet.net/images/logo.gif
)
](https://www.hongsnet.net)
# MariaDB의 Dockerize 구성
> 기존 KVM 가상머신 기반의 DBMS를 Docker 기반으로 변경하여 운용한다. 단, Back-End 시스템만 컨테이너 오케스트레이션 구성을 적용하고, DBMS는 단독 Docker 기반으로 구성한다.
# Docker 이미지 Build
*
[
]
Dockerfile을 이용한 Image Build
*
[
]
Build된 이미지의 Container Registry 등록
*
[
]
docker-compose를 이용한 컨테이너 실행
*
[
]
Portainer를 이용한 관리
## Dockerfile을 이용한 Image Build
```
bash
# cat Dockerfile
FROM registry.hongsnet.net/joohan.hong/docker/centos:7.6.1810
MAINTAINER Hongs <master@hongsnet.net>
#TIME ZONE 설정
ENV
TZ
=
Asia/Seoul
RUN
ln
-snf
/usr/share/zoneinfo/
$TZ
/etc/localtime
&&
echo
$TZ
>
/etc/timezone
&&
\
yum
-y
install
epel-release
#한글 지원
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
COPY CONFIG/MariaDB.repo /etc/yum.repos.d/MariaDB.repo
COPY CONFIG/bashrc /root/.bashrc
COPY CONFIG/my.cnf /etc/my.cnf
#RUN yum update
RUN yum
-y
install
glibc glibc-common openssl-devel net-tools vi vim iproute wget bind-utils pwgen psmisc
hostname
openssh-server openssh-clients MariaDB MariaDB-server MariaDB-client MariaDB-backup cronie crontabs supervisor
RUN
ln
-s
/usr/bin/resolveip /usr/libexec/resolveip
COPY CONFIG/supervisord.conf /etc/supervisor/supervisord.conf
COPY CONFIG/mysql.conf /etc/supervisor/conf.d/mysql.conf
COPY CONFIG/mariadb_start.sh /
RUN
chmod
700 /mariadb_start.sh
RUN
chown
mysql.mysql /mariadb_start.sh
EXPOSE 3306
CMD
[
"/usr/bin/supervisord"
,
"-c"
,
"/etc/supervisor/supervisord.conf"
]
```
## DBMS Docker Image 적용 내역
-
CentOS 7
-
MariaDB 10.3
-
supervisord
## MariaDB 10.3 설정 내역
CentOS 7 YUM 내부 Repository
```
bash
# cat CONFIG/MariaDB.repo
[
mariadb]
name
=
MariaDB
baseurl
=
http://yum.hongsnet.net:8889/mariadb/centos7/10.3/
$basearch
gpgcheck
=
0
```
my.cnf 설정내역은 다음과 같다.
```
bash
# cat CONFIG/my.cnf
#
[
client]
port
=
3306
socket
=
/var/lib/mysql/mysql.sock
[
mysqld_safe]
socket
=
/var/lib/mysql/mysql.sock
nice
=
0
[
mysqld]
log-error
=
/var/lib/mysql/mysql.err
init_connect
=
'SET collation_connection = utf8_unicode_ci'
init_connect
=
'SET NAMES utf8'
character-set-server
=
utf8
collation-server
=
utf8_unicode_ci
skip-character-set-client-handshake
default-storage-engine
=
InnoDB
max_allowed_packet
=
1024M
net_read_timeout
=
120
net_write_timeout
=
120
#wait_timeout=86400
wait_timeout
=
30
user
=
mysql
port
=
3306
basedir
=
/usr
datadir
=
/var/lib/mysql
tmpdir
=
/tmp
skip-external-locking
skip-name-resolve
key_buffer_size
=
64M
max_allowed_packet
=
1024M
thread_stack
=
192K
thread_cache_size
=
256
max_connections
=
4096
table_cache
=
1024
tmp_table_size
=
32M
max_heap_table_size
=
32M
query_cache_size
=
128M
query_cache_type
=
1
sort_buffer_size
=
256K
read_buffer_size
=
256K
read_rnd_buffer_size
=
512K
long_query_time
=
2
server-id
=
250
log_bin
=
mysql-bin
expire_logs_days
=
3
max_binlog_size
=
1024M
innodb_buffer_pool_size
=
4096M
innodb_flush_log_at_trx_commit
=
0
innodb_lock_wait_timeout
=
50
innodb_thread_concurrency
=
8
innodb_log_buffer_size
=
8M
innodb_log_file_size
=
64M
innodb_log_files_in_group
=
2
innodb_file_per_table
=
1
[
mysqldump]
quick
quote-names
max_allowed_packet
=
1024M
[
mysql]
max_allowed_packet
=
1024M
[
isamchk]
key_buffer_size
=
16M
[
client-server]
```
MariaDB의 Supervisord 설정은 다음과 같다.
```
bash
# cat CONFIG/mysql.conf
[
program:nginx]
command
=
/mariadb_start.sh
user
=
mysql
[
program:crond]
command
=
/usr/sbin/crond
-n
user
=
root
```
MariaDB의 시작 스크립트는 다음과 같다.
```
bash
# cat CONFIG/mariadb_start.sh
#!/bin/bash
MYSQL_ROOT_PASSWORD
=
"패스워드"
if
[
!
-d
/var/lib/mysql/mysql
]
;
then
echo
-ne
"Populating DataDir ... "
mysql_install_db
--user
=
mysql
echo
"Done"
fi
if
[
!
-f
/etc/my.cnf
]
;
then
echo
-ne
"Populating ConfDir ... "
cp
/my.cnf /etc/my.cnf
chown
-R
mysql:mysql /etc/my.cnf
echo
"Done"
fi
if
[[
-z
${
MYSQL_ROOT_PASSWORD
}
]]
;
then
MYSQL_ROOT_PASSWORD
=
$(
pwgen
-s
-1
12
)
echo
"Your Root password is :
${
MYSQL_ROOT_PASSWORD
}
"
fi
chown
mysql.mysql /etc/my.cnf
chown
-R
mysql.mysql /var/lib/mysql
echo
"Starintg MariaDB ..."
tail
-f
/var/lib/mysql/mysql.err &
/usr/bin/mysqld_safe
```
> 이 스크립트는 MaraiDB 기동 시 권한을 조정한 후 실행하는 것이 핵심인 init 스크립트 이다.
## Docker Image Build 및 Container Registry Push
```
bash
# docker build --rm -t centos7.6-mariadb10.3 .
```
위와 같이 Build가 수행한 후 정상적으로 완료되면, 다음과 같이 Docker Image가 생성된다.
```
bash
# docker images |grep centos7.6-mariadb
centos7.6-mariadb10.3 latest 408af11faf06 6 weeks ago 956MB
```
내부 Container Registry는 GitLAB에서 제공하는 기능을 사용한다. 다음과 같이 스크립트를 작성하여, PUSH 한다.
```
bash
# cat docker-image-push.sh
#!/bin/bash
DATE
=
"20201016"
docker login
-u
juhanida21@nate.com
-p
PRIVATE_KEY registry.hongsnet.net
/usr/bin/docker tag centos7.6-mariadb10.3:latest registry.hongsnet.net/joohan.hong/docker/mariadb:centos7-10.3_
$DATE
/usr/bin/docker push registry.hongsnet.net/joohan.hong/docker/mariadb:centos7-10.3_
$DATE
if
[[
`
docker images
-f
"dangling=true"
-q
`
!=
""
]]
;
then
docker rmi
$(
docker images
-f
"dangling=true"
-q
)
;
fi
```
!참고 : 최종적으로 PUSH 되는 Image의 TAG는
`$DATE`
-> YYYYMMDD 이다.
## docker-compose를 이용한 컨테이너 실행
```
python
# cat docker-compose.yml
version
:
'3'
services
:
centos76
-
mariadb103
:
image
:
registry
.
hongsnet
.
net
/
joohan
.
hong
/
docker
/
mariadb
:
centos7
-
10.3_20210116
#image: centos7.6-mariadb10.3-hongsnet
restart
:
always
hostname
:
'centos7-mariadb103'
container_name
:
centos7
.6
-
mariadb10
.3
environment
:
-
MYSQL_ROOT_PASSWORD
=
패스워드
volumes
:
-
"/var/lib/libvirt/MYSQL/etc:/etc"
-
"/var/lib/libvirt/MYSQL/mysql_data:/var/lib/mysql"
-
"/var/lib/libvirt/MYSQL/BACKUP:/BACKUP"
-
"/var/lib/libvirt/NFS:/NFS"
ports
:
-
"3306:3306"
extra_hosts
:
-
"localhost:127.0.0.1"
-
"centos7-mariadb103:127.0.0.1"
```
docker-compose 명령을 통해 다음과 같이 실행한다.
```
bash
# docker-compose up -d
```
**!참고**
: portainer의 docker-compose.yml 내역
```
bash
# cat docker-compose.yml
version:
'3'
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: always
ports:
- 9000:9000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /DOCKERS/portainer/data:/data
```
최종적으로 컨테이너의 실행 상태는 다음과 같다.
```
bash
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcf2a1815dc0 registry.hongsnet.net/joohan.hong/docker/mariadb:centos7-10.3_20210116
"/usr/bin/supervisor…"
3 weeks ago Up 3 weeks 0.0.0.0:3306->3306/tcp centos7.6-mariadb10.3
c87da9710121 portainer/portainer-ce:latest
"/portainer"
3 weeks ago Up 3 weeks 8000/tcp, 0.0.0.0:9000->9000/tcp portainer
```
## Portainer를 이용한 관리
> 접속주소 : https://port250.hongsnet.net
![
port1
](
uploads/189225f8b06540b3d396f501b2302c66/port1.png
)
![
port2
](
uploads/0ef602c4a293cc155b56e97be09c33af/port2.png
)
![
port3
](
uploads/2a6d0aa9919c97d997f3158ffa5edbb7/port3.png
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment