Centos7静默安装Oracle11g
环境及配置调整
操作系统版本、内核版本、系统CPU、RAM、硬盘配置如下
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
[root@localhost ~]# cat /proc/cpuinfo| grep "processor"| wc -l
8
[root@localhost ~]# cat /proc/meminfo| grep MemTotal
MemTotal: 131826144 kB
[root@localhost ~]# cat /proc/meminfo| grep SwapTotal
SwapTotal: 1835004 kB
[root@localhost ~]# fdisk -l|grep Disk
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk label type: dos
Disk identifier: 0x000e4fd0
Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Disk /dev/mapper/centos-root: 18.5 GB, 18513657856 bytes, 36159488 sectors
Disk /dev/mapper/centos-swap: 1879 MB, 1879048192 bytes, 3670016 sectors
如下表所示
| 项目 | 值 |
|---|---|
| 操作系统 | CentOS Linux release 7.7.1908 (Core) |
| 内核版本 | 3.10.0-1062.el7.x86_64 |
| CPU | 8C |
| RAM | 128GB |
| SWAP | 1GB |
| 磁盘 | /dev/vda 20G + /dev/vdb 2TB |
数据盘未做格式化分区(这里仅格式化并挂载到单独目录,不做分区)
根据内存大小需要对此操作系统重新分配合适的swap空间(这里增加到16G),关于swap分区大小可参考红帽官方说明
[root@localhost ~]# mkfs.xfs /dev/vdb
[root@localhost ~]# mkdir /data && mount /dev/vdb /data
[root@localhost ~]# df -h | grep "data"
/dev/vdb 2.0T 33M 2.0T 1% /data
[root@localhost ~]# blkid |grep vdb|awk '{print $2}'|cut -d '=' -f 2
"11eda493-b248-4ce0-91fb-e28e1b8164a9"
[root@localhost ~]# echo "UUID=11eda493-b248-4ce0-91fb-e28e1b8164a9 /data xfs defaults 0 0" >> /etc/fstab # 开机自动挂载数据盘
[root@localhost ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab # 关掉原来的swap开机自动挂载
[root@localhost ~]# dd if=/dev/zero of=/data/swapfile bs=1G count=16
[root@localhost ~]# mkswap /data/swapfile
[root@localhost ~]# chmod 600 /data/swapfile
[root@localhost ~]# swapon /data/swapfile
[root@localhost ~]# echo "/data/swapfile swap swap defaults 0 0" >> /etc/fstab # 开机自动挂载swap分区
常用参数
修改主机名、关闭selinux、时间同步等
[root@localhost ~]# hostnamectl set-hostname oracledb-01
[root@localhost ~]# echo "127.0.0.1 oracledb-01" >> /etc/hosts
[root@oracledb-01 ~]# sestatus
SELinux status: disabled
其他准备
-
安装依赖
[root@oracledb-01 ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-dev libXi libXtst make sysstat unixODBC unixODBC-devel -
下载
oracle安装包从官网下载
linux64位安装包,下载后两个文件如下[root@oracledb-01 ~]# ls linux.x64_11gR2_database_2of2linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip -
创建用户:安装
Oracle数据库,需要以下本地操作系统组和用户- Oracle inventory组(通常为 oinstall)
- OSDBA组 (通常为 dba)
- OSOPER组 (通常为 oper)
- Oracle软件所有者(通常为 oracle)
[root@oracledb-01 ~]# groupadd oinstall[root@oracledb-01 ~]# groupadd dba[root@oracledb-01 ~]# groupadd oper[root@oracledb-01 ~]# useradd -g oinstall -G dba oracle -
修改oracle用户的密码
[root@oracledb-01 ~]# echo "oracle" | passwd --stdin oracleChanging password for user oracle.passwd: all authentication tokens updated successfully. -
配置资源限制和内核参数
在
/etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能fs.aio-max-nr = 1048576 # 同时可以拥有的的异步IO请求数目fs.file-max = 6815744 # 指定可以分配的文件句柄的最大数目kernel.shmall = 2097152 # 共享内存总量kernel.shmmax = 536870912 # 共享内存段的最大尺寸kernel.shmmni = 4096 # 系统范围内共享内存段的最大数 量kernel.sem = 250 32000 100 128net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 262144 # 接收缓冲区大小net.core.rmem_max = 4194304 # 接收缓冲区最大值net.core.wmem_default = 262144 # 默认的发送缓冲区大小net.core.wmem_max = 1048576 # 发送缓冲区最大值使内核参数生效
[root@oracledb-01 ~]# sysctl -p编辑
/etc/security/limits.conf(用户限制配置文件),添加如下参数oracle soft nproc 2047oracle hard nproc 16384oracle soft nofile 1024oracle hard nofile 65536编辑
/etc/pam.d/login文件,将配置文件加入到登录验证模块#Add for Install Oracle Database 11gsession required /lib64/security/pam_limits.sosession required pam_limits.so编辑
/etc/profile文件(环境变量文件)[root@oracledb-01 ~]# vim /etc/profileif [ $USER = "oracle" ]; thenif [ $SHELL = "/bin/ksh" ]; thenulimit -p 16384ulimit -n 65536elseulimit -u 16384 -n 65536fifi[root@oracledb-01 ~]# source /etc/profile禁用使用
Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)-
查看是否启用 如果显示
[always]说明启用了 -
禁用Transparent HugePages,在/etc/grub.conf添加如下内容
[root@oracledb-01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled[always] madvise never[root@oracledb-01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled重新启动系统以使上述更改成为永久更改
-
oracle安装
基本配置
-
创建
oracle安装目录[root@oracledb-01 ~]# mkdir -p /data/app/[root@oracledb-01 ~]# chown -R oracle:oinstall /data/app/[root@oracledb-01 ~]# chmod -R 775 /data/app/ -
配置
oracle用户环境变量在文件/home/oracle/.bash_profile里添加下面内容umask 022export ORACLE_HOSTNAME=oracledb-01 # 修改成主机名export ORACLE_BASE=/data/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0/export ORACLE_SID=ORCLexport ORACLE_UNQNAME=orclexport PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATHexport LC_ALL="en_US"export LANG="en_US"export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"由于新增了环境变量,再次重启系统
解压安装包
[root@oracledb-01 ~]# cd linux.x64_11gR2_database_2of2/
[root@oracledb-01 linux.x64_11gR2_database_2of2]# ls
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_1of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_2of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# mkdir -p /data/etc
[root@oracledb-01 linux.x64_11gR2_database_2of2]# cp /data/database/response/* /data/etc/
正式安装
修改文件/data/etc/db_install.rsp中以下变量的值
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracledb-01 # 修改成主机名
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
执行安装脚本
[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ cd /data/database/
[oracle@oracledb-01 database]$ ./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
安装时可以根据安装提示查看日志
[root@oracledb-01 ~]# tail -f /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
安装完成后会有如下提示
You can find the log of this install session at:
/data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/data/app/oracle/inventory/orainstRoot.sh
/data/app/oracle/product/11.2.0/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue
Successfully Setup Software.
按照上述提示进行操作,使用root用户运行脚本
[oracle@oracledb-01 ~]$ su - root
Password:
[root@oracledb-01 ~]# sh /data/app/oracle/inventory/orainstRoot.sh
Changing permissions of /data/app/oracle/inventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /data/app/oracle/inventory to oinstall.
The execution of the script is complete.
[root@oracledb-01 ~]# sh /data/app/oracle/product/11.2.0/root.sh
Check /data/app/oracle/product/11.2.0/install/root_oracledb-01_2020-10-31_09-46-20.log for the output of root script
配置监听
[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ 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
查看监听端口
[oracle@oracledb-01 database]$ netstat -tnpl | grep 1521
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::1521 :::* LISTEN 6064/tnslsnr