J'ai précédemment résumé les étapes pour déployer Db2 dans un environnement Linux.
[Remarque] Résumé de la procédure d'installation de Db2 (Linux) https://qiita.com/Haruka-Ogawa/items/9576399209b32f3016ea
Db2 est disponible en version Docker depuis 2017 Vous pouvez utiliser l'environnement Db2 plus facilement en tirant sur le magasin Docker.
Cette fois, je vais résumer la procédure pour obtenir le conteneur Db2 de Docker.
Installez Docker sur votre PC. Cette fois, nous avons installé Docker v19.03.12 sur Mac PC.
$ docker -v
Docker version 19.03.12, build 48a66213fe
Tout d'abord, récupérez l'image Db2.
Utilisez la commande ** docker pull ** pour obtenir l'image. Ouvrez le lien ci-dessous et copiez la commande ** docker pull ** pour obtenir l'image Db2 sur le côté droit de l'écran.
https://hub.docker.com/r/ibmcom/db2
Exécutez la commande ** docker pull ** copiée.
$ docker pull ibmcom/db2
Using default tag: latest
latest: Pulling from ibmcom/db2
524b0c1e57f8: Pull complete
e7a9171c839a: Pull complete
f4447742b873: Pull complete
db90696d3502: Pull complete
6acc1312ab24: Pull complete
67e9a72bc07a: Pull complete
2b9e6b7678c7: Pull complete
Digest: sha256:cf95dd272a4f99d7f9119945ecad04b64ad3a2badc8a6682f1105aa87279da60
Status: Downloaded newer image for ibmcom/db2:latest
docker.io/ibmcom/db2:latest
[Référence] Document Docker: pull https://docs.docker.jp/engine/reference/commandline/pull.html
Afficher la liste des images acquises par la commande ** docker images ** et afficher Confirmez que l'image db2 a été obtenue.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ibmcom/db2 latest d6b3abc02d57 2 months ago 2.69GB
[Référence] Document Docker: images https://docs.docker.jp/engine/reference/commandline/images.html
Exécutez la commande ** docker run ** pour créer et démarrer le conteneur Db2. La commande exécutée cette fois est basée sur le guide de Docker Hub: ibmcom / db2.
$ docker run -itd --name mydb --privileged=true -p 50000:50000 -e LICENSE=accept -e DB2INST1_PASSWORD=passw0rd -e DBNAME=testdb -v /Users/ogawa/db2fs:/database ibmcom/db2
67070db8cf20d82a9be8b45454eb1d5239c6c4d33b685c8ab9503a3bcc84e68b
[Référence] Docker Hub: ibmcom / db2 https://hub.docker.com/r/ibmcom/db2
[Référence] Document Docker: exécuter https://docs.docker.jp/engine/reference/commandline/run.html
Vérifiez le journal du conteneur avec la commande ** docker logs ** Confirmez que le conteneur a été créé et démarré.
$ docker logs -f mydb
(*) Previous setup has not been detected. Creating the users...
(*) Creating users ...
(*) Creating instance ...
DBI1446I The db2icrt command is running.
DB2 installation is being initialized.
Total number of tasks to be performed: 4
Total estimated time for all tasks to be performed: 309 second(s)
Task #1 start
Description: Setting default global profile registry variables
Estimated time 1 second(s)
Task #1 end
Task #2 start
Description: Initializing instance list
Estimated time 5 second(s)
Task #2 end
Task #3 start
Description: Configuring DB2 instances
Estimated time 300 second(s)
Task #3 end
Task #4 start
Description: Updating global profile registry
Estimated time 3 second(s)
Task #4 end
The execution completed successfully.
For more information see the DB2 installation log at "/tmp/db2icrt.log.77".
DBI1070I Program db2icrt completed successfully.
09/09/2020 03:16:06 0 0 SQL1032N No start database manager command was issued.
SQL1032N No start database manager command was issued. SQLSTATE=57019
(*) Cataloging existing databases
ls: cannot access /database/data/db2inst1/NODE0000: No such file or directory
(*) Applying Db2 license ...
LIC1402I License added successfully.
LIC1426I This product is now licensed for use as outlined in your License Agreement. USE OF THE PRODUCT CONSTITUTES ACCEPTANCE OF THE TERMS OF THE IBM LICENSE AGREEMENT, LOCATED IN THE FOLLOWING DIRECTORY: "/opt/ibm/db2/V11.5/license/en_US.iso88591"
(*) Saving the checksum of the current nodelock file ...
(*) Updating DBM CFG parameters ...
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
No Cgroup memory limit detected, instance memory will follow automatic tuning
(*) Remounting /database with suid...
(*) Nothing appears in the Db2 directory. will skip update/upgrade.
(*) Code level is the same. No update/upgrade needed.
DB2 State : Operable
DB2 has not been started
Starting DB2...
09/09/2020 03:16:35 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(*) User chose to create testdb database
(*) Creating database testdb ...
DB20000I The CREATE DATABASE command completed successfully.
DB20000I The ACTIVATE DATABASE command completed successfully.
09/09/2020 03:18:38 0 0 SQL1026N The database manager is already active.
SQL1026N The database manager is already active.
### Enabling LOGARCHMETH1
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
### Restarting DB2
09/09/2020 03:18:46 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
09/09/2020 03:18:51 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
### Making backup directory and performing backup
Backup successful. The timestamp for this backup image is : 20200909031855
(*) Applying autoconfiguration for instance ...
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, the database
must be shutdown and reactivated before the configuration parameter changes
become effective.
DB20000I The SQL command completed successfully.
09/09/2020 03:19:15 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
09/09/2020 03:19:20 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
(*) Skipping TEXT_SEARCH setup for database testdb because TEXT_SEARCH is not configured for the instance ...
ssh-keygen: generating new host keys: RSA1 RSA DSA ECDSA ED25519
(*) All databases are now active.
(*) Setup has completed.
FALSE
2020-09-09-03.19.20.117938+000 I223959E393 LEVEL: Warning
PID : 14939 TID : 139881437169536 PROC : db2start
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
FUNCTION: DB2 UDB, base sys utilities, sqleReleaseStStLockFile, probe:16076
MESSAGE : Released lock on the file:
DATA #1 : String, 50 bytes
/database/config/db2inst1/sqllib/ctrl/db2strst.lck
2020-09-09-03.19.37.389298+000 I224353E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.20.07.369457+000 I224774E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.20.37.353793+000 I225195E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.21.07.337071+000 I225616E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.24.02.151703+000 I226037E420 LEVEL: Warning
PID : 14947 TID : 140530994374400 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 15 EDUNAME: db2wlmtm 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
2020-09-09-03.24.02.031095+000 I226458E419 LEVEL: Warning
PID : 14947 TID : 140530998568704 PROC : db2sysc 0
INSTANCE: db2inst1 NODE : 000
HOSTNAME: 67070db8cf20
EDUID : 14 EDUNAME: db2wlmt 0
FUNCTION: DB2 UDB, base sys utilities, sqleTimedSleep, probe:1182
DATA #1 : unsigned integer, 8 bytes
1.59962E+12
DATA #2 : unsigned integer, 8 bytes
1.59962E+12
[Référence] Documentation Docker: journaux https://docs.docker.jp/engine/reference/commandline/logs.html
Afficher la liste des conteneurs avec la commande ** docker ps ** Vérifiez l'état du conteneur Db2.
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67070db8cf20 ibmcom/db2 "/var/db2_setup/lib/…" About an hour ago Up About an hour 22/tcp, 55000/tcp, 60006-60007/tcp, 0.0.0.0:50000->50000/tcp mydb
[Référence] Documentation Docker: ps https://docs.docker.jp/engine/reference/commandline/ps.html
La commande ** docker exec ** peut exécuter n'importe quelle commande à l'intérieur du conteneur. Démarrez bash et basculez vers db2inst1 pour accéder à l'environnement db2.
$ docker exec -ti mydb bash -c "su - db2inst1"
Last login: Wed Sep 9 04:48:57 UTC 2020
[Référence] Document Docker: exec https://docs.docker.jp/engine/reference/commandline/exec.html
Assurez-vous que la commande Db2 peut être exécutée.
--Vérifiez la version de db2
Exécutez la commande ** db2level ** pour vérifier la version Db2.
[db2inst1@67070db8cf20 ~]$ db2level
DB21085I This instance or install (instance name, where applicable:
"db2inst1") uses "64" bits and DB2 code release "SQL11054" with level
identifier "0605010F".
Informational tokens are "DB2 v11.5.4.0", "s2006161200", "DYN2006161200AMD64",
and Fix Pack "0".
Product is installed at "/opt/ibm/db2/V11.5".
Au moment de l'exécution de la commande ** docker run **, la base de données * testdb * a été créée. Connectez-vous à la base de données * testdb * avec la commande ** connect **.
[db2inst1@67070db8cf20 ~]$ db2 connect to testdb
Database Connection Information
Database server = DB2/LINUXX8664 11.5.4.0
SQL authorization ID = DB2INST1
Local database alias = TESTDB
--Créer une table
Créons une table * TBL1 * dans la base de données * testdb *.
[db2inst1@67070db8cf20 ~]$ db2 "CREATE TABLE TBL1(COL1 INTEGER, COL2 VARCHAR(50))"
DB20000I The SQL command completed successfully.
Déconnectez-vous de la base de données * testdb * avec la commande ** terminate **.
[db2inst1@67070db8cf20 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
J'ai exécuté la commande Db2 et j'ai confirmé qu'elle pouvait être utilisée.
Utilisez la commande exit lorsque vous quittez le conteneur.
[db2inst1@67070db8cf20 ~]$ exit
logout
Pour démarrer / arrêter le conteneur créé Utilisez la commande ** docker start ** et la commande ** docker stop **.
Démarrez le conteneur Db2 (* mydb *) avec la commande ** docker start **.
$ docker start mydb
mydb
[Référence] Document Docker: démarrer https://docs.docker.jp/engine/reference/commandline/start.html
Utilisez la commande ** docker stop ** pour arrêter le conteneur Db2 (* mydb *).
$ docker stop mydb
mydb
[Référence] Documentation Docker: arrêter https://docs.docker.jp/engine/reference/commandline/stop.html
Cette fois, j'ai essayé d'extraire Db2 fourni en tant que conteneur Docker.
Si vous avez un PC avec Docker installé, vous pouvez utiliser l'environnement Db2 très facilement, Le travail lui-même a été achevé en environ 10 minutes, j'ai donc pensé que ce serait pratique si je voulais vérifier le fonctionnement de Db2 pendant un moment.
Db2 et Docker https://www.ibm.com/blogs/solutions/jp-ja/db2-docker/
Docker Hub:ibmcom/db2 https://hub.docker.com/r/ibmcom/db2
Recommended Posts