前言
製作映像的好處是製作一次,然後可以在不同的docker環境中運行,免去了下載軟件和安裝軟件的工作。
1、在網上搜索centos操作系統
-bash-4.2# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 4079 [OK]
2、將操作系統映像拉到本地操作系統中
docker pull centos
3、啓動操作系統映像
docker run -t -i --net=host -v /db2disk:/db2disk centos /bin/bash
-v選項的含義是將宿主機上的/db2disk目錄mount到容器中的/db2disk目錄
4、cp /db2disk/v10.5fp8_linuxx64_server_t.tar /tmp
cd /tmp
tar xvf v10.5fp8_linuxx64_server_t.tar
5、檢查操作系統是否滿足安裝要求
DBT3507E The db2prereqcheck utility failed to find the following package or file: "gcc".
ERROR : Requirement not matched.
Validating "binutils" ...
Package (or file) found: "binutils"
Requirement matched.
Validating "cpp" ...
DBT3507E The db2prereqcheck utility failed to find the following package or file: "cpp".
ERROR : Requirement not matched.
Validating "gcc-c++" ...
DBT3507E The db2prereqcheck utility failed to find the following package or file: "gcc-c++".
ERROR : Requirement not matched.
DBT3507E The db2prereqcheck utility failed to find the following package or file: "kernel-devel".
ERROR : Requirement not matched.
Validating "sg3_utils" ...
DBT3507E The db2prereqcheck utility failed to find the following package or file: "sg3_utils".
ERROR : Requirement not matched.
Validating "sg_persist" ...
DBT3507E The db2prereqcheck utility failed to find the following package or file: "sg_persist".
ERROR : Requirement not matched.
缺少下面6個包
Summary of prerequisites that are not met on the current system:
DBT3507E The db2prereqcheck utility failed to find the following package or file: "sg_persist".
DBT3507E The db2prereqcheck utility failed to find the following package or file: "sg3_utils".
DBT3507E The db2prereqcheck utility failed to find the following package or file: "kernel-devel".
DBT3507E The db2prereqcheck utility failed to find the following package or file: "gcc-c++".
DBT3507E The db2prereqcheck utility failed to find the following package or file: "cpp".
DBT3507E The db2prereqcheck utility failed to find the following package or file: "gcc".
6、安裝下面幾個包
yum install sg_persist -y
yum install sg3_utils -y
yum install kernel-devel -y
yum install gcc-c++ -y
yum install gcc -y
7、重新執行db2prereqcheck, 顯示操作系統滿足了安裝的要求
8、執行db2_install安裝,選擇安裝在缺省的目錄,安裝產品爲企業版
9、增加組:
groupadd db2iadm
groupadd db2ifenc
10、增加用戶
useradd -u 1003 -g db2iadm -d /home/db2inst1 -m db2inst1
useradd -u 1004 -g db2ifenc -d /home/db2fenc1 -m db2fenc1
11、創建實例
[root@shcallisto-25 instance]# ./db2icrt -u db2fenc1 db2inst1
12、啓動實例
[db2inst1@shcallisto-25 db2disk]$ db2start
03/13/2018 06:30:46 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
註冊許可證
db2licm -a db2ese.lic
13、創建實例
[db2inst1@shcallisto-25 db2disk]$ db2 create db mydb
DB20000I The CREATE DATABASE command completed successfully.
14、連接數據庫
[db2inst1@shcallisto-25 db2disk]$ db2 connect to mydb
Database Connection Information
Database server = DB2/LINUXX8664 10.5.8
SQL authorization ID = DB2INST1
Local database alias = MYDB
15、保存映像,新的映像名稱爲 centos_db2ese_v1.1
執行docker ps 看到運行的容器ID爲cc09e1e9f71b
docker commit cc09e1e9f71b centos_db2ese_v1.1
16、啓動新的容器
docker run -t -i --net=host -v /db2disk:/db2disk --privileged centos_db2ese_v1.1 /bin/bash
加--privileged的目的是可以運行sysctl -p命令修改操作系統內核
[db2inst1@shcallisto-25 ~]$ db2start
03/13/2018 06:44:15 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@shcallisto-25 ~]$ db2 connect to mydb
Database Connection Information
Database server = DB2/LINUXX8664 10.5.8
SQL authorization ID = DB2INST1
Local database alias = MYDB
17、刪除中間過程創建的映像
# docker rmi -f centos_db2ese_v1
-bash-4.2# docker rmi -f 4074964aff32
Error response from daemon: conflict: unable to delete 4074964aff32 (cannot be forced) - image is being used by running container b21f2e05626b
查看使用容器的進程
-bash-4.2# docker ps | grep b21f2e05626b
b21f2e05626b 4074964aff32 "bash" 4 days ago Up 4 days nifty_shaw
停止使用容器的進程
-bash-4.2# docker stop b21f2e05626b
b21f2e05626b
再次刪除,執行成功
-bash-4.2# docker rmi -f 4074964aff32
Deleted: sha256:4074964aff321279c48f2bb0090dba8c297b62a936c8a92679303445169ae20c
18、查看映像大小
-bash-4.2# docker images | more
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_db2ese_v1.1 latest e05772da75e6 10 minutes ago 6.38 GB
centos latest 2d194b392dd1 7 days ago 195 MB
ibmcom/db2express-c-new latest 93ab907a6519 7 weeks ago 1.71 GB
19、製作過程中碰到的問題
在執行db2_install時碰到了下面的錯誤,安裝終止:
Task #41 start
Description: Starting DB2 Fault Monitor
Estimated time 10 second(s)
Hangup
解決辦法如下:
1) 執行db2fmcu -d
2)帶--privileged運行容器,然後修改內核參數
docker run -t -i --net=host -v /db2disk:/db2disk --privileged centos_db2ese_v1.1 /bin/bash
vi /etc/sysctl.conf
kernel.shmmni = 65536
kernel.shmmax = 274877906944
kernel.shmall = 134217728
kernel.sem = 250 1024000 32 65536
kernel.msgmni = 262144
kernel.msgmax = 65536
kernel.msgmnb = 65536
vm.dirty_background_ratio = 5
vm.dirty_ratio= 10
vm.overcommit_memory= 0
vm.swappiness= 0 #如果是redhat,建議設置爲5,
否則很有可能在內存不足時OOM killer可能會殺掉DB2進程
執行sysctl -p使參數在線生效
執行ipcs -l查看操作系統內核參數設置
------ Messages Limits --------
max queues system wide = 668
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 18014398509465599
max total shared memory (kbytes) = 18014398442373116
min seg size (bytes) = 1
------ Semaphore Limits --------
max number of arrays = 128
max semaphores per array = 250
max semaphores system wide = 32000
max ops per semop call = 32
semaphore max value = 32767
作者:陸川