DB2 linux

2021-08-16 09:27 更新
  • 在 openSUSE 上安裝 DB2 服務(wù)器
    • 環(huán)境
    • 下載 DB2 Express-C
    • 解壓、檢查環(huán)境
      • 解壓
      • 檢查環(huán)境
    • 創(chuàng)建用戶和組
      • 創(chuàng)建用戶和組
      • 解釋:
      • 用戶標(biāo)識限制
    • 執(zhí)行 db2_install 安裝 DB2
    • 安裝 license
    • 使用 db2icrt 創(chuàng)建實例
      • 問題處理
      • 設(shè)置數(shù)據(jù)庫實例自動啟動
    • 驗證安裝
    • 參考引用

    在 openSUSE 上安裝 DB2 服務(wù)器

    環(huán)境

    本機(jī)演示的環(huán)境為:

    • 操作系統(tǒng): openSUSE Leap 42.1
    • 處理器: 英特爾 第三代酷睿 i3-3110M @ 2.40GHz 雙核
    • 內(nèi)存 : 4 GB
    • DB2: Express-C 10.5(64-bit)

    下載 DB2 Express-C

    DB2 Express-C 具有 DB2 所有版本一樣的核心功能,且免費(fèi),用來學(xué)習(xí) DB2 足夠了。

    下載地址:http://www-01.ibm.com/software/data/db2/express-c/download.html

    本例安裝包為:v10.5_linuxx64_expc.tar.gz

    注: 下載前,需要提供 IBM 賬號,可以免費(fèi)注冊。

    解壓、檢查環(huán)境

    解壓


    1. tar zxvf v10.5_linuxx64_expc.tar.gz

    生成了 expc 目錄,切換到該目錄下,執(zhí)行相關(guān)命令

    檢查環(huán)境

    檢查該環(huán)境是否滿足安裝的需求,這里的安裝包的版本是 10.5.0.7


    1. /home/software/expc/db2prereqcheck -v 10.5.0.7

    如果檢查出,環(huán)境不滿足,則需要安裝相應(yīng)的包,比如:


    1. Requirement not matched for DB2 database "Server" with pureScale feature . Version: "10.5.0.7".
    2. Summary of prerequisites that are not met on the current system:
    3. DBT3507E The db2prereqcheck utility failed to find the following package or file: "kernel-source".
    4. DBT3507E The db2prereqcheck utility failed to find the following package or file: "gcc-c++".
    5. DBT3507E The db2prereqcheck utility failed to find the following package or file: "cpp".

    上面提示 kernel-source、gcc-c++、cpp 不滿足安裝條件,先安裝上述軟件


    1. zypper install kernel-source
    2. zypper install gcc-c++
    3. zypper install cpp

    安裝完成,再執(zhí)行 db2prereqcheck 檢查,最終輸出如下,才能執(zhí)行安裝


    1. DBT3533I The db2prereqcheck utility has confirmed that all installation prerequisites were met.

    創(chuàng)建用戶和組

    創(chuàng)建用戶和組

    需用具有 root 用戶權(quán)限手動創(chuàng)建下列用戶和組:

    用戶 示例用戶名 示例組名
    實例所有者 db2inst1 db2iadm1
    受防護(hù)的用戶 db2fenc1 db2fsdm1
    DB2 管理服務(wù)器用戶 dasusr1 dasadm1

    輸入下列命令:

    1. groupadd -g 999 db2iadm1
    2. groupadd -g 998 db2fsdm1
    3. groupadd -g 997 dasadm1

    為每個組創(chuàng)建用戶:

    1. useradd -u 1004 -g db2iadm1 -m -d /home/db2inst1 db2inst1
    2. useradd -u 1003 -g db2fsdm1 -m -d /home/db2fenc1 db2fenc1
    3. useradd -u 1002 -g dasadm1 -m -d /home/dasusr1 dasusr1

    設(shè)置初始密碼:

    1. passwd db2inst1
    2. passwd db2fenc1
    3. passwd dasusr1

    解釋:

    • Instance owner(實例所有者):DB2 實例 被 Instance owner 創(chuàng)建在 home 目錄。這個 用戶 ID 控制所有 DB2 進(jìn)程、擁有的所有文件系統(tǒng)和包含在實例的數(shù)據(jù)庫使用的設(shè)備。默認(rèn)用戶名稱是 db2inst1 和默認(rèn)分組是 db2iadm1。
    • Fenced user(受防護(hù)的用戶):主要負(fù)責(zé)用戶自定義函數(shù)(user defined function)和存儲過程(stored precedure)。創(chuàng)建這個用戶的好處是,當(dāng)一個自定義函數(shù)發(fā)生內(nèi)存泄漏的問題,至多影響到這些自定義函數(shù)和存儲過程。而影響不到整個數(shù)據(jù)庫管理系統(tǒng)。所以,如果你不需要過多的安全需要,比如在測試環(huán)境,可以將 Instance owner 用戶作為 Fenced user。 如果你的系統(tǒng)有很多自定義函數(shù)或者存儲過程的話,最好創(chuàng)建一個跟實例名不是同名的,這里默認(rèn)創(chuàng)建一個名叫 db2fenc1 的用戶,默認(rèn)分組 db2fadm1
    • DB2 administration server user(DB2 管理服務(wù)器用戶):DB2 管理服務(wù)器用戶的用戶標(biāo)識用于在系統(tǒng)上運(yùn)行 DB2 管理服務(wù)器 (DAS)。缺省用戶為 dasusr1,缺省組為 dasadm1。每臺計算機(jī)上只能有一個 DAS。一個 DAS 維護(hù)一個或多個數(shù)據(jù)庫實例,包括屬于不同安裝的數(shù)據(jù)庫實例。DAS 可以維護(hù)其發(fā)行版級別低于 DAS 發(fā)行版級別的數(shù)據(jù)庫實例。但是,對于其發(fā)行版級別高于 DAS 發(fā)行版級別的數(shù)據(jù)庫實例,DAS 必須遷移到更高級別。DAS 發(fā)行版級別必須不低于所維護(hù)的任何數(shù)據(jù)庫實例的發(fā)行版級別。注意, V9.7 中已經(jīng)不推薦使用 DAS,在以后的發(fā)行版中可能會將其除去。推薦使用 IBM? Data Studio 和 IBM Optim? 工具來代替控制中心工具。有關(guān)詳細(xì)信息,請參閱 不推薦使用控制中心工具。推薦使用采用安全 shell (SSH) 協(xié)議的軟件程序進(jìn)行遠(yuǎn)程管理。例如,可以在 Data Studio 配置工作臺以運(yùn)行 SQL 語句、實用程序和命令,或使用安全 shell (SHH) 協(xié)議來瀏覽和訪問遠(yuǎn)程服務(wù)器上的文件。

    用戶標(biāo)識限制

    用戶標(biāo)識具有下列限制和要求:

    • 必須具有除 guests、admins、users 和 local 之外的主組
    • 可以包含小寫字母 (a-z)、數(shù)字 (0-9) 和下劃線字符 ( _ )
    • 長度不能超過八個字符
    • 不能以 IBM、SYS、SQL 或數(shù)字開頭
    • 不能是 DB2 保留字(USERS、ADMINS、GUESTS、PUBLIC 或 LOCAL)或 SQL 保留字
    • 不能使用任何具有 root 用戶特權(quán)的用戶標(biāo)識作為 DB2 實例標(biāo)識、DAS 標(biāo)識或受防護(hù)標(biāo)識
    • 不能包含重音字符
    • 如果已指定現(xiàn)有用戶標(biāo)識,而不是創(chuàng)建新用戶標(biāo)識,那么確保該用戶標(biāo)識:
      • 未鎖定
      • 不具有到期的密碼

    執(zhí)行 db2_install 安裝 DB2

    執(zhí)行安裝


    1. linux-rrkj:/home/software/expc/db2_install
    2. DBI1324W Support of the db2_install command is deprecated.
    3. Default directory for installation of products - /opt/ibm/db2/V10.5
    4. ***********************************************************
    5. Install into default directory (/opt/ibm/db2/V10.5) ? [yes/no]

    期間需要確認(rèn)安裝位置,輸入 yes 繼續(xù)

    安裝完成后,輸出如下:

    1. The execution completed successfully.
    2. For more information see the DB2 installation log at
    3. "/tmp/db2_install.log.26071".

    默認(rèn)安裝目錄為 /opt/ibm/db2/V10.5 ,該 tmp 目錄下,存儲的是日志文件

    安裝 license

    license 文件在解壓包目錄 /home/software/expc/db2/license/db2expc_uw.lic

    安裝 license,命令如下:

    1. linux-rrkj:~ # /opt/ibm/db2/V10.5/adm/db2licm -a /home/software/expc/db2/license/db2expc_uw.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"

    查看授權(quán)信息


    1. linux-rrkj:~ # /opt/ibm/db2/V10.5/adm/db2licm -l
    2. Product name: "DB2 Express-C"
    3. License type: "Unwarranted"
    4. Expiry date: "Permanent"
    5. Product identifier: "db2expc"
    6. Version information: "10.5"
    7. Max number of CPUs: "2"
    8. Max amount of memory (GB): "16"
    9. Enforcement policy: "Soft Stop"

    使用 db2icrt 創(chuàng)建實例

    /opt/IBM/db2/V10.5/instance/db2icrt -p 50001 -u db2fenc1 db2inst1

    其中,-p 制定了服務(wù)器端口號,不指定默認(rèn)是 50000。


    1. waylau:~ # /opt/ibm/db2/V10.5/instance/db2icrt -p 50001 -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.3207".
    24. DBI1070I Program db2icrt completed successfully.

    問題處理

    可能會出現(xiàn)如下問題:

    1. linux-rrkj:~ # /opt/ibm/db2/V10.5/instance/db2icrt -p 50001 -u db2fenc1 db2inst1
    2. DBI1446I The db2icrt command is running.
    3. DB2 installation is being initialized.
    4. The host name "linux-rrkj" is invalid. Specify a valid host name.
    5. A major error occurred during the execution that caused this program to
    6. terminate prematurely. If the problem persists, contact your technical service
    7. representative.
    8. For more information see the DB2 installation log at "/tmp/db2icrt.log.21212".
    9. DBI1264E This program failed. Errors encountered during execution were
    10. written to the installation log file. Program name:
    11. db2icrt. Log file name: /tmp/db2icrt.log.21212.
    12. Explanation:
    13. This message is returned when some processes and operations have failed.
    14. Detailed information about the error was written to the log file.
    15. User response:
    16. Contact IBM support to get assistance in resolving this issue. Keep the
    17. log file intact as this file is an important reference for IBM support.

    解決方法:

    設(shè)置主機(jī)名稱,比如,本例為 waylau.com

    1. linux-rrkj:~ # hostname waylau.com
    2. linux-rrkj:~ # vi /etc/hosts

    在 hosts 中添加一個

    1. 127.0.0.1 waylau.com
    2. ::1 waylau.com

    修改 HOSTNAME 為 waylau.com

    1. linux-rrkj:~ # vi /etc/HOSTNAME

    設(shè)置數(shù)據(jù)庫實例自動啟動

    設(shè)置數(shù)據(jù)庫實例 db2inst1 自動啟動,執(zhí)行

    1. waylau:~ # /opt/ibm/db2/V10.5/instance/db2iauto -on db2inst1

    驗證安裝

    1. 作為具有 SYSADM 權(quán)限的用戶登錄系統(tǒng)(這里指 db2inst1)。
    2. 輸入 db2start 命令來啟動數(shù)據(jù)庫管理器。
    3. 輸入 db2sampl 命令來創(chuàng)建 SAMPLE 數(shù)據(jù)庫。處理此命令可能要花幾分鐘。沒有完成消息;當(dāng)返回命令提示符時,該過程完成。創(chuàng)建 SAMPLE 數(shù)據(jù)庫時,該數(shù)據(jù)庫自動以數(shù)據(jù)庫別名 SAMPLE 進(jìn)行編目。

    4. 連接至 SAMPLE 數(shù)據(jù)庫,檢索所有在部門 20 工作的職員的列表,然后重置數(shù)據(jù)庫連接。從命令行處理器 (CLP) 中輸入下列命令:

    1. connect to sample
    2. select * from staff where dept = 20
    3. connect reset

    輸出應(yīng)該類似于以下內(nèi)容:

    1. db2inst1@waylau:~> db2
    2. (c) Copyright IBM Corporation 1993,2007
    3. Command Line Processor for DB2 Client 10.5.7
    4. You can issue database manager commands and SQL statements from the command
    5. prompt. For example:
    6. db2 => connect to sample
    7. db2 => bind sample.bnd
    8. For general help, type: ?.
    9. For command help, type: ? command, where command can be
    10. the first few keywords of a database manager command. For example:
    11. ? CATALOG DATABASE for help on the CATALOG DATABASE command
    12. ? CATALOG for help on all of the CATALOG commands.
    13. To exit db2 interactive mode, type QUIT at the command prompt. Outside
    14. interactive mode, all commands must be prefixed with 'db2'.
    15. To list the current command option settings, type LIST COMMAND OPTIONS.
    16. For more detailed help, refer to the Online Reference Manual.
    17. db2 => connect to sample
    18. Database Connection Information
    19. Database server = DB2/LINUXX8664 10.5.7
    20. SQL authorization ID = DB2INST1
    21. Local database alias = SAMPLE
    22. db2 => select * from staff where dept = 20
    23. ID NAME DEPT JOB YEARS SALARY COMM
    24. ------ --------- ------ ----- ------ --------- ---------
    25. 10 Sanders 20 Mgr 7 98357.50 -
    26. 20 Pernal 20 Sales 8 78171.25 612.45
    27. 80 James 20 Clerk - 43504.60 128.20
    28. 190 Sneider 20 Clerk 8 34252.75 126.50
    29. 4 record(s) selected.
    30. db2 => connect reset
    31. DB20000I The SQL command completed successfully.
    32. db2 => terminate
    33. DB20000I The TERMINATE command completed successfully.
    34. db2 => quit
    35. DB20000I The QUIT command completed successfully.

    停止數(shù)據(jù)庫

    1. db2inst1@waylau:~> db2stop
    2. SQL1064N DB2STOP processing was successful.

    參考引用


    以上內(nèi)容是否對您有幫助:
    在線筆記
    App下載
    App下載

    掃描二維碼

    下載編程獅App

    公眾號
    微信公眾號

    編程獅公眾號