1、检查主机名和网络并且配置/etc/hosts文件
关闭防火墙
#检查防火墙状态
systemctl status firewalld.service
#暂时关闭防火墙,下次启动时防火墙仍随系统启动而启动
systemctl stop firewalld.service
#彻底永久关闭防火墙
systemctl disable firewalld.service
#关闭SELINUX防火墙!
vi /etc/selinux/config
#将内容
SELINUX=enforcing
#更改为
SELINUX=disabled
2、安装依赖
yum install binutils compat-libcap1 gcc gcc-c++ glibc glibc-devel libaio libaio-devel libgcc libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat compat-libstdc++-33 elfutils-libelf-devel net-tools ksh smartmontools unzip
rpm -q binutils compat-libcap1 gcc gcc-c++ glibc glibc-devel libaio libaio-devel libgcc libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat compat-libstdc++-33 elfutils-libelf-devel net-tools ksh smartmontools unzip | grep "not installed"
binutils-2.27-44.base.el7_9.1.x86_64
compat-libcap1-1.10-7.el7.x86_64
gcc-4.8.5-44.el7.x86_64
gcc-c++-4.8.5-44.el7.x86_64
glibc-2.17-326.el7_9.x86_64
glibc-devel-2.17-326.el7_9.x86_64
libaio-0.3.109-13.el7.x86_64
libaio-devel-0.3.109-13.el7.x86_64
libgcc-4.8.5-44.el7.x86_64
libgcc-4.8.5-44.el7.x86_64
libstdc++-4.8.5-44.el7.x86_64
libstdc++-devel-4.8.5-44.el7.x86_64
libXi-1.7.9-1.el7.x86_64
libXtst-1.2.3-1.el7.x86_64
make-3.82-24.el7.x86_64
sysstat-10.1.5-20.el7_9.x86_64
compat-libstdc++-33-3.2.3-72.el7.x86_64
elfutils-libelf-devel-0.176-5.el7.x86_64
net-tools-2.0-0.25.20131004git.el7.x86_64
ksh-20120801-144.el7_9.x86_64
smartmontools-7.0-2.el7.x86_64
unzip-6.0-24.el7_9.x86_64
3、修改LINUX的内核文件sysctl.conf
[root@cent7 yum.repos.d]# vim /etc/sysctl.conf
[root@cent7 yum.repos.d]# sysctl -p
kernel.shmmax = 277495689510912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.file-max = 6815744
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_probes = 6
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_timestamps = 0
fs.aio-max-nr = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
参数说明:
fs.file-max //文件句柄数 一次可以打开文件的个数
kernel.shmall //公式:内存大小102410241024/41024 //表示所有内存大小(单位:页=4K)
kernel.shmmax //表示最大共享内存大小,一般为物理内存的3/4 但是常用的就是将所有内存换算成字节后-1(单位:字节)
kernel.shmmni = 4096 //表示最小共享内存固定4096KB 一般是固定值
kernel.sem //4个参数依次是SEMMSL:每个用户拥有信号量最大数,SEMMNS:系统信号量最大数,SEMOPM:每次semopm系统调用操作数,SEMMNI:系统辛苦量集数最大数。这4个参数为固定内容大小
net.ipv4.ip_local_port_range = 9000 65500 //ip_local_port_range表示端口的范围,为指定的内容 一般是固定值
net.core.rmem_default //表示套接字接收缓冲区大小的缺省值
net.core.rmem_max //表示套接字接收缓冲区大小的最大值。
net.core.wmem_default //表示套接字发送缓冲区大小的缺省值。
net.core.wmem_max //表示套接字发送缓冲区大小的最大值。
参数编辑完成后执行下面的命令
sysctl -p 生成系统参数
4、添加下列参数到/etc/security/limits.conf
vim /etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
oracle hard memlock 134217728
oracle soft memlock 134217728
5、添加下列条目到/etc/pam.d/login
这两个主要是限制使用进程数
vim /etc/pam.d/login
session required /lib/security/pam_limits.so
session required pam_limits.so
6、环境变量中添加下列语句
vim /etc/profile
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 使环境变量生效
7、创建文件目录和相应的用户
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle
groupadd oinstall --创建 oinstall组 安装数据库软件用
groupadd dba --创建 dba组 管理数据库软件用
groupadd oper --创建 oper组 操作数据库软件用–但是基本用不到。
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oraInventory
chown -R oracle:oinstall /u01
chmod -R 775 /u01/app/oracle
mkdir -p /u01/app/oracle --级联创建/u01/app/oracle目录
mkdir -p /u01/oraInventory --级联创建oraInventory目录 这个目录下放置的是安装oracle所需要的的环境
chown -R oracle:oinstall /u01 --该命令为把/u01这个目录的所属用户和所属组变为oracle用户和oracle用户所在的oinstall组
chmod -R 775 /u01/app/oracle --该命令为把/u01/app/oracle这个目录的权限改为所属用户可对可写可执行 所属用户所在组下的所有同组成员皆为可读可写可执行 其他用户对这个目录只有可读和可执行
给oracle用户加一个密码
passwd oracle
8、配置ORACLE用户的环境变量
su - oracle
修改oracle用户的环境变量文件
vim .bash_profile
export EDITOR=vi
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export INVENTORY_LOCATION=/u01/oraInventory
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
umask 022
source .bash_profile
参数说明
export EDITOR=vi 默认的编辑器是vi
export TMP=/tmp ORACLE默认的临时目录是/tmp
export TMPDIR=TMP 临时目录生成
export ORACLE_SID=orcl ORACLE实例名称是orcl
export ORACLE_BASE=/u01/app/oracle ORACLE的基本目录
export ORACLE_HOME=ORACLE_BASE/product/12.2.0/db_1 ORACLE数据库的HOME目录
export INVENTORY_LOCATION=/u01/oraInventory ORACLE安装时的inventory
export TNS_ADMIN=ORACLE_HOME/network/admin ORACLE的网络文件主目录
export LD_LIBRARY_PATH=ORACLE_HOME/lib ORACLE的库文件目录
export NLS_LANG=“AMERICAN_AMERICA.AL32UTF8” ORACLE的字符集 不过我们弃用 因为我们使用UTF8
export NLS_DATE_FORMAT=“YYYY-MM-DD HH24:MI:SS” ORACLE的日期格式 我们使用会话的方式修改 没有上面的NLS_LANG,那么这个参数不会生成
export PATH=ORACLEHOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:ORACLEHOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:PATH:$HOME/bin 生成相关参数
9、上传软件并且解压
ls -lh /u01/soft/linuxx64_12201_*
-rw-r--r-- 1 root root 3.3G Feb 5 18:56 /u01/soft/linuxx64_12201_database.zip
-rw-r--r-- 1 root root 2.8G Feb 5 18:56 /u01/soft/linuxx64_12201_grid_home.zip
10、rlwrap软件配置
yum install readline readline-devel
tar -zxvf rlwrap-0.43.tar.gz
cd rlwrap-0.43 && ./configure
make && make install
su - oracle
vi /home/oracle/.bash_profile
#将下面两行文字粘贴进该文件中即可
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
#添加完内容后保存退出 并执行以下命令来生成环境变量
. /home/oracle/.bash_profile
11、解压安装包并安装
unzip linuxx64_12201_database.zip -d $ORACLE_HOME
#静默安装ORACLE 19C 数据库软件!进入到$ORACLE_HOME下 执行下列命令 那个rsp文件一定要记住被你放到哪了
#修改rsp文件
vim db_install.rsp
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.OSDGDBA_GROUP=dba
oracle.install.db.OSKMDBA_GROUP=dba
oracle.install.db.OSRACDBA_GROUP=dba
DECLINE_SECURITY_UPDATES=true
./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /home/oracle/12c_response/db_install.rsp
#root用户执行
As a root user, execute the following script(s):
1. /u01/app/oraInventory/orainstRoot.sh
2. u01/app/oracle/product/12.2.0/db_1/root.sh
12、创建并启动监听
cd $ORACLE_HOME
netca -silent -responseFile netca.rsp
13、初始化实例
vim dbca.rsp
characterSet AL32UTF8
sysPassword OraPasswd1
systemPassword OraPasswd1
createAsContainerDatabase true
numberOfPDBs 1
pdbName pdb3
pdbAdminPassword OraPasswd1
databaseType MULTIPURPOSE
datafileDestination "/u01/app/oracle/oradata/"
dbca -createdatabase -silent -responseFile dbca.rsp
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname orclcwai -sid cwai -responseFile NO_VALUE -characterSet AL32UTF8 -sysPassword oracle -systemPassword "oracle" -databaseType MULTIPURPOSE -storageType FS -datafileDestination "/u01/app/oracle/oradata/" -redoLogFileSize 50 -emConfiguration NONE
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orclcwai/orclcwai.log" for further details.
14、手工创建CDB
#1、修改sid cdb的sid=cwai
sed -i 's#ORACLE_SID=.*#ORACLE_SID=cwai#' /home/oracle/.bash_profile
source ~/.bash_profile
#2、创建密码文件
orapwd file=$ORACLE_HOME/dbs/orapwcwai
password=oracle force=y format=12
#3、创建pfile
mkdir -p /u01/app/oracle/admin/cwai/adump --建立cdb1的审计目录
mkdir -p /u01/app/oracle/oradata/cwai --建立cdb1的数据文件存放目录
mkdir -p /u01/app/oracle/oradata/cwai/pdbseed --创建pdbseed目录
vi /u01/app/oracle/init_cwai.ora
*.audit_file_dest='/u01/app/oracle/admin/cwai/adump'
*.audit_trail='db'
*.control_files='/u01/app/oracle/oradata/cwai/control01.ctl','/u01/app/oracle/oradata/cwai/control02.ctl'
*.db_block_size=8192
*.db_name='cwai'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=cwaiXDB)'
*.enable_pluggable_database=true
*.open_cursors=300
*.pga_aggregate_target=200m
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=800m
*.undo_tablespace='UNDOTBS1'
#修改后保存退出。这里我们必须要注意下面的参数必须要添加进去:*.enable_pluggable_database=true
#4、使用创建出来的pfile生产spfile后启动。
SQL> conn /as sysdba
SQL> startup nomount pfile='/u01/app/oracle/init_cwai.ora'
SQL> create spfile from pfile='/u01/app/oracle/init_cwai.ora' ;
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
#5、创建一个CDB的建库脚本
vim create_cwai.sql
CREATE DATABASE cwai
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/cwai/redo01a.log','/u01/app/oracle/oradata/cwai/redo01b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/app/oracle/oradata/cwai/redo02a.log','/u01/app/oracle/oradata/cwai/redo02b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/app/oracle/oradata/cwai/redo03a.log','/u01/app/oracle/oradata/cwai/redo03b.log')
SIZE 100M BLOCKSIZE 512
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/u01/app/oracle/oradata/cwai/system01.dbf'
SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/u01/app/oracle/oradata/cwai/sysaux01.dbf'
SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE deftbs
DATAFILE '/u01/app/oracle/oradata/cwai/deftbs01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/cwai/temp01.dbf'
SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE undotbs1
DATAFILE '/u01/app/oracle/oradata/cwai/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
USER_DATA TABLESPACE usertbs
DATAFILE '/u01/app/oracle/oradata/cwai/pdbseed/usertbs01.dbf'
SIZE 50M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE
SEED
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/cwai/', '/u01/app/oracle/oradata/cwai/pdbseed/')
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M
LOCAL UNDO ON;
SQL> @/u01/app/oracle/create_cwai.sql
Database created.
SQL> @?/rdbms/admin/catcdb.sql
如果遇到让你输入参数的时候 ,输入下面的参数:
Enter value for 1: /home/oracle
Enter value for 2: /home/oracle/cdb.log
Enter new password for SYS: oracle
Enter new password for SYSTEM: oracle
Enter temporary tablespace name: temp
当最后输出这些时候代表脚本运行成功:catcon: See [/home/oracle/utlrp_*.lst] files for spool files, if any catcon.pl: completed successfully
Can't locate Term/ReadKey.pm in @INC (@INC contains: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 30.
BEGIN failed--compilation aborted at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 30.
#遇到上述报错,执行如下语句后再次执行catcdb.sql
export PERL5LIB=$ORACLE_HOME/rdbms/admin:$PERL5LIB
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH
cd $ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash
ln -s Util.pm util.pm
#6、使用语句去验证
SQL> select name,cdb,con_id,open_mode from v$database;
NAME CDB CON_ID OPEN_MODE
--------- --- ---------- --------------------
CWAI YES 0 READ WRITE
SQL> set lines 300
SQL> col NAME for a40
SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ---------------------------------------- ----------
2 1900432340 PDB$SEED READ ONLY
#7、注册监听服务
vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclcwai)
(ORACLE_HOME = /u01/app/oracle/product/12.2.0/db_1)
(SID_NAME = cwai)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle12c-cdb)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
15、手工创建PDB
#1.利用PDB$SEED创建PDB
SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ---------------------------------------- ----------
2 1900432340 PDB$SEED READ ONLY
CREATE PLUGGABLE DATABASE pdb1 ADMIN USER pdb1admin IDENTIFIED BY oracle
FILE_NAME_CONVERT=(
'/u01/app/oracle/oradata/cwai/pdbseed/system01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/system01.dbf',
'/u01/app/oracle/oradata/cwai/pdbseed/sysaux01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/sysaux01.dbf',
'/u01/app/oracle/oradata/cwai/pdbseed/undotbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/undotbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdbseed/deftbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/deftbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdbseed/usertbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/usertbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdbseed/temp01.dbf', '/u01/app/oracle/oradata/cwai/pdb1/temp01.dbf'
9 ) STORAGE UNLIMITED TEMPFILE REUSE;
Pluggable database created.
SQL> select name,cdb,con_id,open_mode from v$database;
NAME CDB CON_ID OPEN_MODE
---------------------------------------- --- ---------- --------------------
CWAI YES 0 READ WRITE
SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ---------------------------------------- ----------
2 1900432340 PDB$SEED READ ONLY
3 1475059426 PDB1 MOUNTED
SQL> select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
CON_ID DBID NAME OPEN_MODE
---------- ---------- ---------------------------------------- ---------
2 1900432340 PDB$SEED READ ONLY
3 1475059426 PDB1
#2、使用已有的PDB去创建新的PDB
需要注意几点:
使用的用户必须拥有'CREATE PLUGGABLE DATABASE'的权限(测试里使用sys用户)
源PDB不可以是关闭状态或者是mount状态的
如果CDB为shared undo,PDB必须为READ-ONLY状态。才能进行相关复制,不然丢失事务。
如果CDB不是归档模式,那么PDB必须为READ-ONLY状态。才能进行相关复制
SQL> alter pluggable database pdb1 open read write ;
Pluggable database altered.
CREATE PLUGGABLE DATABASE pdb2 FROM pdb1
STORAGE UNLIMITED TEMPFILE REUSE
FILE_NAME_CONVERT=(
'/u01/app/oracle/oradata/cwai/pdb1/system01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/system01.dbf',
'/u01/app/oracle/oradata/cwai/pdb1/sysaux01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/sysaux01.dbf',
'/u01/app/oracle/oradata/cwai/pdb1/undotbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/undotbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdb1/deftbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/deftbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdb1/usertbs01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/usertbs01.dbf',
'/u01/app/oracle/oradata/cwai/pdb1/temp01.dbf', '/u01/app/oracle/oradata/cwai/pdb2/temp01.dbf'
)
11 PARALLEL 2;
Pluggable database created.
16、建库、建用户、建表
SQL> conn pdb1admin/oracle@pdb1
Connected.
CREATE TABLESPACE hr LOGGING DATAFILE '/u01/app/oracle/oradata/cwai/pdb1/hr.dbf'
SIZE 100M AUTOEXTEND ON NEXT 32M MAXSIZE 500M EXTENT MANAGEMENT LOCAL;
create temporary tablespace hr_temp tempfile '/u01/app/oracle/oradata/cwai/pdb1/hr_temp.dbf'
size 100m autoextend on next 32m maxsize 500m extent management local;
Tablespace created.
SQL> SQL> 2
Tablespace created.
grant connect,resource,dba to hr;
grant create session to hr;
SQL> conn hr/hr@pdb1
Connected.
SQL> create table test1(name VARCHAR2(20));
Table created.
SQL> insert into test1 values ('ZhangSan');
1 row created.
SQL> insert into test1 values ('Lisi');
1 row created.
SQL> commit ;
Commit complete.
SQL> select * from test1;
NAME
--------------------
ZhangSan
Lisi