관리 메뉴

ふたりで

centos7+docker+linux+mariadb setup&config 본문

centos7 & rocky9

centos7+docker+linux+mariadb setup&config

graykang 2022. 8. 25. 16:17
728x90
반응형
SMALL

1. 오라클 VirtualBOX에 centos7을 먼저 설치 한다. 해당 작업은 docker전용서버를 생성 하는 과정이며,

관련한 내용은 생략한다...너무 쉬워서? ㅎㅎ

VirtualBOX 환경일경우 중요하건 아래 그림처럼 포트포워딩 부분이다.

주) 호스트IP는 VirtualBOX+centos7이고,

      게스트IP는 본인의 local PC(VirtualBOX가 설치되면 생성되는 네트웍카드의 IP)이다.

 

2. centos7 update  하기.

  VirtualBOX에 설치한 centos7의 yum update를 하여 최신버전으로 업데이트 한다.

[root@localhost /]# yum -y update

2-1. docker 레파지도리추가.

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3. docker 설치하기~

  VirtualBOX에 설치한 centos7에 docker를 설치 한다.

[root@localhost /]# yum install docker-ce docker-ce-cli containerd.io

4. docker 설치완료후 demon 실행.

[root@localhost /]# systemctl start docker

5. docker에 mariadb 설치 파일 image 다운로드

[root@localhost /]# docker pull mariadb
Using default tag: latest
latest: Pulling from library/mariadb
d19f32bd9e41: Pull complete
f587559f9b58: Pull complete
b91b7f01dd8c: Pull complete
fb5f1b1e214a: Pull complete
a5ab08b1f4c5: Pull complete
1093648eca21: Pull complete
e1cc76be63b2: Pull complete
710253f0933b: Pull complete
962d5115199c: Pull complete
31f43d7b59b5: Pull complete
4e7032a660a4: Pull complete
Digest: sha256:816e53e5e0990de0d126ba981234bacfc56f82a837411231bcf1e9021a3d9d4f
Status: Downloaded newer image for mariadb:latest
docker.io/library/mariadb:latest
[root@localhost /]#

 6. docker에 mariadb 설치.

주) mariadb설치시 centos와 docker 간의 포트포워딩을 같이 설정 한다.

##명령어 옵션

--name은 사용할컨테이너의 이름, 

-d는 컨테이너를 백그라운드에서 실행, 

-p는 호스트와 컨테이너 간의 포트를 연결 (host-port:container-port) centos7 3308 포트 연결 시 컨테이너 3306 포트로

 포워딩 설정,

--restart=always는 도커서비스 실행시 항상 컨테이너를 같이 실행으로 설정,

-e는 기타 환경설정(Enviorment),

MYSQL_ROOT_PASSWORD=********는 mariadb의 root 사용자 초기 비밀번호를 설정,

mariadb는 컨테이너를 만들 때 사용할 이미지 이름

[root@localhost /]# docker run --name mariadb -d -p 3308:3306 --restart=always -e MYSQL_ROOT_PASSWORD=******** mariadb
6bc569c015b83e893aec4fe4abacb9d41ef390618d0d420c30c6cda8271a9a40
[root@localhost /]#

6-1. VirtualBOX에 설치한 centos7의 3308 포트 방화벽 오픈.

[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=3308/tcp 
success 
[root@localhost /]# firewall-cmd --reload 
success
[root@localhost /]#
728x90
반응형
SMALL

7. docker의 mariadb 컨테이너 접속.

[root@localhost /]# docker exec -it mariadb /bin/bash
root@54e89cbec63f:/#

8. docker의 mariadb 컨테이너에 접속 및 DB생성, 계성생성, 권한설정.

root@54e89cbec63f:/# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.9.2-MariaDB-1:10.9.2+maria~ubu2204 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)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]>
MariaDB [mysql]> create database test;
Query OK, 1 row affected (0.001 sec)

MariaDB [mysql]> create user 'db****'@'%' identified by '1******0';
Query OK, 0 rows affected (0.007 sec)

MariaDB [mysql]> grant all privileges on test.* to 'db****'@'%';
Query OK, 0 rows affected (0.007 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> exit
Bye
root@54e89cbec63f:/# exit
exit
[root@localhost /]#

여기까지 쫒아 했으면 이제 외부에서 위에서 생성한 db****이란 계정으로 VirtualBOX에 설정한 centos7환경의 docker의

mariadb 에 접속 할수 있다.

- 아래와 같이 DB TOOL을 사용 하여 접속 테스트.

9. docker 명령어 일부만 정리.

-- docker의 컨테이너 종료.
[root@localhost /]# docker stop mariadb

-- docker의 컨테이너 시작.
[root@localhost /]# docker start mariadb

-- docker의 특정 컨테이너에 접속하기
[root@localhost /]# docker exec -it [coneainerID] /bin/bash

-- docker demon서비스 종료.(소켓은 별도로 종료 해야 하는것 같은 확실치 않음...)
[root@localhost /]# systemctl stop docker
[root@localhost /]# systemctl stop docker.socket

-- docker demon서비스 시작.
[root@localhost /]# systemctl start docker

-- 컨테이너 접속.
[root@localhost /]# docker exec -it mariadb /bin/bash

-- 컨테이너 삭제.(컨테이너 종료후 삭제 가능.)
[root@localhost /]# docker rm mariadb

-- docker 에서 실행 중인 컨테이너 확인.
[root@localhost /]# docker ps

-- docker 정보확인.
[root@localhost /]# docker info

-- docker 에 다운로드(pull)된 이미지 리스트 확인
[root@localhost /]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
mariadb      latest    01d138caf7d0   32 hours ago   384MB

-- 각 컨테이너별 로그를 확인 하고 싶을때는.
[root@localhost /]# docker logs --tail 50 --follow --timestamps mariadb
728x90
반응형
LIST

'centos7 & rocky9' 카테고리의 다른 글

centos7+crontab+mysql+backup+mysqldump  (0) 2023.06.02
centos7+docker+MSSQL setup & config Ing~  (0) 2022.09.08
centos7+yona(Git사용)  (2) 2020.11.02
SVN error E204900  (0) 2020.05.20
centos7 부팅모드 변경 CLI / GUI  (0) 2020.05.14
Comments