说明
本文系统使用 OracleLinux-R7-U8-Server-x86_64-dvd.iso 最小化安装,新建/data目录用于安装Oracle数据库。
系统下载地址:OracleLinux7.8
本文Oracle版本为 linuxx64_12201_database.zip。
数据库下载地址:Oracle12c
依赖包pdksh下载地址:pdksh包, 提取码:gzry。
本文操作系统hostname为test,安装Oracle数据库sid为test,管理员用户密码统一为 managertest。
添加用户和组
[root@test ~]# groupadd oinstall
[root@test ~]# groupadd dba
[root@test ~]# useradd -g oinstall -G dba -m oracle
修改密码
[root@test ~]# id oracle
uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)
[root@test ~]# passwd oracle
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
创建相关目录
[root@test ~]# mkdir -p /data/oracle
[root@test ~]# mkdir -p /data/oraInventory
[root@test ~]# mkdir -p /data/soft
[root@test ~]# mkdir -p /data/java
目录赋权
[root@test ~]# chmod -R 775 /data
[root@test ~]# chmod 777 -R /tmp
拷贝文件
拷贝文件jdk-8u151-linux-x64.tar.gz , linuxx64_12201_database.zip ,pdksh-5.2.14-37.el5_8.1.x86_64.rpm 到 soft目录。
安装解压工具
jdk-8u151-linux-x64.tar.gz
linuxx64_12201_database.zip
[root@test ~]# yum install -y unzip
[root@test ~]# yum install -y tar
解压文件
[root@test ~]# cd /data/soft/
[root@test soft]# ls
jdk-8u151-linux-x64.tar.gz linuxx64_12201_database.zip pdksh-5.2.14-37.el5_8.1.x86_64.rpm
[root@test soft]# tar -zxvf jdk-8u151-linux-x64.tar.gz
[root@test soft]# mv /data/soft/jdk1.8.0_151/* /data/java
[root@test soft]# rm -rf /data/soft/jdk1.8.0_151/
[root@test soft]# unzip linuxx64_12201_database.zip
配置java环境
[root@Slave01 soft]# vi /etc/profile
#添加环境变量,建议添加在开头部分
export JAVA_HOME=/data/java/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
[root@test soft]# source /etc/profile
安装Oracle依赖包
# 查看依赖包
[root@test tmp]# rpm -q \
> binutils \
> compat-libstdc++-33 \
> elfutils-libelf \
> elfutils-libelf-devel \
> expat \
> gcc \
> gcc-c++ \
> glibc \
> glibc-common \
> glibc-devel \
> glibc-headers \
> libaio \
> libaio-devel \
> libgcc \
> libstdc++ \
> libstdc++-devel \
> make \
> pdksh \
> sysstat \
> unixODBC \
> unixODBC-devel
binutils-2.27-43.base.0.1.el7.x86_64
package compat-libstdc++-33 is not installed
elfutils-libelf-0.176-4.el7.x86_64
package elfutils-libelf-devel is not installed
expat-2.1.0-11.el7.x86_64
package gcc is not installed
package gcc-c++ is not installed
glibc-2.17-307.0.1.el7.1.x86_64
glibc-common-2.17-307.0.1.el7.1.x86_64
package glibc-devel is not installed
package glibc-headers is not installed
libaio-0.3.109-13.el7.x86_64
package libaio-devel is not installed
libgcc-4.8.5-39.0.3.el7.x86_64
libstdc++-4.8.5-39.0.3.el7.x86_64
package libstdc++-devel is not installed
make-3.82-24.el7.x86_64
package pdksh is not installed
package sysstat is not installed
package unixODBC is not installed
package unixODBC-devel is not installed
# 安装依赖包
[root@test tmp]# yum install compat-libstdc++-33 -y
[root@test tmp]# yum install -y elfutils-libelf-devel
[root@test tmp]# yum install -y gcc
[root@test tmp]# yum install -y gcc-c++
[root@test tmp]# yum install -y glibc-devel
[root@test tmp]# yum install -y glibc-headers
[root@test tmp]# yum install -y libaio-devel
[root@test tmp]# yum install -y libstdc++-devel
[root@test tmp]# yum install -y sysstat
[root@test tmp]# yum install -y unixODBC
[root@test tmp]# yum install -y unixODBC-devel
[root@test tmp]# yum install -y pdksh
No package pdksh available.
安装pdksh包
[root@test tmp]# rpm -ivh /data/soft/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
warning: /data/soft/pdksh-5.2.14-37.el5_8.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:pdksh-5.2.14-37.el5_8.1 ################################# [100%]
配置Oracle服务端口
# 查看开放的端口
[root@test tmp]# firewall-cmd --zone=public --list-ports
[root@test tmp]# firewall-cmd --zone=public --add-port=1521/tcp --permanen
success
[root@test tmp]# firewall-cmd --zone=public --add-port=5500/tcp --permanen
success
[root@test tmp]# firewall-cmd --zone=public --add-port=5502/tcp --permanen
success
# 使配置立即生效
[root@test tmp]# setenforce 0
[root@test tmp]# firewall-cmd --reload
success
[root@test tmp]# firewall-cmd --zone=public --list-ports
1521/tcp 5500/tcp 5502/tcp
制作模板,生成快照准备安装Oracle数据库
配置内核参数
[root@Slave01 tmp]# vi /etc/sysctl.conf
# 内容如下
# 为Oracle安装配置内核参数
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享内存的总量,8G内存设置:2097152
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存端的最大数
kernel.sem=250 32000 100 128
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4端口范围
net.core.rmem_default = 262144
net.core.rmem_max= 4194304
net.core.wmem_default= 262144
net.core.wmem_max= 1048576
# 设置生效
[root@Slave01 tmp]# sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享内存的总量,8G内存设置:2097152
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存端的最大数
kernel.sem = 250 32000 100 128
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4端口范围
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
用户设置
[root@test tmp]# vi /etc/security/limits.conf
# 将下面内容添加到 limits.conf
# oracle用户优化配置
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
[root@test tmp]# vi /etc/pam.d/login
# 将下面内容添加到login
# 进程配置
session required /lib64/security/pam_limits.so
session required pam_limits.so
[root@test tmp]# vi /etc/profile
# 将下面内容添加到export之前
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
# 使配置文件生效
[root@Slave01 tmp]# source /etc/profile
配置环境变量
[root@test tmp]# vi /home/oracle/.bash_profile
# 找到下列语句
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
# 在其之前添加如下内容
# 配置Oracle环境
export ORACLE_HOSTNAME=test
export ORACLE_BASE=/data/oracle #oracle数据库安装目录
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1 #oracle数据库路径
export ORACLE_SID=test #oracle启动数据库实例名
export ORACLE_UNQNAME=test
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #添加系统环境变量
export LANG=en_US #防止安装过程出现乱码
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_DATE_FORMST="YYYY-MM-DD HH24:MI:SS"
# 配置完成后,建议重启系统 或分别执行以下命令:
# 建议重启服务器
[root@test ~]# source /home/oracle/.bash_profile
[root@test ~]# env
目录赋权
#将目录的权限赋给oracle用户
[root@test ~]# chown -R oracle:oinstall /data
配置数据库安装响应文件
使用Oracle用户
# 切换用户,使配置文件生效
[root@test ~]# su oracle
[oracle@test root]$ source /home/oracle/.bash_profile
# 切换目录备份响应文件
[oracle@test root]$ cd /data/soft/database/response
[oracle@test response]$ ls
dbca.rsp db_install.rsp netca.rsp
[oracle@test response]$ cp db_install.rsp db_install.rsp.bak
# 修改响应文件
# 为确保每条都被执行,建议单条粘贴执行
sed -i "s/^oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/g" db_install.rsp
sed -i "s/^UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/g" db_install.rsp
sed -i "s/^INVENTORY_LOCATION=/INVENTORY_LOCATION=\/data\/oraInventory/g" db_install.rsp
sed -i "s/^SELECTED_LANGUAGES=en/SELECTED_LANGUAGES=en,zh_CN/g" db_install.rsp
sed -i "s/^ORACLE_HOME=/ORACLE_HOME=\/data\/oracle\/product\/12.2.0\/db_1/g" db_install.rsp
sed -i "s/^ORACLE_BASE=/ORACLE_BASE=\/data\/oracle/g" db_install.rsp
sed -i "s/^oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/g" db_install.rsp
sed -i "s/^oracle.install.db.OSDBA_GROUP=/oracle.install.db.OSDBA_GROUP=dba/g" db_install.rsp
sed -i "s/^oracle.install.db.OSOPER_GROUP=/oracle.install.db.OSOPER_GROUP=oinstall/g" db_install.rsp
sed -i "s/^oracle.install.db.OSBACKUPDBA_GROUP=/oracle.install.db.OSBACKUPDBA_GROUP=dba/g" db_install.rsp
sed -i "s/^oracle.install.db.OSDGDBA_GROUP=/oracle.install.db.OSDGDBA_GROUP=dba/g" db_install.rsp
sed -i "s/^oracle.install.db.OSKMDBA_GROUP=/oracle.install.db.OSKMDBA_GROUP=dba/g" db_install.rsp
sed -i "s/^oracle.install.db.OSRACDBA_GROUP=/oracle.install.db.OSRACDBA_GROUP=dba/g" db_install.rsp
sed -i "s/^oracle.install.db.config.starterdb.type=/oracle.install.db.config.starterdb.type=GENERAL_PURPOSE/g" db_install.rsp
# 设置全局数据库名为test
sed -i
"s/^oracle.install.db.config.starterdb.globalDBName=/oracle.install.db.config.starterdb.globalDBName=test/g" db_install.rsp
# 修改SID为test
sed -i "s/^oracle.install.db.config.starterdb.SID=/oracle.install.db.config.starterdb.SID=test/g" db_install.rsp
sed -i "s/^oracle.install.db.config.starterdb.characterSet=/oracle.install.db.config.starterdb.characterSet=ZHS16GBK/g" db_install.rsp
# 修改数据库软件的管理密码为managertest
sed -i "s/^oracle.install.db.config.starterdb.password.ALL=/oracle.install.db.config.starterdb.password.ALL=managertest/g" db_install.rsp
sed -i "s/^SECURITY_UPDATES_VIA_MYORACLESUPPORT=/SECURITY_UPDATES_VIA_MYORACLESUPPORT=false/g" db_install.rsp
sed -i "s/^DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/g" db_install.rsp
静默安装Oracle12c
# 回到database目录
[oracle@test response]$ cd /data/soft/database/
# 安装软件
[oracle@test database]$ ./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /data/soft/database/response/db_install.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 500 MB. Actual 8297 MB Passed
Checking swap space: must be greater than 150 MB. Actual 8191 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-11-18_11-27-52PM. Please wait ...[oracle@Slave01 database]$ You can find the log of this install session at:
/data/oraInventory/logs/installActions2021-11-18_11-27-52PM.log
The installation of Oracle Database 12c was successful.
Please check '/data/oraInventory/logs/silentInstall2021-11-18_11-27-52PM.log' for more details.
As a root user, execute the following script(s):
1. /data/oraInventory/orainstRoot.sh
2. /data/oracle/product/12.2.0/db_1/root.sh
Successfully Setup Software.
# 新建会话使用root用户执行sh脚本
[root@test ~]# /data/oraInventory/orainstRoot.sh
Changing permissions of /data/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /data/oraInventory to oinstall.
The execution of the script is complete.
[root@test ~]# /data/oracle/product/12.2.0/db_1/root.sh
Check /data/oracle/product/12.2.0/db_1/install/root_Slave01_2021-11-18_23-33-34-644861766.log for the output of root script
配置Oracle监听
使用Oracle用户
# 用Oracle用户配置监听
[oracle@test database]$ netca /silent /responseFile /data/soft/database/response/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/soft/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/oracle/product/12.2.0/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
创建数据库
# 备份dbca文件
[oracle@test database]$ cd /data/soft/database/response
[oracle@test response]$ ls
dbca.rsp db_install.rsp db_install.rsp.bak netca.rsp
[oracle@test response]$ cp dbca.rsp dbca.rsp.bak
# 修改dbca响应文件
# 修改全局数据库名为test
sed -i 's/^gdbName=/gdbName=slave/g' dbca.rsp
# 修改sid为test
sed -i 's/^sid=/sid=slave/g' dbca.rsp
sed -i 's/^databaseConfigType=/databaseConfigType=SI/g' dbca.rsp
sed -i 's/^storageType=/storageType=FS/g' dbca.rsp
# 修改管理密码为managertest
sed -i 's/^sysPassword=/sysPassword=managertest/g' dbca.rsp
sed -i 's/^systemPassword=/systemPassword=managertest/g' dbca.rsp
sed -i 's/^oracleHomeUserPassword=/oracleHomeUserPassword=managertest/g' dbca.rsp
sed -i 's/^datafileDestination=/datafileDestination=\/data\/oradata/g' dbca.rsp
sed -i 's/^recoveryAreaDestination=/recoveryAreaDestination=\/data\/oracle\/fast_recovery_area/g' dbca.rsp
sed -i 's/^characterSet=/characterSet=ZHS16GBK/' dbca.rsp
sed -i 's/^templateName=/templateName=\/data\/oracle\/product\/12.2.0\/db_1\/assistants\/dbca\/templates\/General_Purpose.dbc/g' dbca.rsp
sed -i 's/^listeners=/listeners=LISTENER/g' dbca.rsp
# 设置Oracle使用系统内存上限
sed -i 's/^totalMemory=/totalMemory=5000/g' dbca.rsp #值设置为物理内存的60%
# 创建数据库
[oracle@test response]$ cd /data/soft/database
[oracle@test database]$ dbca -silent -createDatabase -responseFile /data/soft/database/response/dbca.rsp
[WARNING] [DBT-11207] Specified SGA size is greater than the shmmax on the system. This might make database creation to fail with ORA-27125 - Unable to create shared memory segment error.
ACTION: Specify SGA size lesser than or equal to the shmmax on the system.
[WARNING] [DBT-06208] The 'SYS' password entered does not conform to the Oracle recommended standards.
CAUSE:
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'SYSTEM' password entered does not conform to the Oracle recommended standards.
CAUSE:
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
Copying database files
1% complete
2% complete
查看监听状态
如果未启动,请启动监听
[oracle@test database]$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-NOV-2021 23:46:06
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=Slave01)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 18-NOV-2021 23:34:33
Uptime 0 days 0 hr. 11 min. 33 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/Slave01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=Slave01)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "slave" has 1 instance(s).
Instance "slave", status READY, has 1 handler(s) for this service...
Service "slaveXDB" has 1 instance(s).
Instance "slave", status READY, has 1 handler(s) for this service...
The command completed successfully
配置dbconsole
# 用sysdba用户登录数据库
[oracle@test database]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Thu Nov 18 23:53:43 2021
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> conn /as sysdba
Connected.
# 设置端口
SQL> EXEC DBMS_XDB_CONFIG.SETHTTPSPORT(5500);
PL/SQL procedure successfully completed.
SQL> SQL> EXEC DBMS_XDB_CONFIG.SETHTTPPORT(5502);
SP2-0734: unknown command beginning "SQL> EXEC ..." - rest of line ignored.
SQL> EXEC DBMS_XDB_CONFIG.SETHTTPPORT(5502);
PL/SQL procedure successfully completed.
# 查看结果
SQL> select dbms_xdb_config.gethttpsport() from dual;
DBMS_XDB_CONFIG.GETHTTPSPORT()
------------------------------
5500
SQL> select dbms_xdb_config.gethttpport() from dual;
DBMS_XDB_CONFIG.GETHTTPPORT()
-----------------------------
5502
访问em控制台
em控制台需要浏览器添加flash插件,Windows10以后不再支持flash插件,Windowsserver相关版本对网页的控制又太高,本人使用windows7虚拟机ie浏览器添加flash插件完成相关操作。
用户权限控制
本人使用新建用户分配resource和connect权限用以控制相关资源的建立(需要赋数据空间的使用权),新建用户分配connect权限用于访问数据。
对于所有表的读写权限全部通过sys用户控制。