目录
- 一、环境准备
- 1.安装依赖
- 2.查看libaiobaio版本
- 3.修改host,绑定主机名
- 4.关闭selinux
- 二、安装配置
- 1.创建组、用户
- 2.修改内核参数
- 3.配置Oracle用户参数
- 4.修改/etc/pam.d/login 文件
- 5.修改/etc/profile 文件
- 6.创建数据库相关目录
- 7.安装包上传、解压
- 8.添加环境变量
- 三、部署
- 1.修改db_install.rsp
- 2.安装数据库
- 3.监听安装
- 4.监听状态查看
- 5.静默建库
- 6.登录查看
- 四、系统服务注册
- 1.dbstart文件修改
- 2.dbshut文件修改
- 3.oratab文件修改
- 4.系统服务文件编写
一、环境准备
1.安装依赖
在线安装
[root@localhost ~]# yum install libnsl libnsl2-devel libaio-devel libcap-devel xorg-x11-utils xauth gcc make libstdc++-devel sysstat smartmontools glibc-compat-2.17
若服务器无法连接网络,可使用离线安装:在可以使用互联网的服务器上运行以下命令,将把相关依赖下载至/root/rpm目录下
[root@localhost ~]# yum -y install yum-utils
[root@localhost ~]# yumdownloader --destdir=/root/rpm --resolve libnsl libnsl2-devel libaio-devel libcap-devel xorg-x11-utils xauth gcc make libstdc++-devel sysstat smartmontools glibc-compat-2.17
--destdir 指定下载的软件包存放路径
--resolve 解决依赖关系并下载所需的包
2.查看libaiobaio版本
libaio库版本不能大于0.3.109,libaio版本太高,会造成编译错误
[root@localhost ~]# rpm -qa libaio
libaio-0.3.109-13.el7.x86_64[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
若版本太高,需下载指定版本(libaio-0.3.109)
# 下载
[root@localhost ~]# wget http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm# 备份原来的libaio.so.1
[root@localhost ~]# mv /usr/lib64/libaio.so.1 /usr/lib64/libaio.so.1-bak# 解压
[root@localhost ~]# rpm2cpio libaio-0.3.109-13.el7.x86_64.rpm |cpio -idmv# 把解压后的文件拷贝到/usr/lib64下
[root@localhost ~]# cp -r /lib64/libaio.so.1 /usr/lib64
[root@localhost ~]# cp -r /lib64/libaio.so.1.0.1 /usr/lib64# 执行安装
[root@localhost ~]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm --force --nodeps
3.修改host,绑定主机名
修改 vim /etc/hosts文件
# 设置主机名
[root@localhost ~]# hostnamectl set-hostname db && bash# 查看主机名
[root@db ~]# hostname
db# 配置本地解析
[root@db ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.16.32.13 db
4.关闭selinux
设置SELINUX= enforcing 为SELINUX=disabled
# 修改
命令方式:
[root@db ~]# vim /etc/selinux/config
命令方式:
[root@db ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config# 重启服务器、查看是否修改成功
[root@db ~]# setenforce 0
setenforce: SELinux is disabled
二、安装配置
1.创建组、用户
添加oinstall 、dba 组,新建oracle用户并加入oinstall、dba组中
[root@db ~]# groupadd oinstall
[root@db ~]# groupadd dba
[root@db ~]# useradd -g oinstall -G dba oracle
[root@db ~]# passwd oracle
2.修改内核参数
[root@db ~]# vim /etc/sysctl.conf
在文档最后加入以下内容:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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让参数生效:
[root@db ~]# /sbin/sysctl -p
3.配置Oracle用户参数
[root@db ~]# vim /etc/security/limits.conf
在文档最后加入以下内容:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
4.修改/etc/pam.d/login 文件
[root@db ~]# vim /etc/pam.d/login
在文档最后加入以下内容:
session required /lib64/security/pam_limits.so
session required pam_limits.so
5.修改/etc/profile 文件
[root@db ~]# vim /etc/profile
在文档最后加入以下内容:if [ $USER = "oracle" ]; thenif [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384ulimit -n 65536else ulimit -u 16384 -n 65536fi
fi# 重新加载配置
[root@db ~]# source /etc/profile
6.创建数据库相关目录
创建安装目录app、静默安装目录etc
[root@db ~]# mkdir -p /apps/oracle/app/
[root@db ~]# mkdir -p /apps/oracle/etc/
[root@db ~]# chown -R oracle:oinstall /apps/oracle
[root@db ~]# chmod 775 /apps/oracle
7.安装包上传、解压
上传oracle安装包到:/apps/oracle/app/下,并解压,将生成一个database目录
切换oracle用户、上传安装包并解压
[root@db ~]# su - oracle
[oracle@db app]$ unzip p13390677_112040_Linux-x86-64_1of7.zip
[oracle@db app]$ unzip p13390677_112040_Linux-x86-64_2of7.zip# 安装包下载链接:
https://updates.oracle.com/Orion/Services/download/p13390677_112040_Linux-x86-64_1of7.zip?aru=16716375&patch_file=p13390677_112040_Linux-x86-64_1of7.zip
https://updates.oracle.com/Orion/Services/download/p13390677_112040_Linux-x86-64_2of7.zip?aru=16716375&patch_file=p13390677_112040_Linux-x86-64_2of7.zip
拷贝/apps/oracle/app/database/response的.rsp文件到/apps/oracle/etc/目录下
[oracle@db app]$ cp /apps/oracle/app/database/response/* /apps/oracle/etc/
8.添加环境变量
# 切换oracle用户
[root@db ~]# su - oracle编辑环境变量,并生效
[oracle@db app]$ vim ~/.bash_profile内容如下:# oracle安装目录
export ORACLE_BASE=/apps/oracle/app
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
# oracle实例SID名称
export ORACLE_SID=orcl
# 同SID
export ORACLE_TERM=orcl
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LANG=C
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
# 同SID
export ORACLE_UNQNAME=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export PATH
export SQLPATH=/apps/oracle/labs[oracle@db app]$ source ~/.bash_profile# 验证是否生效
[oracle@db app]$ echo $ORACLE_HOME
/apps/oracle/app/product/11.2.0(与~/.bash_profile中配置一致即生效)
三、部署
1.修改db_install.rsp
编辑/apps/oracle/etc/目录下db_install.rsp,参考下述配置,根据实际编写
[oracle@db app]$ cat /apps/oracle/etc/db_install.rsp | grep -v "#" | grep -v "^$"
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=db
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/apps/oracle/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/apps/oracle/app/product/11.2.0
ORACLE_BASE=/apps/oracle/app
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=
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.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
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=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=
2.安装数据库
2.1、在路径:/apps/oracle/app/database/下执行命令
./runInstaller -silent -force -responseFile /apps/oracle/etc/db_install.rsp -ignorePrereq
2.2、切换root用户执行(有时候可能只有一个root.sh,也是正常的)
以 root 用户的身份执行以下脚本
[root@db ~]# /apps/oracle/app/oraInventory/orainstRoot.sh
[root@db ~]# /apps/oracle/app/product/11.2.0/root.sh
3.监听安装
[oracle@db database]$ cd /apps/oracle/app/product/11.2.0/bin
[oracle@db bin]$ ./netca /silent /responsefile /apps/oracle/etc/netca.rsp
若报错
UnsatisfiedLinkError exception loading native library: njni11
java.lang.UnsatisfiedLinkError: /apps/oracle/app/product/11.2.0/lib/libnjni11.so: libclntsh.so.11.1: cannot open shared object file: No such file or directory
java.lang.UnsatisfiedLinkError: jniGetOracleHomeat oracle.net.common.NetGetEnv.jniGetOracleHome(Native Method)at oracle.net.common.NetGetEnv.getOracleHome(Unknown Source)at oracle.net.ca.NetCALogger.getOracleHome(NetCALogger.java:230)at oracle.net.ca.NetCALogger.initOracleParameters(NetCALogger.java:215)at oracle.net.ca.NetCALogger.initLogger(NetCALogger.java:130)at oracle.net.ca.NetCA.main(NetCA.java:427)Error: jniGetOracleHome
Oracle Net Services 配置失败。退出代码是1
解决方法
[oracle@db bin]$ cp /apps/oracle/appbase/stage/ext/lib/libclntsh.so.11.1 /apps/oracle/app/product/11.2.0/lib/
4.监听状态查看
[oracle@db bin]$ lsnrctl status
5.静默建库
5.1、编辑/apps/oracle/etc/目录下dbca.rsp,参考下述配置,根据实际编写
[oracle@db ~]$ cat /apps/oracle/etc/dbca.rsp | grep -v '#' | grep -v '^$'
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "sysdba"
SYSTEMPASSWORD = "sysdba"
SYSMANPASSWORD = "sysdba"
DBSNMPPASSWORD = "sysdba"
CHARACTERSET = "ZHS16GBK"
TEMPLATENAME = "General_Purpose.dbc"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:orcl"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "orcl"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "orcl"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "orcl11.us.oracle.com"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "orcl"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "orcl"
INSTANCENAME = "orcl"
SYSDBAUSERNAME = "sys"
5.2、执行建库命令:
[oracle@db bin]$ cd /apps/oracle/app/product/11.2.0/bin
[oracle@db bin]$ ./dbca -silent -responseFile /apps/oracle/etc/dbca.rsp
6.登录查看
[oracle@db bin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Apr 15 11:36:06 2024
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
四、系统服务注册
1.dbstart文件修改
[oracle@db ~]$ echo $ORACLE_HOME
/apps/oracle/app/product/11.2.0修改/apps/oracle/app/product/11.2.0/bin/dbstart文件
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=/apps/oracle/app/product/11.2.0
2.dbshut文件修改
修改/apps/oracle/app/product/11.2.0/bin/dbshut文件
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=/apps/oracle/app/product/11.2.0
3.oratab文件修改
修改/etc/oratab文件
将orcl:/apps/oracle/app/product/11.2.0:N修改为orcl:/apps/oracle/app/product/11.2.0:Y
4.系统服务文件编写
oracle.service(root用户)
[Unit]
Description=Oracle Database 11g Startup/Shutdown Service
After=syslog.target network.target[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
Type=oneshot
RemainAfterExit=yes
User=oracle
Environment="ORACLE_HOME=/apps/oracle/app/product/11.2.0"
ExecStart=/apps/oracle/app/product/11.2.0/bin/dbstart $ORACLE_HOME >> 2>&1 &
ExecStop=/apps/oracle/app/product/11.2.0/bin/dbshut $ORACLE_HOME 2>&1 &[Install]
WantedBy=multi-user.target
将oracle.service放置于/etc/systemd/system/目录下,即可搭配systemctl命令启停oracle服务
# 开机自启动oracle服务
[root@db ~]# systemctl enable oracle
# 查看oracle服务状态
[root@db ~]# systemctl status oracle
# 手动启动oracle服务
[root@db ~]# systemctl start oracle
# 手动停止oracle服务
[root@db ~]# systemctl stop oracle
# 禁止oracle服务开机自启动
[root@db ~]# systemctl disable oracle