CentOS7.X静默安装Oracle12C数据库
uname -a
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
vi /etc/selinux/config
SELINUX=disabled
#下载oracle12201
wget https://www.oracle.com/database/technologies/oracle12c-linux-12201-downloads.html#license-lightbox
#使用root用户登录,进行系统基础环境准备。
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
yum -y install libXext
yum -y install libX11
yum -y install libXau
yum -y install libxcb
#执行检查命令:
rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
id oracle
#添加主机
vi /etc/hosts
127.0.0.1 node1
192.168.92.18 node1
vi /etc/sysctl.conf 增加如下内容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
# shmall 是全部允许使用的共享内存大小,shmmax 是单个段允许使用的大小。这两个可以设置为内存的 90%。例如 16G 内存,16*1024*1024*1024*90% = 15461882265,shmall 的大小为 15461882265/4k(getconf PAGESIZE可得到) = 3774873
# 因为本机是32G内存,所以shmmax 是 32*1024*1024*1024*90% = 30,923,764,531,shmall 是 30,923,764,531/4096 = 7,549,747
kernel.shmmax = 30923764531
kernel.shmall = 7549747
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
#使配置生效
sysctl -p
vi /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240
vi /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
vi /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
#创建安装目录,配置安装目录权限。
mkdir -p /u01/app/oracle/oradata
mkdir -p /u01/app/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/app/
chmod -R 775 /u01/app/
su - oracle
vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
export PS1=`uname -n`':$PWD/> '
#生效
source .bash_profile
#数据库应用安装
mkdir etc
#上传安装文件到oracle用户目录
执行命令:
unzip linuxx64_12201_database.zip
#复制Oracle配置文件到etc
cp ./database/response/* ./etc/
chmod 700 ./etc/*.rsp
#修改静默安装配置文件 db_install.rsp
cp ./etc/db_install.rsp ./etc/db_install.rsp.bak
> ./etc/db_install.rsp
vi ./etc/db_install.rsp
#oracle_install_db_InstallOption INSTALL_DB_AND_CONFIG #安装oracel软件及监听数据库实例 #INSTALL_DB_SWONLY #仅仅安装数据软件
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oracle/oradata
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/u01/app/oracle/fast_recovery_area
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.2.0
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oralnventory
ORACLE_HOME=/u01/app/oracle/product/12/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.OSDBA_GROUP=dba
oracle.install.db.OSOPER_GROUP=oinstall
oracle.install.db.OSBACKUPDBA_GROUP=oinstall
oracle.install.db.OSDGDBA_GROUP=oinstall
oracle.install.db.OSKMDBA_GROUP=oinstall
oracle.install.db.OSRACDBA_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.PDBName=pdboracle
oracle.install.db.config.starterdb.memoryLimit=2048
oracle.install.db.config.starterdb.password.ALL=oracle
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
-----------------------------
#修改文件配置参考,121020版本
#oracle.install.option=INSTALL_DB_SWONLY
#UNIX_GROUP_NAME=oinstall
#INVENTORY_LOCATION=/u01/app/oracle/oraInventory
#SELECTED_LANGUAGES=en,zh_CN
#ORACLE_HOME=/u01/app/oracle/product/12/db_1
#ORACLE_BASE=/u01/app/oracle
#oracle.install.db.InstallEdition=EE
#oracle.install.db.DBA_GROUP=dba
#oracle.install.db.OPER_GROUP=oinstall
#oracle.install.db.BACKUPDBA_GROUP=oinstall
#oracle.install.db.DGDBA_GROUP=oinstall
#oracle.install.db.KMDBA_GROUP=oinstall
#oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
#oracle.install.db.config.starterdb.globalDBName=orcl
#oracle.install.db.config.starterdb.SID=orcl
#oracle.install.db.config.starterdb.characterSet=AL32UTF8
#oracle.install.db.config.starterdb.memoryOption=true
#oracle.install.db.config.starterdb.password.ALL=oracle
#SECURITY_UPDATES_VIA_MYORACLESUPPORT=true
#DECLINE_SECURITY_UPDATES=true
#开始安装
./database/runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp
#Checking swap space: 0 MB available, 150 MB required. Failed <<<<
--------------------------
#报错了,避免失败,把问题解决一下。
#虚拟内存空间设置的小于等于2个G时操作
一、是没有swap空间
#1.检查一下系统的 swap 文件
swapon -s
#2.切换 root 用户,创建swap文件
dd if=/dev/zero of=/swapfile bs=1024 count=512k
536870912 bytes (537 MB) copied, 1.49301 s, 360 MB/s
#3.格式化并激活 Swap 文件
mkswap /swapfil
选项:
-c, --check 创建交换区前检查坏块
-f, --force 允许交换区大于设备大小
-p, --pagesize SIZE 指定页大小为 SIZE 字节
-L, --label LABEL 指定标签为 LABEL
-v, --swapversion NUM 指定交换空间版本号为 NUM
-U, --uuid UUID 指定要使用的 UUID
-V, --version 输出版本信息并退出
-h, --help 显示此帮助并退出
#swapon激活swapfile文件
swapon /swapfile
#4.再次检查系统的 Swap 文件
swapon -s
Filename Type Size Used Priority
/swapfile file 524284 0 -1
#5.配置机器重启自动挂载Swap
vi /etc/fstab 添加一行 并注释掉/dev/mapper/centos-swap swap
/swapfile swap swap defaults 0 0
#6.赋予 Swap 文件权限
chmod 600 /swapfile
chown root:root /swapfile
#再次执行本部操作的数据库安装命令:
--------------------------
#切换 root 用户,修改数据库配置
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/12/db_1/root.sh
#使用oracle用户登录
vi ~/.bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
#oracle conf
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
export ORACLE_PID=pdb
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_HOME=/u01/app/oracle/product/12/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export LANG="en_US.UTF-8"
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
stty erase ^H
#使环境变量生效
source .bash_profile
#配置监听程序
#如果1521端口被占用则修改netca.rsp,如果监听启动报错ip地址不对则修改$ORACLE_HOME/network/admin/listener.ora
#查询端口被占用的程序
lsof -i:1521
#最后一列显示端口号/进程名称
netstat -tunpl | grep 1521
netca /silent /responsefile /home/oracle/etc/netca.rsp
#查看监听
lsnrctl status
4、静默建库文件修改,打开 dbca.rsp 文件。
cp etc/dbca.rsp etc/dbca.rsp.bak
> etc/dbca.rsp
#nationalCharacterSet参数未指定
vi ./etc/dbca.rsp
gdbName=orcl
sid=orcl
databaseConfigType=SI
createAsContainerDatabase=true
numberOfPDBs=1
pdbName=pdboracle
templateName=/u01/app/oracle/product/12/db_1/assistants/dbca/templates/General_Purpose.dbc
emExpressPort=5500
omsPort=0
characterSet=AL32UTF8
listeners=LISTENER
memoryPercentage=40
automaticMemoryManagement=false
totalMemory=0
------------------
#参考
SID = "orcl"
CHARACTERSET = "AL32UTF8"
LISTENERS = "LISTENERS"
------------------
#执行静默建库
#输入SYS ,SYSTEM,PDBADMIN用户口令
dbca -silent -createDatabase -responseFile /home/oracle/etc/dbca.rsp
#dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ogg1 -sid ogg1 -sysPassword lhr -systemPassword lhr -responseFile NO_VALUE -datafileDestination /u01/app/oracle/oradata -redoLogFileSize 50 -recoveryAreaDestination /u01/app/oracle/flash_recovery_area -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema true -memoryPercentage 30 -totalMemory 200 -databaseType OLTP -emConfiguration NONE -automaticMemoryManagement true
----------------------------------------
vi $ORACLE_HOME/network/admin/tnsnames.ora
#修改plsql登录配置
PDBORACLE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDBORACLE)
)
)
--配置客户端连接,消除报错:ORA-28040: No matching authentication protocol
cd $ORACLE_HOME/network/admin
vi sqlnet.ora
#SQLNET.ALLOWED_LOGON_VERSION=8 #12c已废弃
#或当jdbc首次连接成功后,可能出现去掉以下配置仍可以连接
#AUTHENTICATION_SERVICES加上后不能以操作系统身份登陆
#SQLNET.AUTHENTICATION_SERVICES=(NTS)
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
--ORA-01017: invalid username/password; logon denied
--12c需要重新更改密码后允许客户端登陆
sqlplus / as sysdba
alter user sys identified by oracle;
#创建数据库应用用户并授权
sqlplus / as sysdba
create user c##test identified by test;
alter session set container=pdboracle;
create user zyj identified by zyj;
grant connect,resource,dba to zyj;
select username from dba_users order by 1;
--------------------
#配置数据库实例与监听自动启动
#方法一
--安装完成后cdb中配置pdb自启动
sqlplus / as sysdba
create trigger startup_pdbs
after startup on database
begin
execute immediate 'alter pluggable database all open';
end startup_pdbs;
/
#安装好Oracle数据库后: 执行 dbstart和dbshut会提示:
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/oracle/product/10.2.0/db_1/bin/dbstart ORACLE_HOME
vi $ORACLE_HOME/bin/dbstart
vi $ORACLE_HOME/bin/dbshut
ORACLE_HOME_LISTNER=$1,修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME:
#修改为orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Y
vi /etc/oratab
找到:orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Y
su -
chmod +x /etc/rc.d/rc.local
vi /etc/rc.d/rc.local
su oracle -lc "/u01/app/oracle/product/12/db_1/bin/lsnrctl start"
su oracle -lc /u01/app/oracle/product/12/db_1/bin/dbstart
-----------
#方法二
--安装完成后cdb中配置pdb自启动
sqlplus / as sysdba
create trigger startup_pdbs
after startup on database
begin
execute immediate 'alter pluggable database all open';
end startup_pdbs;
/
#11g、12c设置数据库软件开机自启动
su - oracle
vim /etc/oratab
orcl:/u01/app/oracle/product/11.2.0.4:Y
su -
chmod +x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
su - oracle <<EOF
lsnrctl start LISTENER
sqlplus /nolog<<EOS
connect / as sysdba
startup
alter system register;
EOS
EOF
----------------------------------------------------------------------------
oracle数据库在/dev/mapper/centos-root下,分配多一些空间给centos-root
我将自己/home上多余的10个G空间分配给我的root空间内。
具体命令与步骤:
1.查看磁盘空间:
[root@localhost ~]# df -h
2.查看逻辑卷组:
[root@localhost ~]# vgdisplay
3.查看逻辑卷:
这里我主要看/dev/centos/root的大小。
[root@localhost ~]# lvdisplay
4.将现有的/home备份或移动到/media下:
[root@localhost ~]# mv /home/* /media/
5.卸载现有的/home目录:
[root@localhost ~]# umount /home
6.再次使用[root@localhost ~]# df -h命令查看磁盘内已经没有/home的目录了。
7.删除掉我们卸载的/home目录所引用的逻辑卷:
输入yes
[root@localhost ~]# lvremove /dev/centos/home
8.查看卷组空间:
[root@localhost ~]# vgdisplay
9.新建/dev/centos/home:
我给我的/home8个G大小以后再增加。
[root@localhost ~]# lvcreate -L 8G -n home centos
10.查看逻辑卷情况:
[root@localhost ~]# lvdisplay /dev/centos/home
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID 0ffL0k-Xgnc-pDua-Jxij-RhPd-bFxs-NKTwd2
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-02-20 08:48:33 +0800
LV Status available
# open 1
LV Size 8.00 GiB
Current LE 2048
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
11.在/dev/centos/home上建立xfs系统:
[root@localhost ~]# mkfs -t xfs /dev/centos/home
12.将新分配的home逻辑卷挂载到/home文件夹:
[root@localhost ~]# mount /dev/centos/home /home/
13.把我们第4步移动的文件重新移动到/home文件夹内:
[root@localhost ~]# mv /media/* /home/
14.将我所能够用的空间拿出10G来给我的/dev/centos/root
[root@localhost ~]# lvextend -L +10G /dev/centos/root
15.激活我们创建的centos卷组:
[root@localhost ~]# vgchange -ay centos
16.扩展/dev/centos/root:
[root@localhost ~]# xfs_growfs /dev/centos/root
17.查看空间大小:
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 49G 21G 28G 43% /
devtmpfs 897M 0 897M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.0M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
/dev/mapper/centos-home 8.0G 6.9G 1.2G 86% /home
tmpfs 183M 12K 183M 1% /run/user/42
tmpfs 183M 0 183M 0% /run/user/0
tmpfs 183M 0 183M 0% /run/user/1001