实际开发过程中,如果项目不是非得用Oracle及Centos的话,还是建议可以使用MySQL或者是数据库申请Windows服务器,因为在centos上面安装Oracle比MySQL要复杂的多。之前用过图形化安装Oracle,我感觉还是有些复杂,所以本篇介绍Oracle的静默安装步骤(我以后反正是能不用centos安装Oracle就不用)。
1. 安装前准备
- 关闭防火墙,禁止防火墙开机自启
systemctl stop firewalld.service --关闭防火墙
systemctl disable firewalld.service -- 禁止防火墙开机启动
systemctl status firewalld.service -- 查看防火墙状态
- 关闭selinux
vi /etc/selinux/config -- 编辑文件
SELINUX=disabled --修改
- yum安装必要安装包
#若执行一遍失败则执行第二遍
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
#检查是否安装成功(31个安装包)
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
2. 创建用户组
- 创建oinstall和dba组
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba - 创建oracle用户
/usr/sbin/useradd -g oinstall -G dba oracle - 设置oracle密码
passwd oracle - 查看创建结果
id oracle
3. 修改内核参数 - 编辑配置文件
vi /etc/sysctl.conf - 文件内容添加
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967296
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
- 使配置生效
/sbin/sysctl -p
4. 修改配置 - 修改用户限制
编辑文件: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
- 修改 /etc/pam.d/login
vi /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
- 修改/etc/profile
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 /home/db/
chown -R oracle:oinstall /home/db/
chmod -R 775 /home/db/
5. 配置oracle用户
#切换到oracle用户下
su - oracle
- 配置oracle用户环境变量
vi ~/.bash_profile
#添加
export ORACLE_BASE=/home/db/oracle
export ORACLE_SID=orcl
#使配置生效
source ~/.bash_profile - 上传数据库压缩包
创建一个文件夹:mkdir oradb
上传成功后,安装解压插件:
切换到root用户
su - root
yum install -y unzip zip
解压文件:
切换到oracle用户
su - oracle
unzip xxx.zip
复制相应的模板:mkdir etc
cp /home/oracle/oradb/database/response/* /home/oracle/etc/
#设置权限
su - root
chmod 700 /home/oracle/etc/*.rsp
静默安装文件配置:
返回oracle用户
su - oracle
#编辑
/home/oracle/etc/db_install.rsp
vi /home/oracle/etc/db_install.rsp
#文件内容修改为
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/db/oraInventory
SELECTED_LANGUAGES=en
ORACLE_HOME=/home/db/oracle/product/12/db_1
ORACLE_BASE=/home/db/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=oinstall
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.rac.configurationType=
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.rac.serverpoolName=
oracle.install.db.rac.serverpoolCardinality=
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.ConfigureAsContainerDB=
oracle.install.db.config.PDBName=
oracle.install.db.config.starterdb.characterSet=
oracle.install.db.config.starterdb.memoryOption=
oracle.install.db.config.starterdb.memoryLimit=81920
oracle.install.db.config.starterdb.installExampleSchemas=
oracle.install.db.config.starterdb.password.ALL=oracle
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.password.PDBADMIN=
oracle.install.db.config.starterdb.managementOption=
oracle.install.db.config.starterdb.omsHost=
oracle.install.db.config.starterdb.omsPort=
oracle.install.db.config.starterdb.emAdminUser=
oracle.install.db.config.starterdb.emAdminPassword=
oracle.install.db.config.starterdb.enableRecovery=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
COLLECTOR_SUPPORTHUB_URL=
6. 开始安装
- 执行文件db_install.rsp
切换到database文件夹下,执行./runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp
查看日志:tail -f xxx.log,成功后结果为:
- 执行命令
#执行下方命令
su - root
/home/db/oraInventory/orainstRoot.sh
/home/db/oracle/product/12/db_1/root.sh - 修改oracle用户环境变量
su - oracle
vim ~/.bash_profile
export ORACLE_BASE=/home/db/oracle
export ORACLE_SID=orcl
export ROACLE_PID=oral12
#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_HOME=/hoem/db/oracle/product/12/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
#使配置生效
source ~/.bash_profile
- 配置监听
netca /silent /responsefile /home/oracle/etc/netca.rsp
#启动监听
lsnrctl start
- 静默建库配置文件修改
vi etc/dbca.rsp
#文件内容
responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=orcl
sid=orcl
databaseConfigType=SI
createAsContainerDatabase=true
numberOfPDBs=1
pdbName=orclpdb
templateName=/home/db/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
- 执行静默建库
dbca -silent -createDatabase -responseFile /home/oracle/etc/dbca.rsp
最终结果:
数据库安装成功。
创建oracle 用户
sqlplus / as sysdba ;
create user 用户名 identified by 口令[即密码];
grant connect, resource,dba to 用户名;
7. 总结
还是不建议再centos上面安装Oracle,多数场景没啥意义,用MySQL或者是再Windows上面安装Oracle不香嘛。