Trong hướng dẫn này chúng ta sẽ tìm hiểu về cách cấu hình Oracle network, listener và tnsnames, chúng ta có 2 server với thông tin được mô tả như sau:
Items | Primary – SRV1 | Standby – SRV2 |
hostname | srv1 | srv2 |
ip | 192.168.1.11 | 192.168.1.12 |
db name | duodb | duodb |
instance_name | duodb | duodb |
db_unique_name | duodb | stand |
version DB | 19.3 | 19.3 |
DB_HOME | /u01/app/oracle/ product/19.3.0/dbhome_1 | /u01/app/oracle/ product/19.3.0/dbhome_1 |
DB_BASE | /u01/app/oracle | /u01/app/oracle |
global database name | srv1.localdomain | srv2.localdomain |
Và nhiệm vụ của chúng ta là cấu hình cho chúng có thể nói chuyện được với nhau: ping, tnsping
Đặt hostname trên cả 2 host và cấu hình /etc/hosts:
trên SRV1:
hostnamectl set-hostname srv1.localdomain
trên SRV2:
hostnamectl set-hostname srv2.localdomain
Thêm vào cuối file hosts trên cả 2 server theo thông tin bên dưới:
vi /etc/hosts 192.168.1.11 srv1.localdomain srv1 192.168.1.12 srv2.localdomain srv2
Tắt firewall trên cả Source và Target (quan trọng nếu không sẽ không tnsping được) (sử dụng user root)
systemctl stop firewalld.service systemctl disable firewalld.service
SRV1: mở database lên và thực hiện lệnh cấu hình net cho DB (open db)
netmgr
trong mục Listener thực hiện cài đặt thông tin như hình bên dưới:
Trong mục Service Naming thực hiện cài đặt cấu hình như bên dưới:
tiếp theo vào File trên cửa sổ này và lưu lại cấu hình rồi thoát ra ngoài.
SRV1: Xem thông tin về tnsnames và listener vừa tạo ra:
cd $ORACLE_HOME/network/admin cat tnsnames.ora
# kết quả file:
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. DUODB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = duodb.localdomain) ) ) STAND = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv2.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stand.localdomain) ) ) LISTENER_DUODB = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521))
File listener:
[oracle@srv1 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = duodb.localdomain) (ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1) (SID_NAME = duodb) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
SRV2: Tương tự như vậy chúng ta cũng có thông tin trên srv2 như sau:
netmgr
Kiểm tra nội dung file listener.ora và tnsnames.ora trên SRV2:
File listener.ora:
[oracle@srv2 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = stand.localdomain) (ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1) (SID_NAME = stand) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = srv2.localdomain)(PORT = 1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
File tnsname.ora:
[oracle@srv2 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. DUODB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = duodb.localdomain) ) ) STAND = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv2.localdomain)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stand.localdomain) ) ) LISTENER_DUODB = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521))
TIẾN HÀNH PING VÀ TNSPING:
host ping:
[oracle@srv2 admin]$ ping srv1 -c 5 [oracle@srv2 admin]$ ping srv1.localdomain -c 5 [oracle@srv1 admin]$ ping srv2 -c 5 [oracle@srv1 admin]$ ping srv2.localdomain -c 5
# kết quả ping:
PING srv1.localdomain (192.168.1.11) 56(84) bytes of data. 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=1 ttl=64 time=0.636 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=2 ttl=64 time=1.03 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=3 ttl=64 time=1.04 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=4 ttl=64 time=0.945 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=5 ttl=64 time=0.264 ms --- srv1.localdomain ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4068ms rtt min/avg/max/mdev = 0.264/0.783/1.041/0.300 ms PING srv1.localdomain (192.168.1.11) 56(84) bytes of data. 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=1 ttl=64 time=0.395 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=2 ttl=64 time=1.06 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=3 ttl=64 time=0.301 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=4 ttl=64 time=0.301 ms 64 bytes from srv1.localdomain (192.168.1.11): icmp_seq=5 ttl=64 time=0.949 ms --- srv1.localdomain ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4154ms rtt min/avg/max/mdev = 0.301/0.601/1.063/0.335 ms PING srv2.localdomain (192.168.1.12) 56(84) bytes of data. 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=1 ttl=64 time=0.544 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=2 ttl=64 time=0.628 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=3 ttl=64 time=0.428 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=4 ttl=64 time=0.734 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=5 ttl=64 time=1.23 ms --- srv2.localdomain ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4092ms rtt min/avg/max/mdev = 0.428/0.714/1.238/0.281 ms PING srv2.localdomain (192.168.1.12) 56(84) bytes of data. 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=1 ttl=64 time=0.481 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=2 ttl=64 time=1.63 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=3 ttl=64 time=1.35 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=4 ttl=64 time=1.09 ms 64 bytes from srv2.localdomain (192.168.1.12): icmp_seq=5 ttl=64 time=0.686 ms --- srv2.localdomain ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4049ms rtt min/avg/max/mdev = 0.481/1.049/1.638/0.424 ms
TNSPING:
Bật listener trên cả 2 server:
lsnrctl start
Tiến hành tnsping:
[oracle@srv1 admin]$ tnsping duodb [oracle@srv1 admin]$ tnsping stand [oracle@srv2 admin]$ tnsping duodb [oracle@srv2 admin]$ tnsping stand
# kết quả tnsping:
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 04-MAY-2024 22:44:39 Copyright (c) 1997, 2019, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = duodb.localdomain))) OK (0 msec) TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 04-MAY-2024 22:45:01 Copyright (c) 1997, 2019, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv2.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stand.localdomain))) OK (0 msec) TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 04-MAY-2024 22:45:30 Copyright (c) 1997, 2019, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv1.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = duodb.localdomain))) OK (10 msec) TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 04-MAY-2024 22:45:34 Copyright (c) 1997, 2019, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = srv2.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stand.localdomain))) OK (0 msec)
Như vậy là kết quả ping đã thành công trên cả 2 srv.