# IBM MQ for DB Replication

#### MQ Server Installation

Software Information:

- MQ8: WS\_MQ\_V8.0\_IFR1\_LINUX\_ON\_X86\_64\_I.tar (主程式)
- MQ8: 8.0.0-WS-MQ-LinuxX64-FP0011.tar (更新檔)
- MQ9: IBM\_MQ\_9.2.0.5\_LINUX\_X86-64.tar.gz
- OS: RHEL 6/7/8

System Configuration:

Edit `/etc/sysctl.d/ibmmq.conf`

```
# for MQ
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.shmmax = 268435456
kernel.sem = 500 256000 250 1024
fs.file-max = 524288
net.ipv4.tcp_keepalive_time = 300
kernel.threads-max = 32768
```

Apply the changes

```bash
sysctl -p /etc/sysctl.d/ibmmq.conf
```

Edit /etc/security/limits.conf

```
# for MQ
mqm     hard    nofile  10240
mqm     soft    nofile  10240
```

##### MQ 8 Install

```bash
tar -xf WS_MQ_V8.0_IFR1_LINUX_ON_X86_64_I.tar
cd server
./mqlicense.sh -text_only
rpm -ivh MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm
```

Install MQ8-FP0011

```bash
mkdir FP0011
tar -xzf 8.0.0-WS-MQ-LinuxX64-FP0011.tar.gz -C FP0011
cd FP0011
rpm -ivh MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm
```

##### MQ 9 Install

```bash
tar xzf IBM_MQ_9.2.0.5_LINUX_X86-64.tar.gz
cd MQServer
./mqlicense.sh -text_only
rpm -ivh MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesGSKit-*.rpm
```

> <div>IMPORTANT: READ CAREFULLY</div><div>  
> </div><div>Press Enter to continue viewing the license agreement, or</div><div>enter "1" to accept the agreement, "2" to decline it, "3"</div><div>to print it, "4" to read non-IBM terms, or "99" to go back</div><div>to the previous screen.</div><div>1 &lt;=== Press 1</div>

Install MQ9-FP0031

```bash
mkdir FP0031
tar xzf 9.2.0-IBM-MQ-LinuxX64-FP0031.tar.gz -C FP0031
cd FP0031
rpm -ivh MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm MQSeriesGSKit-*.rpm
```

##### Install Notes

- 預設 MQ 安裝目錄：/opt/mqm
- 如果安裝時，想變更目錄位置，安裝指令改成   
    `rpm --prefix /opt/customLocation -ivh MQSeriesRuntime-*.rpm MQSeriesServer-*.rpm`
- 安裝完成，系統會自動建立帳號 mqm
- 帳號 mqm 的 Home: /var/mqm

##### Post-Installation

RHEL

```bash
su - mqm
vi ~/.bash_profile
```

.bash\_profile:

```bash
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

# Set up environment variables for the user mqm
. /opt/mqm/bin/setmqenv -s
```

Show the MQ version

```
[mqm@dotnetdev ~]$ dspmqver
Name:        WebSphere MQ
Version:     8.0.0.11
Level:       p800-011-181212.1
BuildType:   IKAP - (Production)
Platform:    WebSphere MQ for Linux (x86-64 platform)
Mode:        64-bit
O/S:         Linux 4.18.0-553.40.1.el8_10.x86_64
InstName:    Installation1
InstDesc:
Primary:     No
InstPath:    /opt/mqm
DataPath:    /var/mqm
MaxCmdLevel: 802
LicenseType: Production
```

檢視已安裝的 MQ 元件

```bash
# List the packages installed
rpm -qa | grep MQ

# Detail Information for the packages installed
rpm -qa | grep MQ | xargs rpm -q --info
```

#### Shell Commands

```bash
# Create a queue manager called QMA
crtmqm QMA

# Start the queue manager
strmqm QMA

# Enter MQSC console
runmqsc QMA

> DEFINE QLOCAL (QUEUE1)  # Define a local queue called QUEUE1
> end   # Quit MQSC

# List all running queue managers
dspmq
dspmq -o installation

# Stop the queue manager QMA
endmqm QMA

# Delete a queue manager QMA
dltmqm QMA
```

#### MQSC Commands

```
Display listener status
> dis lsstatus(*)

Display channels status
> dis chstatus(*)

Display a specific channel
> dis chl(CHANNEL-NAME)

Dispaly all queues
> dis q(*)

Start a channel
> start chl(CHANNEL-NAME)

Stop a channel
> stop chl(CHANNEL-NAME)

Reset a channel
> reset chl(CHANNEL-NAME)
```

#### Backup/Restore MQ Configuration

- Queue Manager: BQMREP

Backup MQ Configuration

```bash
su - mqm
dmpmqcfg -m BQMREP -a > /tmp/BQMREP.mqsc
```

Backup Messages (RestartQ 中會記錄 Capture 啟動時要從哪個 LSN 開始, 因此需移轉至新的 MQ)

```bash
dmpmqmsg -m BQMREP -i BWINQCAP.RESTARTQ -f /tmp/BWINQCAP.RESTARTQ.msg
```

Restore MQ Configuration to new server

```bash
crtmqm BQMREP
strmqm BQMREP
runmqsc BQMREP < /tmp/BQMREP.mqsc | tee restore.log
```

Restore Messages to new server

```bash
dmpmqmsg -m BQMREP -o BWINQCAP.RESTARTQ -f /tmp/BWINQCAP.RESTARTQ.msg
```

#### DB2 Instance

建立一個帳號 istq 用來執行資料庫抄寫程序

Create DB2 instance

- 必須安裝 Server Instance (非 Client)，不過不會啟動 Instance，只會用到相關的元件與指令。

```
[root@tycdbsmq01 ~]# /usr/local/bin/db2ls

Install Path                       Level   Fix Pack   Special Install Number   Install Date                  Installer UID
---------------------------------------------------------------------------------------------------------------------
/opt/ibm/db2/V11.1               11.1.4.7        7                            Thu May 22 14:06:25 2025 CST             0

[root@tycdbsmq01 ~]# cd /opt/ibm/db2/V11.1/instance/

[root@tycdbsmq01 instance]# ./db2icrt -s ese -u istq istq
```

Set Environment Variables for MQ

```bash
su - istq
cat <<EOF>> ~/.bash_profile
# For MQ
# Set up environment variables for MQ
. /opt/mqm/bin/setmqenv -p /opt/mqm -l
EOF

```

#### Q &amp; A

##### 2003 (MQRC\_BACKED\_OUT)

> The program encountered a WebSphere MQ error "2003 (MQRC\_BACKED\_OUT)" while issuing the WebSphere MQ command "MQDELETE" on object ...

Solution: MQ 的 LOG files 使用已達設定上限，需要調整設定。

編輯 /var/mqm/qmgrs/{YOUR-MGR-NAME}/qm.ini

```
Log:
   LogPrimaryFiles=5
   LogSecondaryFiles=4

```

調高 LogPrimaryFiles 與 LogSecondaryFiles 數值

這些 LOG 檔案的預設路徑：/var/mqm/log/{YOUR-MGR-NAME}/active

 以下 MQSC 的指令可以用來檢查目前 LOG 的使用率，檢查以下兩個數值，如果其中之一超過 100 以上，要特別注意是否要調高檔案數設定。

- LOGINUSE: The percentage of the primary log space in use for restart recovery at this point in time. A value of 100 or greater indicates the queue manager might have allocated, and be using, secondary log files, probably due to long-lived transactions at this point in time.
- LOGUTIL: A percentage estimate of how well the queue manager workload is contained within the primary log space. If the value is consistently above 100 you might want to investigate whether there are long-lived transactions, or if the number of primary files is not sufficient for the workload.

```bash
runmqsc YOUR-MGR-NAME

> display qmstatus log

AMQ8705I: Display Queue Manager Status Details.
   QMNAME(BQMREP)                          STATUS(RUNNING)
   ARCHLOG( )                              ARCHSZ(0)
   CURRLOG( )                              LOGINUSE(56)
   LOGPATH(/var/mqm/log/BQMREP/active/)    LOGUTIL(62)
   MEDIALOG( )                             MEDIASZ(0)
   RECLOG( )                               RECSZ(27)
   REUSESZ(0)
```