欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle 11g 静默安装

程序员文章站 2022-06-26 21:41:16
有时候会遇到命令行安装oracle和建库,没事就做个试验记录下1.配置Yum源及关闭SeLinux [root@rhel65 mnt]# mount /dev/sr0 /mntmount: block device /dev/sr0 is write-protected, mounting read ......

有时候会遇到命令行安装oracle和建库,没事就做个试验记录下
1.配置yum源及关闭selinux

[root@rhel65 mnt]# mount /dev/sr0 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only

[root@rhel65 ~]# cat /etc/yum.repos.d/iso.repo
[iso]
name=iso
baseurl=file:///mnt
enabled=1
gpgcheck=0

[root@rhel65 ~]# vi /etc/selinux/config
selinux=disabled

2.检查安装必要的rpm包
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
与上面不同,待检查
yum -y install binutils binutils-devel compat-libcap1 compat-libstdc++-33 compat-libstdc++-33.i686 ksh elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel glibc-headers gcc gcc-c++ libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libstdc++ libstdc++.i686 libstdc++-devel libstdc++-devel.i686 make sysstat unixodbc unixodbc-devel libxp libxp-devel libxpm-devel telnet

3.修改sysctl.conf文件
vi /etc/sysctl.conf
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
fs.aio-max-nr = 1048576
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

以上几个内核参数的大致含义如下
kernel.shmma:最大共享内存段,以字节为单位,物理内存*1024*1024*2,为物理内存的2倍。
kernel.shmmni:整个系统共享内存段的最大数目。
kernel.shmall:共享内存总量,以页为单位。
kernel.sem:每个信号对象集的最大信号对象数;系统范围内最大信号对象数;每个信号对象支持的最大操作数;系统范围内最大信号对象集数。
fs.file-max:文件句柄数,表示在linux系统中可以打开的文件数量。
net.ipv4.ip_local_port_range:应用程序可使用的ipv4端口范围。
net.core.rmem_default:套接字接收缓冲区大小的缺省值
net.core.rmem_max:套接字接收缓冲区大小的最大值
net.core.wmem_default:套接字发送缓冲区大小的缺省值
net.core.wmem_max:套接字发送缓冲区大小的最大值

使内核参数实时生效
sysctl -p

4.oracle用户设置shell限制
vi /etc/security/limits.conf
oracle soft nproc 65536
oracle hard nproc 65536
oracle soft nofile 65536
oracle hard nofile 65536

5.session登录安全设置
vi /etc/pam.d/login #增加以下一行
session required pam_limits.so

在/etc/profile末尾增加oracle相关限制
vi /etc/profile

#oracle判断
if [ \$user = "oracle" ]; then
if [ \$shell = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi

6.创建oracle用户,组(root用户)
创建oracle安装组oinstall,数据库管理员组dba,及oracle用户
groupadd oinstall
groupadd dba
useradd -g oinstall -g dba oracle
echo "oarcle" | passwd --stdin oracle
chmod -r 700 /home/oracle

/*
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/useradd -g oinstall -g dba oracle(主组oinstall,其它组:dba)
--passwd oracle
echo "oarcle" | passwd --stdin oracle
一句话修改账户密码的命令 echo "密码" | passwd --stdin 用户名

cat /etc/group
groupadd -g 54321 oinstall
groupadd -g 54322 dba
useradd -u 54321 -m -d /home/oracle -g oinstall -g dba oracle
id oracle
uid=54321(oracle) gid=54321(oinstall) 组=54321(oinstall),54322(dba)
groupadd oinstall 是创建用户组,用来做oracle的安装和维护工作
useradd 是创建用户
-m –d /home/oracle 是把/home/oracle目录作为oracle用户的主目录或登录默认目录
–g oinstall 是表示oracle用户的初始组为oinstall
–g dba 是表示oracle用户同时属于dba组,做数据维护,和数据库管理工作
*/

7.创建安装目录
mkdir -p /u01/app/oracle
--创建数据文件路径
mkdir -p /u01/app/oracle/oradata
mkdir -p /u01/app/orainventory
--创建闪回路径
mkdir -p /u01/app/oracle/fast_recovery_area
mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -r oracle:oinstall /u01/app/oracle
chown -r oracle:oinstall /u01/app
chmod -r 755 /u01/app

8.创建 oracle bash_profile
su - oracle
vi .bash_profile

export oracle_base=/u01/app/oracle;
export oracle_home=$oracle_base/product/11.2.0/db_1;
export oracle_sid=testdb;
export oracle_unqname=testdb;
export oracle_term=xterm;
export path=$oracle_home/bin:$path;
export ld_library_path=$oracle_home/lib:/lib:/usr/lib;
export nls_lang=american_america.zhs16gbk #数据库编码 zhs16gbk/utf8 任选一个
export nls_date_format=yyyy/mm/dd #数据库时间格式
#以下两个设置是用来设置rlwrap插件的环境,用来支持命令行回显功能
#alias sqlplus="rlwrap sqlplus"
#alias rman="rlwrap rman"
export path

#alias sqlplus="rlwrap sqlplus"
#alias rman="rlwrap rman"
umask 022
set –o vi
export sqlpath=/home/oracle/sqlpath
alias sql='sqlplus / as sysdba'
alias jdb='export oracle_home=$oracle_base/product/11.2.0/db;export oracle_sid=testdb'
alias bdump='cd /u01/app/oracle/diag/rdbms/testdb/testdb/trace'

--使配置生效
source /home/oracle/.bash_profile

[oracle@testdb ~]# . /home/oracle/.bash_profile

检查环境变量是否生效
env |grep ora

9.解压文件
unzip ...

10.静默文件配置/单节点为例
[root@rhel65 ~]# cd /home/oracle/soft/database/response/
[root@rhel65 response]# ls
dbca.rsp db_install.rsp netca.rsp
[root@rhel65 response]# grep -ev "^$|^#" db_install.rsp
#对照响应文件修改自己的配置,示例是安装在/u01/app目录下的
oracle.install.responsefileversion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=install_db_swonly ##// 安装类型 29行
oracle_hostname=rhel65 ##// 主机名称(hostname查询,这里要注意,主机名要在 /etc/hosts 文件中配置好ip对应关系,否则安装会报错) 37行
unix_group_name=oinstall ##// 安装组 42行
inventory_location=/u01/app/orainventory ##//inventory目录(不填就是默认值) 49行 这个文件不能放在oracle_base下
selected_languages=en,zh_cn,zh_tw ##// 选择语言 86行
oracle_home=/u01/app/oracle/product/11.2.0/db_1 ##// oracle_home 91行
oracle_base=/u01/app/oracle ##// oracle_base --96行
oracle.install.db.installedition=ee ##// oracle版本 107行
oracle.install.db.iscustominstall=false ##//自定义安装,否,使用默认组件 117行
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 ##// dba用户组 154行
oracle.install.db.oper_group=oinstall ##// oper用户组 160行
oracle.install.db.cluster_nodes=
oracle.install.db.israconeinstall=
oracle.install.db.raconeserviceame=
oracle.install.db.config.starterdb.type=general_purpose ##//数据库类型 189行
oracle.install.db.config.starterdb.globaldbname=testdb ##//globaldbname(这里要和第8步配置的sid一致) 194行
oracle.install.db.config.starterdb.sid=testdb ##//sid(这里要和第8步配置的sid一致)199行
oracle.install.db.config.starterdb.characterset=al32utf8 213行
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 ##//设定所有数据库用户使用同一个密码 262行
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=file_system_storage ##//这里是文件系统
oracle.install.db.config.starterdb.filesystemstorage.datalocation=/u01/app/oracle/oradata ##//数据文件路径 mkdir -p /u01/app/oracle/oradata
oracle.install.db.config.starterdb.filesystemstorage.recoverylocation=/u01/app/oracle/fast_recovery_area ##//闪回路径 mkdir -p /u01/app/oracle/fast_recovery_area
oracle.install.db.config.asm.diskgroup=
oracle.install.db.config.asm.asmsnmppassword=
myoraclesupport_username=
myoraclesupport_password=
security_updates_via_myoraclesupport=false (手动写了false) 388
decline_security_updates=true ##//设置安全更新(貌似是有bug,这个一定要选true,否则会无限提醒邮件地址有问题,终止安装。 400行
proxy_host=
proxy_port=
proxy_user=
proxy_pwd=
proxy_realm=
collector_supporthub_url=
oracle.installer.autoupdates.option=skip_updates ##//
oracle.installer.autoupdates.downloadupdatesloc=
autoupdates_myoraclesupport_username=
autoupdates_myoraclesupport_password=
[root@rhel65 response]#

安装
[root@rhel65 response]# su - oracle
[23:07:00 oracle(db_1)@rhel65 ~]$ cd /home/oracle/soft/database/response
[23:07:14 oracle(db_1)@rhel65 response]$ cd ..
[23:07:18 oracle(db_1)@rhel65 database]$ ./runinstaller -silent -showprogress -ignoresysprereqs -responsefile /home/oracle/soft/database/response/db_install.rsp

--yum install --nogpgcheck oracle-rdbms-server-11gr2-preinstall
--wget http://public-yum.oracle.com/rpm-gpg-key-oracle-ol7 -o /etc/pki/rpm-gpg/rpm-gpg-key-oracle

[23:49:14 oracle(db_1)@rhel65 database]$ ./runinstaller -silent -showprogress -ignoresysprereqs -responsefile /home/oracle/soft/database/response/db_install.rsp
starting oracle universal installer...

checking temp space: must be greater than 120 mb. actual 5173 mb passed
checking swap space: must be greater than 150 mb. actual 3999 mb passed
preparing to launch oracle universal installer from /tmp/orainstall2019-05-18_11-49-20pm. please wait ...[23:49:21 oracle(db_1)@rhel65 database]$ [warning] [ins-13014] target environment do not meet some optional requirements.
cause: some of the optional prerequisites are not met. see logs for details. /usr/oracle/orainventory/logs/installactions2019-05-18_11-49-20pm.log
action: identify the list of failed prerequisite checks from the log: /usr/oracle/orainventory/logs/installactions2019-05-18_11-49-20pm.log. then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
you can find the log of this install session at:
/usr/oracle/orainventory/logs/installactions2019-05-18_11-49-20pm.log

prepare in progress.
.................................................. 9% done.

prepare successful.

copy files in progress.
.................................................. 14% done.
.................................................. 20% done.
.................................................. 26% done.
.................................................. 32% done.
.................................................. 41% done.
.................................................. 46% done.
.................................................. 51% done.
.................................................. 56% done.
.................................................. 62% done.
.................................................. 67% done.
.................................................. 72% done.
.................................................. 77% done.
.................................................. 82% done.
........................................
copy files successful.

link binaries in progress.
..........
link binaries successful.

setup files in progress.
.................................................. 87% done.
.................................................. 94% done.

setup files successful.
the installation of oracle database 11g was successful.
please check '/usr/oracle/orainventory/logs/silentinstall2019-05-18_11-49-20pm.log' for more details.

execute root scripts in progress.

as a root user, execute the following script(s):
1. /usr/oracle/orainventory/orainstroot.sh
2. /u01/app/oracle/product/11.2.0/db_1/root.sh
.................................................. 100% done.

execute root scripts successful.
successfully setup software.

--root下执行上述2脚本
[19:19:42 root(db_1)@rhel65 ~]# /usr/oracle/orainventory/orainstroot.sh
changing permissions of /usr/oracle/orainventory.
adding read,write permissions for group.
removing read,write,execute permissions for world.

changing groupname of /usr/oracle/orainventory to oinstall.
the execution of the script is complete.
[19:19:43 root(db_1)@rhel65 ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh
check /u01/app/oracle/product/11.2.0/db_1/install/root_rhel65_2019-05-26_19-19-52.log for the output of root script


11.配置监听程序 切换oracle用户执行
[14:42:16 oracle(db_1)@rhel65 response]$ $oracle_home/bin/netca /testdb /responsefile /home/oracle/soft/database/response/netca.rsp

12.静默dbca建库
$oracle_home/bin/dbca -silent -responsefile /home/oracle/soft/database/response/dbca.rsp

需要设置以下参数,rsp中以下都被注释掉了,可以直接添加到最后
gdbname= "testdb"
sid ="testdb"
syspassword= "oracle"
systempassword= "oracle"
sysmanpassword= "oracle"
dbsnmppassword= "oracle"
datafiledestination=/u01/app/oracle/oradata
recoveryareadestination=/u01/app/oracle/fast_recovery_area
characterset= "zhs16gbk"
totalmemory= "2638"
#其中totalmemory ="1638" 为1638mb,物理内存2g*80%。

[19:28:56 oracle(db_1)@rhel65 ~]$ $oracle_home/bin/dbca -silent -responsefile /home/oracle/soft/database/response/dbca.rsp
enter sys user password:

enter system user password:

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
57% complete
60% complete
62% complete
completing database creation
66% complete
70% complete
73% complete
74% complete
85% complete
86% complete
98% complete
100% complete
look at the log file "/u01/app/oracle/cfgtoollogs/dbca/testdb/testdb.log" for further details.


[20:30:46 oracle(db_1)@rhel65 ~]$ sqlplus / as sysdba

sql*plus: release 11.2.0.4.0 production on sun may 26 20:30:48 2019

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

20:30:48 sys@testdb> select status from v$instance;

status
------------
open

elapsed: 00:00:00.00
20:30:50 sys@testdb>
数据库已open

[20:31:20 oracle(db_1)@rhel65 ~]$ lsnrctl status

lsnrctl for linux: version 11.2.0.4.0 - production on 26-may-2019 20:31:20

copyright (c) 1991, 2013, 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.4.0 - production
start date 26-may-2019 19:23:22
uptime 0 days 1 hr. 7 min. 58 sec
trace level off
security on: local os authentication
snmp off
listener parameter file /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
listener log file /u01/app/oracle/diag/tnslsnr/rhel65/listener/alert/log.xml
listening endpoints summary...
(description=(address=(protocol=ipc)(key=extproc1521)))
(description=(address=(protocol=tcp)(host=rhel65)(port=1521)))
services summary...
service "testdb" has 1 instance(s).
instance "testdb", status restricted, has 1 handler(s) for this service...
service "testdbxdb" has 1 instance(s).
instance "testdb", status restricted, has

监听已启动
数据库到这基本可以正常工作了。。。

//

一、主机信息查看
1、查看主机名 uname -a
2、查看主机版本 cat /etc/redhat-release
3、查看主机ip ifconfig -a
4、查看hosts解析 cat /etc/hosts
5、查看主机时间 date
6、查看主机磁盘 df -h
7、查看存储配置 multipath -l
8、查看主机防火墙 service iptables status
9、查看selinux配置 cat /etc/selinux/config
10、查看存储超时时间 cat /sys/block/sdb/device/timeout
11、查看系统硬件时钟 hwclock --show

二、主机基础信息可能的修改
1、修改主机时间 date -s 14:20:50
2、硬件同步的系统时钟 clock --systohc
系统同步硬件的时钟 clock --hctosys
3、停止防火墙 service iptables stop
防火墙不开机启动 chkconfig iptables off
确认防火墙状态 service iptables status
防火墙开机启动确认 chkconfig --list|grep iptables
4、删除主机ntp配置文件 rm -rf /etc/ntp.conf
5、修改selinux配置 sed -i '/enforcing/s/selinux=enforced/selinux=disabled/g' /etc/selinux/config
确认selinux修改 cat /etc/selinux/config

设置sar
默认sar记录为10分钟一次,改为1分钟一次
日志保存目录为/var/log/sa
运行频率修改,把时间*/10改为*/1,出下面
# vi /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/1 * * * * root /usr/lib64/sa/sa1 1 1
如果没有配置文件则需要安装sysstat-7.0.2-3.el5_5.1.x86_64.rpm包
日志保存时间,改为30天
# vi /etc/sysconfig/sysstat
history=30

增强提示符
为了使用同一用户oracle更好的分辨在哪个oracle_home中,使用以下增强的命令提示符
vi /etc/profile
export ps1='[\t \u(${oracle_home##*/})@\h \w]\$ '

设置sqlpath目录
sqlpath目录中的login.sql设置了登录sqlplus的环境变量
mkdir -p /home/oracle/sqlpath
vi login.sql
set term off
define_editor=vim
define loginname=idle
column global_name new_value loginname
select lower(user||'@'
||substr(global_name,1,decode(dot,0,length(global_name),dot-1))) global_name
from
(select global_name, instr(global_name,'.') dot
from global_name);
set sqlprompt '&loginname> '
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
set timing on
set time on
set serveroutput on <p align="justify"></p>
set linesize 130
set term on
set numwidth 13
set pagesize 1000
set echo on

在安装过程中涉及的几个文件位置及用途
/etc/sysctl.conf (修改内核参数)
/etc/security/limits.conf (shell对oracle用户的限制)
/etc/pam.d/login
/etc/profile (系统相关的环境变量)
/home/oracle/.bash_profile (oracle用户相关的环境变量)
/home/oracle(确保本目录空间足够大)
/etc/hosts (建立ip和机器名的关系,通过uname把地址和机器名关联,否则在安装数据库时报监听器错误)
/etc/sysconfig/network 修改机器名

使用yum安装缺失的rpm包
yum list
yum -y install rpm_name.rpm
yum makecache 是将服务器上的软件包信息 现在本地缓存,以提高 搜索 安装软件的速度
man yum 查看yum的帮助信息
yum 主要的一下命令如下:
yum search 软件包 搜索软件包
yum install 软件包 安装软件包
yum remove 软件包
yum update 更新系统
yum clean all 清除缓存目录下的软件包及旧的headers

执行完 yum makecache之后,你可以用
yum search subversion和yum -c search subversion 二者差别挺明显的,前者明显比后者慢

修改启动参数打开归档和闪回
# 修改spfile参数
alter system set log_archive_dest_1='location=/doea5/arch';
alter system set log_archive_format='arch_%t_%s_%r.log' scope=spfile;
alter system set db_recovery_file_dest_size=20g scope=spfile;
alter system set db_recovery_file_dest='/oracle/app/oracle/flash_recovery';
alter system set db_flashback_retention_target=10080 scope=spfile;
alter system set undo_retention=10800;

# 打开归档和闪回
shutdown immediate
startup mount
alter database archivelog ;
alter database flashback on;
alter database open;

防火墙设置
在文件【/etc/sysconfig/iptables】内增加以下内容:
-a input -m state --state new -m tcp -p tcp --dport 22 -j accept
-a input -m state --state new -m tcp -p tcp --dport 1521 -j accept
-a input -m state --state new -m tcp -p tcp --dport 1158 -j accept
oracle远程访问端口默认是1521,oem端口1158,若自定义新端口,请开放相应端口。
(新开放端口的配置必须紧跟着放在端口22的配置后面)
重启防火墙
[root@oracle sysconfig]# service iptables restart

关闭selinux和iptables
iptables -f
iptables -x
编辑/etc/selinux/config,状态变成disabled

chown oracle:oinstall -r /tmp/database
chmod +x -r /tmp/database

修改操作系统启动模式
把level 5的图形界面改为level 3的字符界面,启动操作系统后会进入字符界面
# vi /etc/inittab
id:3:initdefault:

清空resolv.conf
在生产环境中,不建议使用resolve.conf解析域名,可能会使客户端登录缓慢,建议清空它
vi /etc/resolv.conf
清空

参考下面进行参数设置
https://www.linuxidc.com/linux/2016-11/137543.htm

增强提示符
为了使用同一用户oracle更好的分辨在哪个oracle_home中,使用以下增强的命令提示符
# vi /etc/profile
export ps1='[\t \u(${oracle_home##*/})@\h \w]\$ '

配置ntp服务
根据公司的ntp策略,需要布置ntp脚本,从idc处取得ntpd-deploy.sh
目前有一份脚本存放在/u07/system_configuration/ntpd/for_linux目录
如果时间与实现的时间相关太多,先使用ntpdate手工同步一下
# ntpdate ntp-hb1.99bill.com
# ./ntpd-deploy.sh hb

gi环境的ntpd需要加上-x参数
# vi /etc/sysconfig/ntpd
加上参数-x
options="-x -u ntp:ntp -p /var/run/ntpd.pid"

为了保证bios时间和系统时间差别太大,ntpd会不同步,在系统重启时增加自动同步一次的脚本
# vi /etc/rc.local
ntpdate ntp-hb1.99bill.com

设置sar
默认sar记录为10分钟一次,改为1分钟一次
日志保存目录为/var/log/sa
运行频率修改,把时间*/10改为*/1,出下面
# vi /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/1 * * * * root /usr/lib64/sa/sa1 1 1
如果没有配置文件则需要安装sysstat-7.0.2-3.el5_5.1.x86_64.rpm包
日志保存时间,改为30天
# vi /etc/sysconfig/sysstat
history=30