Oracle 12c Sharding學習(二)-安裝
這裡我使用三臺虛擬機器來完成Sharding的安裝。主要是Sharding-Catalog,Shard1和Shard2。
安裝步驟如下:
1.先在三臺Linux主機上安裝Oracle資料庫軟體,注意選擇只安裝軟體(install database software only)
建立安裝目錄
[root@localhost ~]# mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
[root@localhost ~]# chown -R oracle:oinstall /u01
[root@localhost ~]# chmod -R 775 /u01
安裝Oracle Database軟體,在安裝的過程中選擇install database software only,其餘都和安裝單機版資料庫一致。

2.在sharding-catalog主機上安裝GSM軟體
安裝過程如下面截圖所示:
3.在sharding-catalog上建立資料庫(Shard Catalog Database)
4.主機上的Oracle共享管理和路由層的建立
4.1 設定 catalog database 環境和啟動監聽
[oracle@sharding-catalog ~]$ . oraenv ORACLE_SID = [oracle] ? scat The Oracle base remains unchanged with value /u01/app/oracle [oracle@sharding-catalog ~]$ lsnrctl start LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 07-SEP-2018 16:08:58 Copyright (c) 1991, 2016, Oracle.All rights reserved. Starting /u01/app/oracle/product/12.2.0.1/db_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 12.2.0.1.0 - Production Log messages written to /u01/app/oracle/diag/tnslsnr/sharding-catalog/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sharding-catalog)(PORT=1521))) Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) STATUS of the LISTENER ------------------------ AliasLISTENER VersionTNSLSNR for Linux: Version 12.2.0.1.0 - Production Start Date07-SEP-2018 16:08:58 Uptime0 days 0 hr. 0 min. 0 sec Trace Leveloff SecurityON: Local OS Authentication SNMPOFF Listener Log File/u01/app/oracle/diag/tnslsnr/sharding-catalog/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sharding-catalog)(PORT=1521))) The listener supports no services The command completed successfully
4.2 調整open_links和open_links_per_instance引數
SQL> show parameter open NAMETYPEVALUE ------------------------------------ ----------- ------------------------------ open_cursorsinteger300 open_linksinteger4 open_links_per_instanceinteger4 read_only_open_delayedbooleanFALSE session_max_open_filesinteger10 SQL> alter system set open_links=16 scope=spfile; System altered. SQL> alter system set open_links_per_instance=16 scope=spfile; System altered. SQL> shutdown immediate; SQL> startup
4.3在scat資料庫上授予相關角色和許可權
SQL> alter user gsmcatuser account unlock; SQL> alter user gsmcatuser identified by welcome1; SQL> create user mysdbadmin identified by welcome1; SQL> grant connect, create session, gsmadmin_role to mysdbadmin; SQL> grant inherit privileges on user SYS to GSMADMIN_INTERNAL;
4.4連線sharding-catalog主機,並使用GDSCTL建立shard catalog,並配置遠端排程代理程式
[oracle@sharding-catalog ~]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/gsm_1/ [oracle@sharding-catalog ~]$ export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin [oracle@sharding-catalog ~]$ gdsctl GDSCTL: Version 12.2.0.1.0 - Production on Fri Sep 07 16:26:02 CST 2018 Copyright (c) 2011, 2016, Oracle.All rights reserved. Welcome to GDSCTL, type "help" for information. Warning: current GSM name is not set automatically because gsm.ora contains zero or several GSM entries. Use "setgsm" command to set GSM for the session. Current GSM is set to GSMORA GDSCTL>create shardcatalog -database sharding-catalog:1521:scat -chunks 12 -user mysdbadmin/welcome1 -sdb orasdb -region region1, region2 Catalog is created
4.5建立和啟動shard director,設定作業系統憑證(credentials)
GDSCTL>add gsm -gsm sharddirector1 -listener 1522 -pwd welcome1 -catalog sharding-catalog:1521:scat -region region1 GSM successfully added GDSCTL>start gsm -gsm sharddirector1 GSM is started successfully GDSCTL>add credential -credential region1_cred -osaccount oracle -ospassword oracle The operation completed successfully
4.6連線catalog database scat,設定排程埠和密碼
[oracle@sdb1 ~]$ . oraenv ORACLE_SID = [scat] ? scat The Oracle base remains unchanged with value /u01/app/oracle [oracle@sdb1 ~]$ sqlplus / as sysdba SQL> exec DBMS_XDB.sethttpport(8080); SQL> commit; SQL> exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('welcome1'); SQL> alter system register;
4.7連線每一個分片主機,在上面註冊遠端排程程式代理。並建立資料庫目錄和fast_recovery_area
[root@sharding-catalog gsm_1]# ssh oracle@shard1 oracle@shard1's password: Last failed login: Fri Sep7 16:36:09 CST 2018 from 192.168.56.141 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Fri Sep7 16:35:07 2018 from 192.168.56.141 [oracle@shard1 ~]$ schagent -start Scheduler agent started using port 57133 [oracle@shard1 ~]$ schagent -status Agent running with PID 6878 Agent_version:12.2.0.1.2 Running_time:00:00:13 Total_jobs_run:0 Running_jobs:0 Platform:Linux ORACLE_HOME:/u01/app/oracle/product/12.2.0.1/db_1 ORACLE_BASE:/u01/app/oracle Port:57133 Host:shard1 [oracle@shard1 ~]$ echo welcome1 | schagent -registerdatabase sharding-catalog 8080 Agent Registration Password ? Oracle Scheduler Agent Registration for 12.2.0.1.2 Agent Agent Registration Successful! [oracle@shard1 ~]$ mkdir /u01/app/oracle/oradata [oracle@shard1 ~]$ mkdir /u01/app/oracle/fast_recovery_area [root@sharding-catalog gsm_1]# ssh oracle@shard2 oracle@shard2's password: Last login: Fri Sep7 16:45:51 2018 from 192.168.56.141 [oracle@shard2 ~]$ schagent -start Scheduler agent started using port 32779 [oracle@shard2 ~]$ schagent -status Agent running with PID 6227 Agent_version:12.2.0.1.2 Running_time:00:00:06 Total_jobs_run:0 Running_jobs:0 Platform:Linux ORACLE_HOME:/u01/app/oracle/product/12.2.0.1/db_1 ORACLE_BASE:/u01/app/oracle Port:32779 Host:shard2 [oracle@shard2 ~]$ echo welcome1 | schagent -registerdatabase sharding-catalog 8080 Agent Registration Password ? Oracle Scheduler Agent Registration for 12.2.0.1.2 Agent Agent Registration Successful! [oracle@shard2 ~]$ mkdir /u01/app/oracle/oradata [oracle@shard2 ~]$ mkdir /u01/app/oracle/fast_recovery_area
5.部署SDB
5.1準備
[oracle@sharding-catalog ~]$ export ORACLE_BASE=/u01/app/oracle [oracle@sharding-catalog ~]$ export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/gsm_1/ [oracle@sharding-catalog ~]$ export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin [oracle@sharding-catalog ~]$ gdsctl GDSCTL: Version 12.2.0.1.0 - Production on Fri Sep 07 16:50:44 CST 2018 Copyright (c) 2011, 2016, Oracle.All rights reserved. Welcome to GDSCTL, type "help" for information. Current GSM is set to SHARDDIRECTOR1 GDSCTL> GDSCTL>set gsm -gsm sharddirector1 GDSCTL>connect mysdbadmin/welcome1 Catalog connection is established GDSCTL>add shardgroup -shardgroup primary_shardgroup -deploy_as primary -region region1 The operation completed successfully GDSCTL>create shard -shardgroup primary_shardgroup -destination shard1 -credential region1_cred -sys_password welcome1 The operation completed successfully DB Unique Name: sh1 GDSCTL>create shard -shardgroup primary_shardgroup -destination shard2 -credential region1_cred -sys_password welcome1 The operation completed successfully DB Unique Name: sh2 GDSCTL>config shard NameShard GroupStatusStateRegionAvailability -------------------------------------------- sh1primary_shardgroupUnoneregion1- sh2primary_shardgroupUnoneregion1-
5.2部署
GDSCTL>deploy deploy: examining configuration... deploy: deploying primary shard 'sh1' ... deploy: network listener configuration successful at destination 'shard1' deploy: starting DBCA at destination 'shard1' to create primary shard 'sh1' ... deploy: deploying primary shard 'sh2' ... deploy: network listener configuration successful at destination 'shard2' deploy: starting DBCA at destination 'shard2' to create primary shard 'sh2' ... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: waiting for 2 DBCA primary creation job(s) to complete... deploy: DBCA primary creation job succeeded at destination 'shard1' for shard 'sh1' deploy: DBCA primary creation job succeeded at destination 'shard2' for shard 'sh2' deploy: requesting Data Guard configuration on shards via GSM deploy: shards configured successfully The operation completed successfully
部署的過程會在shard主機上靜默使用dbca程式,建立shard資料庫,所以我們可以登陸到shard主機上檢視dbca日誌,如下所示:
[oracle@shard1 dbca]$ tail -200f silent.log_2018-09-07_04-54-22-PM [ 2018-09-07 16:54:33.928 CST ] Copying database files DBCA_PROGRESS : 1% DBCA_PROGRESS : 2% DBCA_PROGRESS : 16% DBCA_PROGRESS : 30% [ 2018-09-07 16:56:04.451 CST ] Creating and starting Oracle instance DBCA_PROGRESS : 32% DBCA_PROGRESS : 36% DBCA_PROGRESS : 40% DBCA_PROGRESS : 44% DBCA_PROGRESS : 45% DBCA_PROGRESS : 48% DBCA_PROGRESS : 50% [ 2018-09-07 16:57:51.528 CST ] Completing Database Creation DBCA_PROGRESS : 51% DBCA_PROGRESS : 52% DBCA_PROGRESS : 53% DBCA_PROGRESS : 56% DBCA_PROGRESS : 59% DBCA_PROGRESS : 60% [ 2018-09-07 16:59:33.584 CST ] Executing Post Configuration Actions DBCA_PROGRESS : 90% [ 2018-09-07 16:59:33.584 CST ] Running Custom Scripts DBCA_PROGRESS : 100% [ 2018-09-07 17:01:09.900 CST ] Database creation complete. For details check the logfiles at: /u01/app/oracle/cfgtoollogs/dbca/sh1. Database Information: Global Database Name:sh1 System Identifier(SID):sh1
5.3 驗證安裝結果
GDSCTL>status gsm AliasSHARDDIRECTOR1 Version12.2.0.1.0 Start Date07-SEP-2018 16:32:41 Trace Leveloff Listener Log File/u01/app/oracle/diag/gsm/sharding-catalog/sharddirector1/alert/log.xml Listener Trace File/u01/app/oracle/diag/gsm/sharding-catalog/sharddirector1/trace/ora_12204_140704565936512.trc Endpoint summary(ADDRESS=(HOST=sharding-catalog)(PORT=1522)(PROTOCOL=tcp)) GSMOCI Version2.2.1 MastershipY Connected to GDS catalogY Process Id12207 Number of reconnections0 Pending tasks.Total0 Tasks inprocess. Total0 Regional MastershipTRUE Total messages published2 Time Zone+08:00 Orphaned Buddy Regions: None GDS regionregion1