參考:
Oracle 12C Sharding部署和测试
12c新特性-Oracle Sharding简介
1.规划
序号 | 主机名 | 組件 | sid | Oracle_Home | IP | 内存大小 |
---|---|---|---|---|---|---|
1 | gsm1 | shard Director | /u05/../12.2.0/gsm_1 | 192.168.40.135 | 4GB | |
2 | gsm1 | Shard catalog | catadb | /u01/. ./12.2.0/db_1 | 192.168.40.135 | 4GB |
3 | sd1 | shard服务器1 | sh1 | /u01/. ./12.2.0/db_1 | 192.168.40.136 | 4GB |
4 | sd2 | shard服务器2 | sh2 | /u01/. ./12.2.0/db_1 | 192.168.40.137 | 4GB |
2.硬盘划分
序号 | 分区名称 | 大小 | 用途说明 |
---|---|---|---|
1 | /boot | 200MB | 引导分区 |
2 | /tmp | 2G | 临时空间 |
3 | /home | 1G | 所有用户的home目录 |
4 | swap | 8G | 交换分区(物理內存小於8G則 *2 反之 同物理內存 |
5 | / | 39G | 根分区 |
3.禁用防火墙
#关闭firewall:停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
4.安裝基本工具
yum -y install nano vim wget curl net-tools lsof zip unzip
yum -y install perl autoconf autoconf
cd /usr/local/src
wget http://www.rpmfind.net/linux/epel/6/x86_64/Packages/r/rlwrap-0.42-1.el6.x86_64.rpm
rpm -ivh rlwrap-0.42-1.el6.x86_64.rpm
5.linux完整更新(可选项)
yum update -y
6.检查并卸载OpenJDK & 安裝JDK 1.8
#卸载
rpm -qa | grep java
#安装jdk
mkdir /u01/java -p
cd /u01/java/
#上传jdk-8u181-linux-x64.tar.gz
tar -zxvf jdk-8u181-linux-x64.tar.gz
#设置环境变量
vim /etc/profile
在profile中添加如下内容:
#set java environment
JAVA_HOME=/u01/java/jdk1.8.0_181
JRE_HOME=/u01/java/jdk1.8.0_181/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
#让修改生效:
source /etc/profile
#输入java -version查看一下jdk版本信息:
java -version
7.sysctl.conf 配置
grep MemTotal /proc/meminfo
MemTotal: 3861320 kB
#計算方法如下
shmall = 3861320 * 1024 /4096 =965330
shmmax = 3861320 * 1024 *0.9 =3558592512
[root@sd2 ~]# cat /etc/sysctl.conf
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 965330
kernel.shmmax = 3558592512
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
#生效
sysctl -p
8.配置主机名
[root@gsm1 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=gsm1
[root@sd1 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=sd1
[root@sd2 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=sd2
vim /etc/hosts
#增加如下
192.168.40.135 gsm1
192.168.40.136 sd1
192.168.40.137 sd2
9.配置limits.conf
vim /etc/security/limits.conf
#增加如下配置
#最后两行memlock =kernel.shmmax/1024 = 3558592512/1024=3475188
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft nofile 16384
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft memlock 3475188
oracle hard memlock 3475188
10.编辑 /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
#SELINUXTYPE=targeted
SELINUX=permissive
#生效
setenforce Permissive
11.创建用户和组
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
#groupadd -g 54324 backupdba
#groupadd -g 54325 dgdba
#groupadd -g 54326 kmdba
#groupadd -g 54327 asmdba
#groupadd -g 54328 asmoper
#groupadd -g 54329 asmadmin
#groupadd -g 54330 racdba
useradd -u 54321 -g oinstall -G dba,oper oracle
#oracle用户的登录密码,后续登录要用,记着。
echo "123456" | passwd --stdin oracle
#设置密码永不过期
chage -M -1 oracle
chage -l oracle
id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper)
12.配置/dev/shm大小
#验证共享内存是否已正确安装且大小足够
# > SGA+PGA 或 =物理内存*50%
vim /etc/fstab
#修改/dev/shm的大小
修改/etc/fstab的这行: 默认的:
tmpfs /dev/shm tmpfs defaults 0 0
改成:
tmpfs /dev/shm tmpfs defaults,size=4G 0 0
#重新mount /dev/shm使之生效:
mount -o remount /dev/shm
df -h
...
tmpfs 4.0G 0 4.0G 0% /dev/shm
...
13.限制参数修改(可)
vim /etc/pam.d/login
#add
#这是对应64位的
session required /lib64/security/pam_limits.so
#这是对应32位的
#session required /lib/security/pam_limits.so
#修改ulimit:
vim /etc/profile
#添加oracle 用户 limit:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
#生效
source /etc/profile
14.创建目录
mkdir -p /u01/app/oracle/
mkdir -p /u01/tmp/
#mkdir -p /u02/oradata/
#mkdir -p /u03/fra/
mkdir -p /u01/app/oracle/oradata/
mkdir -p /u01/app/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/app/
chown -R oracle:oinstall /u01/tmp/
#chown -R oracle:oinstall /u02/oradata/
#chown -R oracle:oinstall /u03/fra/
chmod -R 775 /u01/app/
chmod -R 775 /u01/tmp/
#chmod -R 775 /u02/oradata/
#chmod -R 775 /u03/fra/
15.安装oracle 12c 依赖包
yum install binutils -y
yum install compat-libcap1 -y
yum install compat-libstdc++-33 -y
yum install compat-libstdc++-33.i686 -y
yum install glibc -y
yum install glibc.i686 -y
yum install glibc-devel -y
yum install glibc-devel.i686 -y
yum install ksh -y
yum install libaio -y
yum install libaio.i686 -y
yum install libaio-devel -y
yum install libaio-devel.i686 -y
yum install libX11 -y
yum install libX11.i686 -y
yum install libXau -y
yum install libXau.i686 -y
yum install libXi -y
yum install libXi.i686 -y
yum install libXtst -y
yum install libXtst.i686 -y
yum install libgcc -y
yum install libgcc.i686 -y
yum install libstdc++ -y
yum install libstdc++.i686 -y
yum install libstdc++-devel -y
yum install libstdc++-devel.i686 -y
yum install libxcb -y
yum install libxcb.i686 -y
yum install make -y
yum install nfs-utils -y
yum install net-tools -y
yum install smartmontools -y
yum install sysstat -y
yum install unixODBC -y
yum install unixODBC-devel -y
yum install gcc gcc-c++ xterm libXp e2fsprogs e2fsprogs-libs elfutils-libelf-devel libXrender -y
yum -y install bc
16.创建scripts 目录及setEnv.sh文件(从此处开始无特别说明都是在oracle用户下操作)
mkdir /home/oracle/scripts
#创建 setEnv.sh 文件 [不同机器上 ORACLE_ 的 HOSTNAME、UNQNAME、SID 不同]
##gsm1
----------------------------------------------------------------------
cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=gsm1
export ORACLE_UNQNAME=catadb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=catadb
export PATH=/usr/sbin:/usr/local/bin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
EOF
=================================================================
##sd1
----------------------------------------------------------------------
cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=sd1
export ORACLE_UNQNAME=sh1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=sh1
export PATH=/usr/sbin:/usr/local/bin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
EOF
=================================================================##sd2
----------------------------------------------------------------------
cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=sd2
export ORACLE_UNQNAME=sh2
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=sh2
export PATH=/usr/sbin:/usr/local/bin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
EOF
=================================================================
#Add a reference to the "setEnv.sh" file at "/home/oracle/.bash_profile" file
echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
#生效
source /home/oracle/.bash_profile
#Create a "start_all.sh" and "stop_all.sh" script
---------------------------------------------------------------
cat > /home/oracle/scripts/start_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbstart $ORACLE_HOME
EOF
---------------------------------------------------------------
cat > /home/oracle/scripts/stop_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbshut $ORACLE_HOME
EOF
=====================================================
chown -R oracle.oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh
17.安装database 软件
export DISPLAY=192.168.0.7:0.0
#安裝oracle 【說明:本次僅安裝軟件】
unzip linuxx64_12201_database.zip
cd database/
./runInstaller
18.创建并启动监听
netca
19.启停说明 【附加】
#编辑 "/etc/oratab" file setting the restart flag for each instance to 'Y'.
catadb:/u01/app/oracle/product/12.2.0.1/db_1:Y
#通过如下脚本启动或停止数据库
/home/oracle//scripts/start_all.sh
/home/oracle//scripts/stop_all.sh
20.安装GDS/GSM软件【gsm1上安裝】
#创建 gds 用户 【root 下操作】
useradd -g oinstall -G dba,oper gds
#gds用户的登录密码,后续登录要用,记着。
echo "123456" | passwd --stdin gds
#设置密码永不过期
chage -M -1 gds
chage -l gds
#创建安装目录
mkdir -p /u05/app/oracle/
chown -R gds:oinstall /u05/app/
chmod -R 775 /u05/app/
mkdir -p /u05/tmp/
chown -R gds:oinstall /u05/tmp/
chmod -R 775 /u05/tmp/
# 查看环境变量
su - gds
vim /home/gds/.bash_profile
source /home/gds/.bash_profile
cat /home/gds/.bash_profile
-------------------------------------------------------------------------
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
ORACLE_BASE=/u05/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.2.0/gsm_1; export ORACLE_HOME
TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN
export PATH=${PATH}:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
export TEMP=/u05/tmp
export TMPDIR=/u05/tmp
umask 022
=================================================================
#開始安裝gsm
export DISPLAY=192.168.0.7:0.0
unzip linuxx64_12201_gsm.zip
cd gsm
./runInstaller
# 安装很简单,一直点 next
21.创建Shard Catalog database (即catadb 實例) -> gsm1 上 oracle 用戶
#在Shard catalog 服务器gsm1 上 创建 non-cdb (即不要勾選 create as container database)
#字符集:AL32UTF8,National character set 选择 AL16UTF。创建过程与普通数据库相同
#选择File System,选择Oracle-Managed Files(OMF)
#选择Specify Fast Recovery Area ,Enable archiving
#不要选择Configure EnterpriseManager(EM) database express
dbca
22.配置GSM/Shard director -> gsm1 上 oracle 用戶
#检查资料库是否存在GSM用户(必备条件)
#12c后新增了几个用户,下面这些用户用于GDS
sql / as sysdba
SQL> SET SQLFORMAT ansiconsole
SQL> select username,account_status from dba_users where username like '%GSM%';
USERNAME ACCOUNT_STATUS
GSMCATUSER EXPIRED & LOCKED
GSMUSER EXPIRED & LOCKED
GSMADMIN_INTERNAL EXPIRED & LOCKED
#解锁用户
sqlplus / as sysdba
SQL> alter user gsmcatuser identified by oracle account unlock;
#创建管理用户mygds 【用于存储Sharding 管理信息,GDSCTL 接口通过用户mygds 连接到catalog 数据库】
SQL> create user mygds identified by oracle;
SQL> grant connect, create session, gsmadmin_role to mygds;
SQL> grant inherit privileges on user SYS to GSMADMIN_INTERNAL;
#在gsm1服务器(catalog 数据库/shard director),启动listener
#步驟4 在gsm1服务器gds用戶下,创建shard catalog,在shard catalog中配置remote scheduler agent.
su - gds
参数含义:
-user : 指定管理用户,在前面步骤中创建的catalog database管理用户mygds
-database : 指定catalog database 信息,catalog 数据库的主机名:监听器port: catalog 数据库db_name
-sdb : 指定sharded database name
-agent_port: 设置端口,用于shard节点agent连接到GSM
-agent_password: 设置密码,用于shard节点agent连接到GSM
如果没有指定- sharding参数,默认是创建system-managed (default)类型
$ gdsctl
GDSCTL>
create shardcatalog -database gsm1:1521:catadb -chunks 12 -user mygds/oracle -sdb shdb -region region1, region2 -agent_port 8080 -agent_password oracle
#创建和启动shard director
参数含义:
-gsm: 指定shard director名称
-listener: 指定shard director的监听端口,注意不能与数据库的listener端口冲突
-catalog: 指定catalog database 信息,catalog数据库的主机名:监听器port: catalog 数据库db_name
GDSCTL>add gsm -gsm sharddirector3 -listener 1522 -pwd oracle -catalog gsm1:1521:catadb -region region1
GDSCTL>start gsm -gsm sharddirector3
#添加操作系统认证.
GDSCTL> add credential -credential cre_reg1 -osaccount oracle -ospassword 123456
#步驟7 在所有的shard 节点(sd1、sd2)分别执行Agent
--在sd1节点执行
[oracle@sd1 ~]$ schagent -start
[oracle@sd1 ~]$ schagent -status
--密码oracle和端口8080是在第4步创建shardcatalog时设置的:
[oracle@sd1 ~] $ echo oracle | schagent -registerdatabase gsm1 8080
Agent Registration Password ?
Oracle Scheduler Agent Registration for 12.2.0.1.2 Agent
Agent Registration Successful!
--在sd2节点执行
[oracle@sd2 ]$ schagent -start
[oracle@sd2 ]$ schagent -status
[oracle@sd2 ]$ echo oracle | schagent -registerdatabase gsm1 8080
Agent Registration Password ?
Oracle Scheduler Agent Registration for 12.2.0.1.2 Agent
Agent Registration Successful!
23.创建System-Managed SDB
1.在Shard服务器 sd1 连接到shard director/GSM服务器(gsm1)
$ ssh gds@gsm1
2. 设置当前session为sharddirector3 shard director.
$ gdsctl
GDSCTL>set gsm -gsm sharddirector3
GDSCTL>connect mygds/oracle
or
GDSCTL>connect mygds/oracle@gsm1:1521:catadb
3. 添加shardgroup, shardgroup是一组shard的集合,
# shardgroup名称为primary_shardgroup,-deploy_as primary表示这个group中的shard都是主库。
GDSCTL>add shardgroup -shardgroup primary_shardgroup -deploy_as primary -region region1
4. 将每个shard 地址添加到catalog 的 (VNCR) 列表,并且创建shard
GDSCTL> add invitednode sd1
GDSCTL>create shard -shardgroup primary_shardgroup -destination sd1 -credential cre_reg1 -sys_password 123456
------------------------------------------------------
The operation completed successfully
DB Unique Name: sh1
GDSCTL> add invitednode sd2
GDSCTL> create shard -shardgroup primary_shardgroup -destination sd2 -credential cre_reg1 -sys_password 123456
-------------------------------------------------------
The operation completed successfully
DB Unique Name: sh2
5. 检查配置
GDSCTL>config
Regions
------------------------
region1
region2
GSMs
------------------------
sharddirector3
Sharded Database
------------------------
shdb
Databases
------------------------
sh1
sh2
Shard Groups
------------------------
primary_shardgroup
Shard spaces
------------------------
shardspaceora
Services
------------------------
GDSCTL pending requests
------------------------
Command Object Status
------- ------ ------
Global properties
------------------------
Name: oradbcloud
Master GSM: sharddirector3
DDL sequence #: 0
----------------------------------------------------------------------------
GDSCTL>config shardspace
Shard space Chunks
----------- ------
shardspaceora 12
-------------------------------------------------------------------------------
GDSCTL>config shardgroup
Shard Group Chunks Region Shard space
----------- ------ ------ -----------
primary_shardgroup 12 region1 shardspaceora
----------------------------------------------------------------------------------
GDSCTL>config vncr
Name Group ID
---- --------
sd1
sd2
192.168.40.135
-------------------------------------------------------------------------------------
GDSCTL>config shard
Name Shard Group Status State Region Availability
---- ----------- ------ ----- ------ ------------
sh1 primary_shardgroup U none region1 -
sh2 primary_shardgroup U none region1 -
-------------------------------------------------------------------------------------------
6. 部署/deploy ( Shard数据库部署过程采用静默安装方式 )
GDSCTL>deploy
deploy: examining configuration...
deploy: deploying primary shard 'sh1' ...
deploy: network listener configuration