虚拟化容器,大数据,DBA,中间件,监控。

CENTOS7/RHEL7.4安装oracle12c数据库,配置PDB监听

03 05月
作者:admin|分类:DBA运维

CENTOS7/RHEL7.4安装oracle12c数据库,并配置CBD与PDB监听信息


修改系统配置

hostnamectl set-hostname db1
chkconfig NetworkManager off
/etc/init.d/NetworkManager stop
chkconfig ip6tables off


安装桌面环境与Oracle依赖包。

yum groupinstall -y "Desktop" "X Window System" "Chinese Support [zh]" "Internet Browser"

yum -y install cjkuni* bitmap* wqy-*
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*.i686 elfutils-libelf-devel gcc gcc-c++ glibc*.i686 glibc glibc-devel glibc-devel*.i686 ksh libgcc*.i686 libgcc libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.i686 libaio libaio*.i686 libaio-devel libaio-devel*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 libXp

yum install glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++ -y
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat unixODBC unixODBC-devel unzip
yum install elfutils-libelf-devel-static -y
yum install elfutils-libelf-devel-static -y
 yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat unixODBC unixODBC-devel unzip
yum install glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++
yum install libcap.so.1 -y
yum  install compat-libstdc*
yum -y install autoconf automake binutils-devel bison cpp dos2unix gcc gcc-c++ lrzsz python-devel
yum -y install kernel-devel kernel-headers
yum –y install libXp libXp.i686
yum -y install libXtst.i686 libXt.i686
yum –y install libXp libXp.i686
yum –y install libX
yum –y install libXp
yum -y install libXp
yum -y install libXp.i686
yum -y install libXtst.i686 libXt.i68
yum -y install libXtst.i686 libXt.i686
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat

yum install libaio.i686 libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 compat-libstdc++-33.i686 compat-libstdc++-33.x86_64 elfutils-libelf-devel.i686 elfutils-libelf-devel.x86_64 libstdc++.i686 libstdc++.x86_64 unixODBC.i686 unixODBC.x86_64 unixODBC-devel.i686 unixODBC-devel.x86_64


配置oracle账号信息。

groupadd dba
groupadd oper
groupadd oinstall

useradd -g oinstall -G dba,oper oracle
passwd oracle


vi /etc/sysctl.d/99-sysctl.conf

kernel.shmmni = 4096  
kernel.sem = 250 32000 100 128

fs.file-max = 6815744
fs.aio-max-nr = 3145728

net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576


 sysctl -p

 sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config


# vi /etc/pam.d/login
session required /lib/security/pam_limits.so
session required pam_limits.so



  vi /etc/security/limits.conf

oracle  soft        nproc   500000
oracle  hard        nproc   500000
oracle  soft        nofile  1048000
oracle  hard        nofile  1048000
oracle  soft        stack   10240
oracle  hard        stack   10240



创建oralce安装目录以及数据存放目录.

# mkdir -p /data/app/oracle

# chown -R oracle:oinstall /data/app/oracle

# chmod -R 775 /data/app/oracle



配置Oracle用户环境变量:

# vi /home/oracle/.bash_profile

在文件末尾加入以下内容:

PATH=$PATH:$HOME/bin

export ORACLE_BASE=/data/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/12.2/db_1

export ORACLE_SID=orcl12g

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK

export PATH



linux oracle 启动脚本:
 
#!/bin/sh
# chkconfig: 345 99 05
# description: Oracle auto start-stop script.

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/xvdb/oracle/app/product/11.2.4/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
ln -s /etc/init.d/oracle11g /etc/rc6.d/K01oracle11g /var/lock/subsys/
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" >>/var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle11g

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac


由于oracle 12c使用了CDB-PDB架构,类似于docker,在container-db内可以加载多个pluggable-db,因此安装后需要额外配置才能使用。

以下方法是使用静态注册方法,不建议使用。

一、修改listener.ora , tnsnames.ora


[oracle@centos7 admin]$ cat listener.ora
# listener.ora Network Configuration File: /data/oracle/app/product/12.2/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl12g)
      (ORACLE_HOME = /data/oracle/app/product/12.2/db_1)
      (SID_NAME = orcl12g)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = orcl12gpdb)
      (ORACLE_HOME = /data/oracle/app/product/12.2/db_1)
      (SID_NAME = orcl12g)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = centos7)(PORT = 1521))
  )

ADR_BASE_LISTENER = /data/oracle/app



###listener.ora###
 LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = centos7)(PORT = 1521))
  )

#sid list列举cdb和所有pdb的数据库名,所有sid与oracle环境变量保持一致#

SID_LIST_LISTENER =(
 SID_LIST = 
  (SID_DESC = (GLOBAL_DBNAME = orcl12g) #cdb db_name 
    (SID_NAME = orcl12g)      # SID 信息与pdb信息一致 ) 
  (SID_DESC = (GLOBAL_DBNAME = orcl12gpdb) #pdb db_name 
    (SID_NAME = orcl12g)      # SID 信息与pdb信息一致                 
 )
)
###listener.ora###


##tnsnames.ora###

#cdb
orcl =
(DESCRIPTION = 
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) )
 (CONNECT_DATA =
 (SERVICE_NAME = orcl) #cdb的db_name
 )
)
#pdb
pdborcl =
(DESCRIPTION =
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
 )
 (CONNECT_DATA =
 (SERVICE_NAME = pdborcl) #pdb的db_name
 )
)
##tnsnames.ora###

[oracle@centos7 admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /data/oracle/app/product/12.2/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

orcl12gpdb =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl12gpdb)
    )
  )

orcl12g =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = centos7)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl12g)
      
    )
  )




下面方法是使用动态注册方法,建议使用。

2.12C 不推荐静态注册,建议动态注册

.动态注册方法信息如下:

To resolve this, make sure that you do the following:
1. Backup then edit the listener.ora file to REMOVE the "static" SID_DESC sections for these PDBs
2. Make sure the Database knows where to register by explicitly setting the LOCAL_LISTENER to 
  any of the end points (addresses) that this listener is listening on.
 Within the PDB issue the following statement:

 

alter session set container=PDB1;

alter system set listener_networks='(( NAME=listener)(LOCAL_LISTENER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle.com)(PORT=1521)))))' scope=spfile;

 

3. Restart the Listener and db.

Always use Dynamic Services for connections. Do not use SID which is very old and obsolete with respect to how connections should be established or serviced.

This would not apply to certain components such as DG or RMAN which sometimes requires connections via a "Static Service" due to the Database not being in an OPEN (and therefore not "ready") status. See the following: Understanding Static Service Registration



oracle自动动态注册监听方法:


[oracle@centos7 admin]$ sqlplus / as sysdba

SQL>
SQL> alter system set local_listener='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=centos7)(PORT=1521)))';

SQL>

SQL> show parameter listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
listener_networks                    string
local_listener                       string      (DESCRIPTION=(ADDRESS=(PROTOCO
                                                 L=TCP)(HOST=centos7)(PORT=1521
                                                 )))
remote_listener                      string


添加PDB注册信息。

SQL> alter session set container=orcl12gpdb;

SQL> alter system set listener_networks='(( NAME=listener)(LOCAL_LISTENER=(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=centos7)(PORT=1521)))))' scope=spfile;

 

Oracle数据库实例的动态监听注册细节。有如下这样一个规律,先总结在这里:
①如果是先启动监听,后启动数据库实例,则动态监听会自动识别到启动的数据库实例;
②在数据库实例正常运行的情况下重启监听,则数据库实例会等很长时间才能在动态监听中注册成功,大约需要1分钟的等待时间;
③如果是先启动数据库实例,后启动监听,效果和②一样;
④如果不希望长时间等待动态监听注册的过程,可以使用“alter system register;”命令加速




清除掉静态注册的信息,内容如下:

[oracle@centos7 admin]$ cat /data/oracle/app/product/12.2/db_1/network/admin/listener.ora

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = centos7)(PORT = 1521))
  )

ADR_BASE_LISTENER = /data/oracle/app

[oracle@centos7 admin]$




-》 静态注册方法信息如下:
•Use of external procedure calls
•Use of Oracle Heterogeneous Services
•Use of Oracle Data Guard
•Remote database startup from a tool other than Oracle Enterprise Manager Cloud Control
•Connections to Oracle databases earlier than Oracle8i release 2 (8.1)

1、配置监听

首先要明确,所有的PDB都使用1个监听,配置多个实际上启动时也只有第1个有意义。

LISTENER=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =ora12c_A)(PORT = 1521))
  )


接下来使用SID_LIST_LISTENER来进行静态注册服务。
SID_LIST_LISTENER=
(SID_LIST=
  (SID_DESC =
  (GLOBAL_DBNAME = ora12c) #该服务是我配置的cdb信息
  (SID_NAME = ora12c)
  )

  (SID_DESC =
  (GLOBAL_DBNAME = pdborcl)#该服务是我配置的pdb信息
  (SID_NAME = ora12c)
  )
)

ADR_BASE_LISTENER= /opt/oracle

2、tnsnames.ora配置
观察发现,在tnsnames中配置pdb跟CDB,即原来11g的配置完全一样。这里SERVICE_NAME = pdborcl使用得是PDB的名字,可以在v$pdbs中查看。

ORA12C=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =ora12c_A)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ora12c)
    )
  )

pdborcl=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST =ora12c_A)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pdborcl)
    )
  )


3、为了保险,检查下sqlnet.ora
NAMES.DIRECTORY_PATH=(TNSNAMES, EZCONNECT)
这一句是为了保证优先使用TNSNAMES解析。



浏览1749 评论0
返回
目录
返回
首页
Oracle WebLogic Server Java反序列化漏洞CVE-2018-2628 Oracle 12c CDB与pdb 自动启动方法