CentOS7.9部署Oracle整体思路
- 准备好CentOS7.9系统和Oracle安装包。Oracle下载链接:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
系统配置最低要求:1c,2G
可用内存 需要交换空间 介于1 GB和2 GB之间 RAM大小的1.5倍 介于2 GB和16 GB之间 等于RAM的大小 超过16 GB 16 GB - 导入安装包
- 检查软件环境依赖包
- Oracle前系统配置(Oracle部署前准备)
- 重启系统
- 部署Oracle
- 执行
- 配置监听程序
- 静默创建数据库
- 设置Oracle开机启动
- 启动文件提权
- 防火墙放通Oracle的端口或关闭防火墙
Oracle部署
系统环境准备
- 手动添加swap分区(若有swap分区可忽略)
dd if=/dev/zero of=/swap bs=1024 count=2048000 mkswap /swap chmod 600 /swap swapon /swap echo "/swap swap swap default 0 0">>/etc/fstab #设置成自动挂载
-
配置hostname
hostnamectl set-hostname oracledb echo "127.0.0.1 oracledb" >>/etc/hosts
-
关闭selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0
- 安装Oracle安装依赖环境
安装命令:
yum -y install 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
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
检查依赖包安装是否成功: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 | grep "not installed"
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 | wc -l - 创建用户组和用户
groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle
#Oracle inventory组(通常为 oinstall)
#OSDBA组 (通常为 dba)
#OSOPER组 (通常为 oper)
#Oracle软件所有者(通常为 oracle)
修改Oracle用户的密码:passwd oracle
- 配置内核参数和资源限制
在/etc/sysctl.conf
添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能
fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 536870912 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
在/etc/security/limits.conf
中添加如下参数:oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536
在/etc/pam.d/login文件中,添加下面内容:session required /lib64/security/pam_limits.so session required pam_limits.so
/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
使用/etc/profile
文件生效:source /etc/profile
禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages):
查看是否启用 如果显示[always]
说明启用了:
cat /sys/kernel/mm/transparent_hugepage/enabled
禁用Transparent HugePages,在/etc/grub.conf添加如下内容:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
重新启动系统更改成为永久更改 - 创建Oracle安装目录
mkdir -p /data/app/ chown -R oracle:oinstall /data/app/ chmod -R 775 /data/app/
- 配置Oracle用户环境变量
在文件/home/oracle/.bash_profile
里添加下面内容(具体值根据实际情况修改):
umask 022 export ORACLE_HOSTNAME=oracledb export ORACLE_BASE=/data/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/ export ORACLE_SID=ORCL export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH export LC_ALL="en_US" export LANG="en_US" export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK" export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
- 重启系统
reboot
- 安装Oracle
安装rpm安装包
rpm -ivh oracle-database-free-23c-1.0-1.el8.x86_64.rpm --force --nodeps
- 配置监听配置
su - oracle netca /silent /responsefile /data/etc/netca.rsp #输出结果 [oracle@oracledb ~]$ netca /silent /responsefile /data/etc/netca.rsp Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /data/etc/netca.rsp Done parsing command line arguments. Oracle Net Services Configuration: Profile configuration complete. Oracle Net Listener Startup: Running Listener Control: /data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER Listener Control complete. Listener started successfully. Listener configuration complete. Oracle Net Services configuration successful. The exit code is 0
查看监听
netstat -tnpl | grep 1521
- 创建数据库
编辑应答文件/data/etc/dbca.rsp
:
[GENERAL] RESPONSEFILE_VERSION = "11.2.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "orcl" SID = "orcl" SYSPASSWORD = "oracle" SYSTEMPASSWORD = "oracle" SYSMANPASSWORD = "oracle" DBSNMPPASSWORD = "oracle" DATAFILEDESTINATION =/data/app/oracle/oradata RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area CHARACTERSET = "AL32UTF8" TOTALMEMORY = "1638"
执行静默建库:
su - oracle dbca -silent -responseFile /data/etc/dbca.rsp
执行过程如下:
[oracle@oracledb ~]$ dbca -silent -responseFile /data/etc/dbca.rsp 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 "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
查看进程:
ps -ef | grep ora_ | grep -v grep # 执行结果 [oracle@oracledb ~]$ ps -ef | grep ora_ | grep -v grep oracle 19304 1 0 18:33 ? 00:00:00 ora_pmon_orcl oracle 19306 1 0 18:33 ? 00:00:00 ora_vktm_orcl oracle 19310 1 0 18:33 ? 00:00:00 ora_gen0_orcl oracle 19312 1 0 18:33 ? 00:00:00 ora_diag_orcl oracle 19314 1 0 18:33 ? 00:00:00 ora_dbrm_orcl oracle 19316 1 0 18:33 ? 00:00:00 ora_psp0_orcl oracle 19318 1 0 18:33 ? 00:00:00 ora_dia0_orcl oracle 19320 1 0 18:33 ? 00:00:00 ora_mman_orcl oracle 19322 1 0 18:33 ? 00:00:00 ora_dbw0_orcl oracle 19324 1 0 18:33 ? 00:00:00 ora_lgwr_orcl oracle 19326 1 0 18:33 ? 00:00:00 ora_ckpt_orcl oracle 19328 1 0 18:33 ? 00:00:00 ora_smon_orcl oracle 19330 1 0 18:33 ? 00:00:00 ora_reco_orcl oracle 19332 1 0 18:33 ? 00:00:00 ora_mmon_orcl oracle 19334 1 0 18:33 ? 00:00:00 ora_mmnl_orcl oracle 19336 1 0 18:33 ? 00:00:00 ora_d000_orcl oracle 19338 1 0 18:33 ? 00:00:00 ora_s000_orcl oracle 19361 1 0 18:34 ? 00:00:00 ora_qmnc_orcl oracle 19376 1 0 18:34 ? 00:00:00 ora_cjq0_orcl oracle 19396 1 0 18:34 ? 00:00:00 ora_q000_orcl oracle 19398 1 0 18:34 ? 00:00:00 ora_q001_orcl
查看监听状态:
$ lsnrctl status #结果 [oracle@oracledb ~]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 02-JAN-2019 18:36:15 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 02-JAN-2019 18:20:21 Uptime 0 days 0 hr. 15 min. 54 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/app/oracle/product/11.2.0/network/admin/listener.ora Listener Log File /data/app/oracle/diag/tnslsnr/oracledb/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb)(PORT=1521))) Services Summary... Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully [oracle@oracledb ~]$
- 登录数据库
su - oracle sqlplus / as sysdba select status from v$instance;
- 执行select时异常状态:
SQL> select status from v$instance; select status from v$instance * ERROR at line 1: ORA-01034: ORACLE not available Process ID: 0 Session ID: 0 Serial number: 0
- 执行select时异常处理方法:
输入startup
:
#startup的输出提示: SQL> statup SP2-0042: unknown command "statup" - rest of line ignored. SQL> startup ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
根据提示,将 O R A C L E B A S E / a d m i n / 数 据 库 名 称 / p f i l e 目 录 下 的 i n i t . o r a . x x x 形 式 的 文 件 c o p y 到 ORACLE_BASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到 ORACLEBASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到ORACLE_HOME/dbs目录下initOracle.ora(根据startup提示)即可
cp /data/app/oracle/admin/orcl/pfile/init.ora.022019183329 initORCL.ora
查看数据库编码:
select * from v$version; #结果 SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
激活scott用户
alter user scott account unlock; alter user scott identified by tiger; select username,account_status from dba_users;
- 设置Oracle开机自启动
修改/data/app/oracle/product/11.2.0/bin/dbstart
:
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改
/data/app/oracle/product/11.2.0/bin/dbshut
:ORACLE_HOME_LISTNER=$ORACLE_HOME
修改
vi /etc/oratab
orcl:/data/app/oracle/product/11.2.0:Y
新建文件
/etc/rc.d/init.d/oracle
:#! /bin/bash # oracle: Start/Stop Oracle Database 11g R2 # # chkconfig: 345 90 10 # description: The Oracle Database is an Object-Relational Database Management System. # # processname: oracle . /etc/rc.d/init.d/functions LOCKFILE=/var/lock/subsys/oracle ORACLE_HOME=/data/app/oracle/product/11.2.0 ORACLE_USER=oracle case "$1" in 'start') if [ -f $LOCKFILE ]; then echo $0 already running. exit 1 fi echo -n $"Starting Oracle Database:" su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start" su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole" touch $LOCKFILE ;; 'stop') if [ ! -f $LOCKFILE ]; then echo $0 already stopping. exit 1 fi echo -n $"Stopping Oracle Database:" su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop" su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut" su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole" rm -f $LOCKFILE ;; 'restart') $0 stop $0 start ;; 'status') if [ -f $LOCKFILE ]; then echo $0 started. else echo $0 stopped. fi ;; *) echo "Usage: $0 [start|stop|status]" exit 1 esac exit 0
给
/etc/init.d/oracle
添加执行权限:chmod +x /etc/init.d/oracle
开机启动oracle
systemctl enable oracle 或 chkconfig oracle on
给启动文件加权限
cd /data/app/oracle/product/11.2.0/bin/ chmod 6751 oracle cd /var/tmp chown -R oracle:oinstall .oracle
- 防火墙端口开放Oracle使用的端口或关闭防火墙
#关闭Oracle使用的端口
firewall-cmd --zone=public --add-port=1521/tcp --permanent firewall-cmd --reload
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
标签:00,部署,ORACLE,CentOS7.9,orcl,oracle,Oracle,ora From: https://www.cnblogs.com/sawyerhan/p/17734714.html