当前位置:   article > 正文

【DB2 流浪之旅】 第一讲 Linux 环境安装 db2 数据库_linux db2安装

linux db2安装

DB2数据库是IBM开发的一种大型关系型数据库平台。它支持多用户或应用程序在同一条SQL 语句中查询不同database甚至不同DBMS中的数据。一般DB2是搭配IBM Power系列小机使用的,兼容性好、性能高。当然DB2也有Linux版本的,相对性能会差一些,主要使用在一些开发、学习环境,成本低嘛。

今天就来简单介绍一下在Linux环境安装db2数据库软件。

一、DB2 软件安装包下载

可在IBM网站的如下地址,下载个版本的DB2软件包:
https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windowsicon-default.png?t=N7T8https://www.ibm.com/support/pages/download-db2-fix-packs-version-db2-linux-unix-and-windows在选择某个版本db2之后,需要选择正确的操作系统版本,并选择“DB2 Server Fix Pack”类型的安装包。
“DB2 Server Fix Pack”与“DB2 Universal Fix Pack”的区别:Server Fix Pack是全量补丁包,可以直接安装;Universal Fix Pack是增量补丁包,只能用来打补丁,不能直接新安装。

二、DB2 软件安装

打开命令行窗口。运行以下命令安装DB2软件:

  1. linux-d4al:~ # ls -l v10.5fp7_linuxx64_server_t.tar.gz
  2. -rw-r--r-- 1 root root 1429018107 Jul 21 00:54 v10.5fp7_linuxx64_server_t.tar.gz
  3. linux-d4al:~ # gzip -d v10.5fp7_linuxx64_server_t.tar.gz -c | tar -xf -
  4. linux-d4al:~ # cd server_t
  5. linux-d4al:~/server_t # ls
  6. db2 db2_deinstall db2_install db2checkCOL.tar.gz db2checkCOL_readme.txt db2ckupgrade db2ls db2prereqcheck db2setup ibm_im installFixPack nlpack
  7. linux-d4al:~/server_t # ./db2_install
  8. DBI1324W Support of the db2_install command is deprecated.
  9. Default directory for installation of products - /opt/ibm/db2/V10.5
  10. ***********************************************************
  11. Install into default directory (/opt/ibm/db2/V10.5) ? [yes/no]
  12. yes
  13. Specify one of the following keywords to install DB2 products.
  14. SERVER
  15. CONSV
  16. EXP
  17. CLIENT
  18. RTCL
  19. Enter "help" to redisplay product names.
  20. Enter "quit" to exit.
  21. ***********************************************************
  22. SERVER
  23. ***********************************************************
  24. Do you want to install the DB2 pureScale Feature? [yes/no]
  25. no
  26. DB2 installation is being initialized.
  27. Total number of tasks to be performed: 49
  28. Total estimated time for all tasks to be performed: 1947 second(s)
  29. Task #1 start
  30. Description: Checking license agreement acceptance
  31. Estimated time 1 second(s)
  32. Task #1 end
  33. Task #2 start
  34. Description: Base Client Support for installation with root privileges
  35. Estimated time 3 second(s)
  36. Task #2 end
  37. Task #3 start
  38. Description: Product Messages - English
  39. Estimated time 14 second(s)
  40. Task #3 end
  41. Task #49 start
  42. Description: Registering DB2 Update Service
  43. Estimated time 30 second(s)
  44. Task #49 end
  45. Task #50 start
  46. Description: Updating global profile registry
  47. Estimated time 3 second(s)
  48. Task #50 end
  49. The execution completed successfully.
  50. For more information see the DB2 installation log at
  51. "/tmp/db2_install.log.43840".

最后看到“The execution completed successfully.”提示后,安装成功。 

三、License 注册

 DB2是IBM出版的商业化数据库软件,需要注册License才能够使用,当然如果不注册是有90天的免费试用期的,试用期内所有功能都是可以使用的,超过试用期后,DB2数据库将无法正常启动。

License注册步骤:

  1. linux-d4al:~ # /opt/ibm/db2/V10.5/adm/db2licm -a /root/db2aese_c.lic
  2. LIC1402I License added successfully.
  3. 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/V10.5/license/en_US.iso88591"

至此,DB2数据库软件就安装完毕可以正常使用啦。接下来就可以建实例、建库、导入数据等等操作。

四、创建DB2实例与数据库

4.1. 创建数据库用户

通过以下命令,创建DB2需要的用户:

  1. linux-d4al:~ # mkdir /db2home
  2. linux-d4al:~ # groupadd db2igrp1
  3. linux-d4al:~ # groupadd db2fgrp1
  4. linux-d4al:~ # useradd -d /db2home/db2inst1 -g db2igrp1 -m db2inst1
  5. linux-d4al:~ # useradd -d /db2home/db2fenc1 -g db2fgrp1 -m db2fenc1

注:其中,db2inst1是实例用户,db2fenc1是防护用户。

4.2. 修改实例用户的ulimit限制(可选)

编辑/etc/security/limits.conf文件,增加如下内容(如果实例名字不是db2inst1,就改成实例名字):

  1. # limits for the db2 instance user
  2. db2inst1 soft data -1
  3. db2inst1 hard data -1
  4. db2inst1 soft nofile 65536
  5. db2inst1 hard nofile 65536
  6. db2inst1 soft fsize -1
  7. db2inst1 hard fsize -1
  8. db2inst1 soft nproc -1
  9. db2inst1 hard nproc -1

重新登录db2inst1(退出shell),然后运行ulimit -l命令,确认一下用户进程数的限制为unlimited。

  1. linux-d4al:~ # su - db2inst1
  2. db2inst1@linux-d4al:~> ulimit -a
  3. core file size (blocks, -c) 1
  4. data seg size (kbytes, -d) unlimited
  5. scheduling priority (-e) 0
  6. file size (blocks, -f) unlimited
  7. pending signals (-i) 31507
  8. max locked memory (kbytes, -l) 64
  9. max memory size (kbytes, -m) 3437652
  10. open files (-n) 65536
  11. pipe size (512 bytes, -p) 8
  12. POSIX message queues (bytes, -q) 819200
  13. real-time priority (-r) 0
  14. stack size (kbytes, -s) 8192
  15. cpu time (seconds, -t) unlimited
  16. max user processes (-u) unlimited
  17. virtual memory (kbytes, -v) 4918080
  18. file locks (-x) unlimited

4.3. 创建实例

在root用户下运行:

  1. linux-d4al:~ # /opt/ibm/db2/V10.5/instance/db2icrt -p 50000 -u db2fenc1 db2inst1
  2. DBI1446I The db2icrt command is running.
  3. DB2 installation is being initialized.
  4. Total number of tasks to be performed: 4
  5. Total estimated time for all tasks to be performed: 309 second(s)
  6. Task #1 start
  7. Description: Setting default global profile registry variables
  8. Estimated time 1 second(s)
  9. Task #1 end
  10. Task #2 start
  11. Description: Initializing instance list
  12. Estimated time 5 second(s)
  13. Task #2 end
  14. Task #3 start
  15. Description: Configuring DB2 instances
  16. Estimated time 300 second(s)
  17. Task #3 end
  18. Task #4 start
  19. Description: Updating global profile registry
  20. Estimated time 3 second(s)
  21. Task #4 end
  22. The execution completed successfully.
  23. For more information see the DB2 installation log at "/tmp/db2icrt.log.82608".
  24. DBI1070I Program db2icrt completed successfully.

实例创建完毕,通过以下命令,启动实例:

  1. linux-d4al:~ # su - db2inst1
  2. db2inst1@linux-d4al:~> db2start
  3. 11/21/2020 02:18:34 0 0 SQL1063N DB2START processing was successful.
  4. SQL1063N DB2START processing was successful.

通过以下命令,验证实例启动成功:

  1. db2inst1@linux-d4al:~> ps -ef|grep db2sysc
  2. db2inst1 98705 98703 1 02:18 pts/1 00:00:00 db2sysc 0
  3. db2inst1 98748 98217 0 02:19 pts/1 00:00:00 grep db2sysc
  4. db2inst1@linux-d4al:~> netstat -an|grep LISTEN|grep 50000
  5. tcp 0 0 0.0.0.0:50000 0.0.0.0:* LISTEN

4.4. 创建数据库

通过以下命令,创建数据库,并连接数据库、建表、插入数据,进行验证:

  1. db2inst1@linux-d4al:~> db2 create db testdb
  2. DB20000I The CREATE DATABASE command completed successfully.
  3. db2inst1@linux-d4al:~> db2 activate db testdb
  4. DB20000I The ACTIVATE DATABASE command completed successfully.
  5. db2inst1@linux-d4al:~> db2 connect to testdb
  6. Database Connection Information
  7. Database server = DB2/LINUXX8664 10.5.7
  8. SQL authorization ID = DB2INST1
  9. Local database alias = TEST
  10. db2inst1@linux-d4al:~> db2 "create table t (id int)"
  11. DB20000I The SQL command completed successfully.
  12. db2inst1@linux-d4al:~> db2 "insert into t values (1)"
  13. DB20000I The SQL command completed successfully.
  14. db2inst1@linux-d4al:~> db2 "select * from t"
  15. ID
  16. -----------
  17. 1
  18. 1 record(s) selected.

所有上面的操作都成功,说明数据库可以正常工作。

4.5. 创建SAMPLE数据库

DB2软件中自带一个SAMPLE数据库,里面有部分表和数据,可以在实验过程中用到。通过以下方式创建SAMPLE数据库:

  1. db2inst1@linux-d4al:~> db2sampl
  2. Creating database "SAMPLE"...
  3. Connecting to database "SAMPLE"...
  4. Creating tables and data in schema "DB2INST1"...
  5. Creating tables with XML columns and XML data in schema "DB2INST1"...
  6. 'db2sampl' processing complete.

 查看SAMPLE数据库中有哪些表:

  1. db2inst1@linux-d4al:~> db2 connect to sample
  2. Database Connection Information
  3. Database server = DB2/LINUXX8664 10.5.7
  4. SQL authorization ID = DB2INST1
  5. Local database alias = SAMPLE
  6. db2inst1@linux-d4al:~> db2 list tables
  7. Table/View Schema Type Creation time
  8. ------------------------------- --------------- ----- --------------------------
  9. ACT DB2INST1 T 2020-11-21-11.26.41.039078
  10. ADEFUSR DB2INST1 S 2020-11-21-11.26.44.389708
  11. CATALOG DB2INST1 T 2020-11-21-11.26.51.653362
  12. CL_SCHED DB2INST1 T 2020-11-21-11.26.38.263370
  13. CUSTOMER DB2INST1 T 2020-11-21-11.26.50.056282
  14. DEPARTMENT DB2INST1 T 2020-11-21-11.26.38.753447
  15. DEPT DB2INST1 A 2020-11-21-11.26.39.231002
  16. EMP DB2INST1 A 2020-11-21-11.26.39.576230
  17. EMPACT DB2INST1 A 2020-11-21-11.26.41.027695
  18. EMPLOYEE DB2INST1 T 2020-11-21-11.26.39.231730
  19. EMPMDC DB2INST1 T 2020-11-21-11.26.45.668977
  20. EMPPROJACT DB2INST1 T 2020-11-21-11.26.40.925404
  21. EMP_ACT DB2INST1 A 2020-11-21-11.26.41.028217
  22. EMP_PHOTO DB2INST1 T 2020-11-21-11.26.39.576716
  23. EMP_RESUME DB2INST1 T 2020-11-21-11.26.39.971092
  24. INVENTORY DB2INST1 T 2020-11-21-11.26.49.691897
  25. IN_TRAY DB2INST1 T 2020-11-21-11.26.41.315460
  26. ORG DB2INST1 T 2020-11-21-11.26.41.450716
  27. PRODUCT DB2INST1 T 2020-11-21-11.26.49.118415
  28. PRODUCTSUPPLIER DB2INST1 T 2020-11-21-11.26.53.558753
  29. PROJ DB2INST1 A 2020-11-21-11.26.40.694064
  30. PROJACT DB2INST1 T 2020-11-21-11.26.40.695770
  31. PROJECT DB2INST1 T 2020-11-21-11.26.40.391983
  32. PURCHASEORDER DB2INST1 T 2020-11-21-11.26.50.896302
  33. SALES DB2INST1 T 2020-11-21-11.26.41.676581
  34. STAFF DB2INST1 T 2020-11-21-11.26.41.547694
  35. STAFFG DB2INST1 T 2020-11-21-11.26.43.416941
  36. SUPPLIERS DB2INST1 T 2020-11-21-11.26.52.367045
  37. VACT DB2INST1 V 2020-11-21-11.26.41.904154
  38. VASTRDE1 DB2INST1 V 2020-11-21-11.26.42.270762
  39. VASTRDE2 DB2INST1 V 2020-11-21-11.26.42.276813
  40. VDEPMG1 DB2INST1 V 2020-11-21-11.26.42.262310
  41. VDEPT DB2INST1 V 2020-11-21-11.26.41.783723
  42. VEMP DB2INST1 V 2020-11-21-11.26.41.901406
  43. VEMPDPT1 DB2INST1 V 2020-11-21-11.26.42.266396
  44. VEMPLP DB2INST1 V 2020-11-21-11.26.42.303926
  45. VEMPPROJACT DB2INST1 V 2020-11-21-11.26.42.152614
  46. VFORPLA DB2INST1 V 2020-11-21-11.26.42.290855
  47. VHDEPT DB2INST1 V 2020-11-21-11.26.41.899784
  48. VPHONE DB2INST1 V 2020-11-21-11.26.42.300732
  49. VPROJ DB2INST1 V 2020-11-21-11.26.41.902841
  50. VPROJACT DB2INST1 V 2020-11-21-11.26.41.929668
  51. VPROJRE1 DB2INST1 V 2020-11-21-11.26.42.280267
  52. VPSTRDE1 DB2INST1 V 2020-11-21-11.26.42.283597
  53. VPSTRDE2 DB2INST1 V 2020-11-21-11.26.42.287719
  54. VSTAFAC1 DB2INST1 V 2020-11-21-11.26.42.293776
  55. VSTAFAC2 DB2INST1 V 2020-11-21-11.26.42.297155
  56. 47 record(s) selected.

最后,搞定!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/578464
推荐阅读
相关标签
  

闽ICP备14008679号