Oracle11g静默安装

Oracle11g静默安装

oracle11g安装介质下载地址:
http://download.oracle.com/otn/nt/oracle11g/112010/linux.x64_11gR2_database_1of2.zip

http://download.oracle.com/otn/nt/oracle11g/112010/linux.x64_11gR2_database_2of2.zip

1 环境配置

1.1 依赖

1.1.1 依赖查看

# 输入以下命令,查看依赖是否安装
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc-2.17 glibc-common glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel unzip

1.1.2 依赖安装

yum install -y binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc-2.17 glibc-common glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel unzip

1.2 新增用户和组

groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
# 输入密码oracle

1.3 系统参数设置

1.3.1 linux内核

# 备份
cp /etc/sysctl.conf /etc/sysctl.conf.bak

# 修改linux内核
cat >> /etc/sysctl.conf << EOF
# 内核参数
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 8388608
kernel.shmmax = 34359738368
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
EOF

# 使参数生效
sysctl -p

1.3.2 关闭selinux

# 备份
cp /etc/selinux/config /etc/selinux/config.bak
# 查看
grep ^SELINUX= /etc/selinux/config
# 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 临时关闭
setenforce 0
# 查看状态
getenforce

1.3.3 关闭防火墙

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

1.3.4 其他

cp /etc/security/limits.conf /etc/security/limits.conf.bak

cat >> /etc/security/limits.conf << EOF
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF

cp /etc/pam.d/login /etc/pam.d/login.bak
cat >> /etc/pam.d/login << EOF
session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so
EOF

cp /etc/profile /etc/profile.bak
cat >> /etc/profile << EOF
if [ \$USER = "oracle" ]; then
    if [ \$SHELL = "/bin/ksh" ]; then
        ulimit -p 16384
        ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi
EOF

source /etc/profile

1.4 创建数据库相关目录并授权

mkdir -p /u01/app/oracle/product/11.2.0
mkdir /u01/app/oracle/oradata
mkdir /u01/app/oracle/inventory
mkdir /u01/app/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle

1.5 添加/etc/oraInst.loc文件

cat > /etc/oraInst.loc << EOF
inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall
EOF

# 授权
chown oracle:oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc

2 介质安装

2.1 修改oracle环境变量

su - oracle

cp ~/.bash_profile ~/.bash_profile.bak

cat >> ~/.bash_profile << EOF
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=\$PATH:\$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
EOF

source ~/.bash_profile

2.2 安装包配置

# 上传并解压文件 linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
cd /tmp
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip

# 复制配置文件,修改权限
cd /home/oracle/ 
cp -R /tmp/database/response/ .
cd response/
# 修改db_install.rsp内容
sed -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/g' db_install.rsp && \
sed -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/g' db_install.rsp && \
sed -i 's/INVENTORY_LOCATION=/INVENTORY_LOCATION=\/u01\/app\/oracle\/inventory/g' db_install.rsp && \
sed -i 's/SELECTED_LANGUAGES=/SELECTED_LANGUAGES=en,zh_CN/g' db_install.rsp && \
sed -i 's/ORACLE_HOME=/ORACLE_HOME=\/u01\/app\/oracle\/product\/11.2.0/g' db_install.rsp && \
sed -i 's/ORACLE_BASE=/ORACLE_BASE=\/u01\/app\/oracle/g' db_install.rsp && \
sed -i 's/oracle\.install\.db\.InstallEdition=/oracle\.install\.db\.InstallEdition=EE/g' db_install.rsp && \
sed -i 's/oracle\.install\.db\.DBA_GROUP=/oracle\.install\.db\.DBA_GROUP=dba/g' db_install.rsp && \
sed -i 's/oracle\.install\.db\.OPER_GROUP=/oracle\.install\.db\.OPER_GROUP=dba/g' db_install.rsp && \
sed -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/g' db_install.rsp

2.3 执行安装

cd /tmp/database/
./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq


# 安装完后使用root用户执行
su root
sh /u01/app/oracle/inventory/orainstRoot.sh
sh /u01/app/oracle/product/11.2.0/root.sh

# 切换到oracle用户【配置监听】
netca /silent /responsefile /home/oracle/response/netca.rsp

​ 成功运行后,在/u01/app/oracle/product/11.2.0/network/admin/中生成listener.ora和sqlnet.ora

# 配置监听后,可以查看1521端口是否启动
ss -ntlp | grep 1521

3 数据库实例安装

​ 以静默方式建立新库,同时也建立一个对应的实例,注意在设置密码时,不能使用特殊符号

3.1 配置dbca.rsp文件

vim /home/oracle/response/dbca.rsp

# 修改以下配置【查找出每一条后修改】
sed -i 's/GDBNAME = \"orcl11\.us\.oracle\.com\"/GDBNAME = \"orcl\"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/GDBNAME = \"orcl11g\.us\.oracle\.com\"/GDBNAME = \"orcl\"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/SID = \"orcl11g\"/SID = \"orcl\"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#SYSPASSWORD = \"password\"/SYSPASSWORD = "oracle"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#SYSTEMPASSWORD = \"password\"/SYSTEMPASSWORD = "oracle"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#SYSMANPASSWORD = \"password\"/SYSMANPASSWORD = "oracle"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#DBSNMPPASSWORD = \"password\"/DBSNMPPASSWORD = "oracle"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#DATAFILEDESTINATION =/DATAFILEDESTINATION =\/u01\/app\/oracle\/oradata/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#DATAFILEDESTINATION =/RECOVERYAREADESTINATION=\/u01\/app\/oracle\/fast_recovery_area/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#CHARACTERSET = \"US7ASCII\"/CHARACTERSET = \"AL32UTF8\"/g' /home/oracle/response/dbca.rsp && \
sed -i 's/#TOTALMEMORY = "800"/TOTALMEMORY = \"800\"/g' /home/oracle/response/dbca.rsp
# 其中TOTALMEMORY = "1638" 为1638MB,物理内存2G*80%。

3.2 安装数据库实例

# 切换到刚在oralce用户终端
dbca -silent -responseFile /home/oracle/response/dbca.rsp

# 完成后检查进程
ps -ef | grep ora_ | grep -v grep

3.4 登录

# 查看监听状态
lsnrctl status

# 登录查看实例状态
sqlplus / as sysdba
select status from v$instance;

4 开机自启

4.1 配置

# 切换到root用户
vim /u01/app/oracle/product/11.2.0/bin/dbstart
# 将 ORACLE_HOME_LISTNER=$1 修改为 
ORACLE_HOME_LISTNER=$ORACLE_HOME

vim /u01/app/oracle/product/11.2.0/bin/dbshut
# 将 ORACLE_HOME_LISTNER=$1 修改为 
ORACLE_HOME_LISTNER=$ORACLE_HOME 

vim /etc/oratab
# 将 orcl:/u01/app/oracle/product/11.2.0:N 中最后的 N 改为 Y

# 切换到oracle用户
# 使用dbshut 和 dbstart 测试
dbshut
dbstart

4.2 自启脚本

# 切换root用户
chmod 755 /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
# 在rc.local中添加
su oracle -lc "/u01/app/oracle/product/11.2.0/bin/lsnrctl start"
su oracle -lc /u01/app/oracle/product/11.2.0/bin/dbstart

# 重启机器后执行
netstat -tpln

5 账户解锁

sqlplus / as sysdba
alter user SYSTEM account unlock;

# SYSTEM用户为之前设置的oracle

posted @ 2023-05-25 17:16  书中黄金屋  阅读(195)  评论(0编辑  收藏  举报