- 在 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)境
解壓
tar –zxvf v10.5_linuxx64_expc.tar.gz
生成了 expc
目錄,切換到該目錄下,執(zhí)行相關(guān)命令
檢查環(huán)境
檢查該環(huán)境是否滿足安裝的需求,這里的安裝包的版本是 10.5.0.7
/home/software/expc/db2prereqcheck -v 10.5.0.7
如果檢查出,環(huán)境不滿足,則需要安裝相應(yīng)的包,比如:
Requirement not matched for DB2 database "Server" with pureScale feature . Version: "10.5.0.7".
Summary of prerequisites that are not met on the current system:
DBT3507E The db2prereqcheck utility failed to find the following package or file: "kernel-source".
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".
上面提示 kernel-source、gcc-c++、cpp 不滿足安裝條件,先安裝上述軟件
zypper install kernel-source
zypper install gcc-c++
zypper install cpp
安裝完成,再執(zhí)行 db2prereqcheck 檢查,最終輸出如下,才能執(zhí)行安裝
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 |
輸入下列命令:
groupadd -g 999 db2iadm1
groupadd -g 998 db2fsdm1
groupadd -g 997 dasadm1
為每個組創(chuàng)建用戶:
useradd -u 1004 -g db2iadm1 -m -d /home/db2inst1 db2inst1
useradd -u 1003 -g db2fsdm1 -m -d /home/db2fenc1 db2fenc1
useradd -u 1002 -g dasadm1 -m -d /home/dasusr1 dasusr1
設(shè)置初始密碼:
passwd db2inst1
passwd db2fenc1
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í)行安裝
linux-rrkj:/home/software/expc/db2_install
DBI1324W Support of the db2_install command is deprecated.
Default directory for installation of products - /opt/ibm/db2/V10.5
***********************************************************
Install into default directory (/opt/ibm/db2/V10.5) ? [yes/no]
期間需要確認(rèn)安裝位置,輸入 yes 繼續(xù)
安裝完成后,輸出如下:
The execution completed successfully.
For more information see the DB2 installation log at
"/tmp/db2_install.log.26071".
默認(rèn)安裝目錄為 /opt/ibm/db2/V10.5 ,該 tmp 目錄下,存儲的是日志文件
安裝 license
license 文件在解壓包目錄 /home/software/expc/db2/license/db2expc_uw.lic
安裝 license,命令如下:
linux-rrkj:~ # /opt/ibm/db2/V10.5/adm/db2licm -a /home/software/expc/db2/license/db2expc_uw.lic
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/V10.5/license/en_US.iso88591"
查看授權(quán)信息
linux-rrkj:~ # /opt/ibm/db2/V10.5/adm/db2licm -l
Product name: "DB2 Express-C"
License type: "Unwarranted"
Expiry date: "Permanent"
Product identifier: "db2expc"
Version information: "10.5"
Max number of CPUs: "2"
Max amount of memory (GB): "16"
Enforcement policy: "Soft Stop"
使用 db2icrt 創(chuàng)建實例
/opt/IBM/db2/V10.5/instance/db2icrt -p 50001 -u db2fenc1 db2inst1
其中,-p 制定了服務(wù)器端口號,不指定默認(rèn)是 50000。
waylau:~ # /opt/ibm/db2/V10.5/instance/db2icrt -p 50001 -u db2fenc1 db2inst1
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.3207".
DBI1070I Program db2icrt completed successfully.
問題處理
可能會出現(xiàn)如下問題:
linux-rrkj:~ # /opt/ibm/db2/V10.5/instance/db2icrt -p 50001 -u db2fenc1 db2inst1
DBI1446I The db2icrt command is running.
DB2 installation is being initialized.
The host name "linux-rrkj" is invalid. Specify a valid host name.
A major error occurred during the execution that caused this program to
terminate prematurely. If the problem persists, contact your technical service
representative.
For more information see the DB2 installation log at "/tmp/db2icrt.log.21212".
DBI1264E This program failed. Errors encountered during execution were
written to the installation log file. Program name:
db2icrt. Log file name: /tmp/db2icrt.log.21212.
Explanation:
This message is returned when some processes and operations have failed.
Detailed information about the error was written to the log file.
User response:
Contact IBM support to get assistance in resolving this issue. Keep the
log file intact as this file is an important reference for IBM support.
解決方法:
設(shè)置主機(jī)名稱,比如,本例為 waylau.com
linux-rrkj:~ # hostname waylau.com
linux-rrkj:~ # vi /etc/hosts
在 hosts 中添加一個
127.0.0.1 waylau.com
::1 waylau.com
修改 HOSTNAME 為 waylau.com
linux-rrkj:~ # vi /etc/HOSTNAME
設(shè)置數(shù)據(jù)庫實例自動啟動
設(shè)置數(shù)據(jù)庫實例 db2inst1 自動啟動,執(zhí)行
waylau:~ # /opt/ibm/db2/V10.5/instance/db2iauto -on db2inst1
驗證安裝
- 作為具有 SYSADM 權(quán)限的用戶登錄系統(tǒng)(這里指 db2inst1)。
- 輸入 db2start 命令來啟動數(shù)據(jù)庫管理器。
-
輸入 db2sampl 命令來創(chuàng)建 SAMPLE 數(shù)據(jù)庫。處理此命令可能要花幾分鐘。沒有完成消息;當(dāng)返回命令提示符時,該過程完成。創(chuàng)建 SAMPLE 數(shù)據(jù)庫時,該數(shù)據(jù)庫自動以數(shù)據(jù)庫別名 SAMPLE 進(jìn)行編目。
-
連接至 SAMPLE 數(shù)據(jù)庫,檢索所有在部門 20 工作的職員的列表,然后重置數(shù)據(jù)庫連接。從命令行處理器 (CLP) 中輸入下列命令:
connect to sample
select * from staff where dept = 20
connect reset
輸出應(yīng)該類似于以下內(nèi)容:
db2inst1@waylau:~> db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 10.5.7
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => connect to sample
Database Connection Information
Database server = DB2/LINUXX8664 10.5.7
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
db2 => select * from staff where dept = 20
ID NAME DEPT JOB YEARS SALARY COMM
------ --------- ------ ----- ------ --------- ---------
10 Sanders 20 Mgr 7 98357.50 -
20 Pernal 20 Sales 8 78171.25 612.45
80 James 20 Clerk - 43504.60 128.20
190 Sneider 20 Clerk 8 34252.75 126.50
4 record(s) selected.
db2 => connect reset
DB20000I The SQL command completed successfully.
db2 => terminate
DB20000I The TERMINATE command completed successfully.
db2 => quit
DB20000I The QUIT command completed successfully.
停止數(shù)據(jù)庫
db2inst1@waylau:~> db2stop
SQL1064N DB2STOP processing was successful.
更多建議: