配置参考:
OS: CentOS 7
配置: 16核32G 250GB硬盘
Docker Configuration
curl -fsSL https://get.docker.com | bash -s docker
修改 docker.service
添加如下内容:
--selinux-enabled --cpu-rt-runtime=950000
启动Docker
systemctl daemon-reload systemctl start docker
创建docker⽹络
docker network create --driver=bridge --subnet=172.16.1.0/24 rac_pub1_nw docker network create --driver=bridge --subnet=192.168.17.0/24 rac_priv1_nw
docker network create -d macvlan --subnet=172.16.1.0/24 --gateway=172.16.1.1 -o parent=eth0 rac_pub1_nw docker network create -d macvlan --subnet=192.168.17.0/24 --gateway=192.168.17.1 -o parent=eth1 rac_priv1_nw
System Configuration
编辑 /etc/sysctl.conf
vim /etc/sysctl.conf fs.file-max = 6815744 net.core.rmem_max = 4194304 net.core.rmem_default = 262144 net.core.wmem_max = 1048576 net.core.wmem_default = 262144 net.core.rmem_default = 262144 #保存退出后执⾏如下操作 sysctl -a sysctl -p
Oracle Database RAC on Docker
⾸先下载Oracle官⽅GitHub仓库相关内容
git clone https://github.com/oracle/docker-images
后续操作主要在 docker-images/OracleDatabase/RAC 下操作,本次测试主要使⽤的是Oracle Database 19C版 本。
OracleDNSServer
⽬录为 /root/docker-images/OracleDatabase/RAC/OracleDNSServer/dockerfiles
./buildContainerImage.sh -v latest
运⾏RAC DNS server容器
docker run -d --name racdns \ --hostname rac-dns \ --dns-search="example.com" \ --cap-add=SYS_ADMIN \ --network rac_pub1_nw \ --ip 172.16.1.25 \ --sysctl net.ipv6.conf.all.disable_ipv6=1 \ --env SETUP_DNS_CONFIG_FILES="setup_true" \ --env DOMAIN_NAME="example.com" \ --env RAC_NODE_NAME_PREFIX="racnode" \ oracle/rac-dnsserver:latest
检查容器是否启动成功
docker logs -f racdns
OracleRACStorageServer
⽬录为 /root/docker-images/OracleDatabase/RAC/OracleRACStorageServer/dockerfiles 执⾏此命令 构建镜像
./buildDockerImage.sh -v 19.3.0
关闭selinux
setenforce 0
安装NFS
yum install nfs-utils -y
运行容器
docker run -d -t --hostname racnode-storage \ --dns-search=example.com --cap-add SYS_ADMIN \ --volume /docker_volumes/asm_vol/$ORACLE_SID:/oradata --init \ --network=rac_priv1_nw --ip=192.168.17.25 --tmpfs=/run \ --volume /sys/fs/cgroup:/sys/fs/cgroup:ro \ --name racnode-storage oracle/rac-storage-server:19.3.0
检查容器是否启动成功
docker logs -f racnode-storage
创建NFS Volume
docker volume create --driver local \ --opt type=nfs \ --opt o=addr=192.168.17.25,rw,bg,hard,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0 \ --opt device=:/oradata \ racstorage
OracleConnectionManager
事先要下载好 LINUX.X64_193000_client.zip 放到此⽬录下 /root/dockerimages/OracleDatabase/RAC/OracleConnectionManager/dockerfiles/19.3.0 ,然后执⾏ buildDockerImage.sh
./buildDockerImage.sh -v 19.3.0
执⾏此命令后⾃动开始打包docker镜像。
创建容器
docker run -d --hostname racnode-cman1 --dns-search=example.com \ --network=rac_pub1_nw --ip=172.16.1.15 \ -e DOMAIN=example.com -e PUBLIC_IP=172.16.1.15 \ -e PUBLIC_HOSTNAME=racnode-cman1 -e SCAN_NAME=racnode-scan \ -e SCAN_IP=172.16.1.70 --privileged=false \ -p 1521:1521 --name racnode-cman oracle/client-cman:19.3.0
检查容器是否启动成功
docker logs -f racnode-cman
OracleRealApplicationClusters
事先要下载好 LINUX.X64_193000_db_home.zip 和 LINUX.X64_193000_grid_home.zip 放 到 /root/dockerimages/OracleDatabase/RAC/OracleRealApplicationClusters/dockerfiles/19.3.0 下
./buildContainerImage.sh -v 19.3.0
所有容器将共享⼀个主机⽂件以进⾏名称解析。共享主机⽂件必须对所有容器可⽤。在以下位置创建共享主机⽂件 (如果不存在) /opt/containers/rac_host_file :
mkdir /opt/containers touch /opt/containers/rac_host_file
注意:不要 /opt/containers/rac_host_file 从 docker 主机修改。它将在容器内进⾏管理。
密码管理
mkdir /opt/.secrets/ openssl rand -hex 64 -out /opt/.secrets/pwd.key
编辑 /opt/.secrets/common_os_pwdfile 这将是 grid/oracle 和数据库⽤户的通⽤密码。执⾏以下命令:
openssl enc -aes-256-cbc -salt -in /opt/.secrets/common_os_pwdfile -out /opt/.secrets/common_os_pwdfile.enc -pass file:/opt/.secrets/pwd.key rm -f /opt/.secrets/common_os_pwdfile chmod 400 /opt/.secrets/common_os_pwdfile.enc chmod 400 /opt/.secrets/pwd.key
创建 Oracle RAC 容器
racnode1
docker create -t -i \ --hostname racnode1 \ --volume /boot:/boot:ro \ --volume /dev/shm \ --tmpfs /dev/shm:rw,exec,size=4G \ --volume /opt/containers/rac_host_file:/etc/hosts \ --volume /opt/.secrets:/run/secrets:ro \ --dns=172.16.1.25 \ --dns-search=example.com \ --privileged=false \ --volume racstorage:/oradata \ --cap-add=SYS_NICE \ --cap-add=SYS_RESOURCE \ --cap-add=NET_ADMIN \ -e DNS_SERVERS="172.16.1.25" \ -e NODE_VIP=172.16.1.160 \ -e VIP_HOSTNAME=racnode1-vip \ -e PRIV_IP=192.168.17.150 \ -e PRIV_HOSTNAME=racnode1-priv \ -e PUBLIC_IP=172.16.1.150 \ -e PUBLIC_HOSTNAME=racnode1 \ -e SCAN_NAME=racnode-scan \ -e OP_TYPE=INSTALL \ -e DOMAIN=example.com \ -e ASM_DISCOVERY_DIR=/oradata \ -e ASM_DEVICE_LIST=/oradata/asm_disk01.img,/oradata/asm_disk02.img,/oradata/asm_disk03.img, /oradata/asm_disk04.img,/oradata/asm_disk05.img \ -e CMAN_HOSTNAME=racnode-cman1 \ -e CMAN_IP=172.16.1.15 \ -e COMMON_OS_PWD_FILE=common_os_pwdfile.enc \ -e PWD_KEY=pwd.key \ --restart=always \ --tmpfs=/run -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ --cpu-rt-runtime=95000 \ --ulimit rtprio=99 \ --name racnode1 \ oracle/database-rac:19.3.0
将⽹络分配给Oracle RAC containers
docker network disconnect bridge racnode1 docker network connect rac_pub1_nw --ip 172.16.1.150 racnode1 docker network connect rac_priv1_nw --ip 192.168.17.150 racnode1
启动容器
docker start racnode1
创建集群可能需要⾄少 40 分钟或更⻓时间。要检查⽇志请使⽤如下命令
docker logs -f racnode1
您应该在最后看到数据库创建成功消息:
racnode2
docker create -t -i \ --hostname racnode2 \ --volume /dev/shm \ --tmpfs /dev/shm:rw,exec,size=4G \ --volume /boot:/boot:ro \ --dns-search=example.com \ --volume /opt/containers/rac_host_file:/etc/hosts \ --volume /opt/.secrets:/run/secrets:ro \ --dns=172.16.1.25 \ --dns-search=example.com \ --privileged=false \ --volume racstorage:/oradata \ --cap-add=SYS_NICE \ --cap-add=SYS_RESOURCE \ --cap-add=NET_ADMIN \ -e DNS_SERVERS="172.16.1.25" \ -e EXISTING_CLS_NODES=racnode1 \ -e NODE_VIP=172.16.1.161 \ -e VIP_HOSTNAME=racnode2-vip \ -e PRIV_IP=192.168.17.151 \ -e PRIV_HOSTNAME=racnode2-priv \ -e PUBLIC_IP=172.16.1.151 \ -e PUBLIC_HOSTNAME=racnode2 \ -e DOMAIN=example.com \ -e SCAN_NAME=racnode-scan \ -e ASM_DISCOVERY_DIR=/oradata \ -e ASM_DEVICE_LIST=/oradata/asm_disk01.img,/oradata/asm_disk02.img,/oradata/asm_disk03.img, /oradata/asm_disk04.img,/oradata/asm_disk05.img \ -e ORACLE_SID=ORCLCDB \ -e OP_TYPE=ADDNODE \ -e COMMON_OS_PWD_FILE=common_os_pwdfile.enc \ -e PWD_KEY=pwd.key \ --tmpfs=/run -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ --cpu-rt-runtime=95000 \ --ulimit rtprio=99 \ --restart=always \ --name racnode2 \ oracle/database-rac:19.3.0
将⽹络分配给Oracle RAC containers
docker network disconnect bridge racnode2 docker network connect rac_pub1_nw --ip 172.16.1.151 racnode2 docker network connect rac_priv1_nw --ip 192.168.17.151 racnode2
启动容器
docker start racnode2
检查日志请使用如下命令:
docker logs -f racnode2
Connecting to Oracle RAC Database
连接命令格式如下
system/@//<docker_host>:1521/<ORACLE_SID>
使⽤connection manager进⾏连接
SingleInstance
事先要下载好 LINUX.X64_193000_db_home.zip 放到 /root/dockerimages/OracleDatabase/SingleInstance/dockerfiles/19.3.0
构建镜像
./buildContainerImage.sh -e -v 19.3.0
运⾏容器
docker run -itd --name single \ --network rac_pub1_nw --ip 172.16.1.200 \ -e ORACLE_PWD=wasd \ -e ORACLE_EDITION=enterprise \ -e ENABLE_ARCHIVELOG=true \ oracle/database:19.3.0-ee