centos7.2静默安装oracle11g
前言:国庆节前centos7.2上静默安装11g出现了多次问题,特地把安装过程自己整理一遍方便下次安装查询。
下载oracle
官方网站:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/
请根据自己的操作系统选择
一、centos7系统准备工作
1、操作系统 root登录centos
[root@localhost ~]# uname -m
x86_64
[root@localhost ~]# cat /etc/redhat-release
redhat-7
vi /etc/redhat-release oracle默认不支持CentOS系统安装,修改文件 /etc/RedHat-release
hostname 修改,修改后注意,前后必须一致
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname localhost.localdomain
2、/etc/hosts文件中添加主机名
[root@localhost ~]# ip addr 查看自己的ip地址
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
vim /etc/hosts 修改为自己的ip地址hosts (备注:centos设置静态ip,没有修改hosts文件访问仍然正常)
127.0.0.1 localhost
1.1.1.1 localhost.localdomain
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
3、创建所需的操作系统组和用户
[root@localhost ~]# groupadd oinstall #创建用户组oinstall
[root@localhost ~]# groupadd dba #创建用户组dba
[root@localhost ~]# useradd -g oinstall -G dba -m oracle #创建oracle用户,并加入到oinstall和dba用户组
[root@localhost ~]# passwd oracle #设置用户oracle的登陆密码
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: #确认密码
passwd: all authentication tokens updated successfully.
[root@localhost admin]# id oracle #查看新建的oracle用户
uid=1001(oracle) gid=1002(dba) groups=1002(dba)
4、关闭selinux(备注:此处设置可能是重启生效)
[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
5、关闭防火墙
[root@localhost ~]# systemctl stop firewalld.service #关闭防火墙
[root@localhost ~]# systemctl status firewalld.service #再次查看防火墙状态
[root@localhost ~]# systemctl disable firewalld.service #关闭开机制动启动
安装、测试、远程访问正常后开启
#systemctl start firewalld.service 开启防火墙
#firewall-cmd --zone=public --add-port=1521/tcp --permanent 开启1521端口
# systemctl restart firewalld.service 重启防火墙
6、安装软件依赖环境
yum -y install gcc gcc-c++ make binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static glibc glibc-common glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel numactl-devel sysstat unixODBC unixODBC-devel kernelheaders pdksh pcre-devel readline rlwrap
检查软件依赖环境
[root@localhost ~]# 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
binutils-2.23.52.0.1-55.el7.x86_64
compat-libcap1-1.10-7.el7.x86_64
compat-libstdc++-33-3.2.3-72.el7.x86_64
gcc-4.8.5-4.el7.x86_64
gcc-c++-4.8.5-4.el7.x86_64
glibc-2.17-105.el7.x86_64
glibc-devel-2.17-105.el7.x86_64
ksh-20120801-22.el7_1.2.x86_64
libaio-0.3.109-13.el7.x86_64
libaio-devel-0.3.109-13.el7.x86_64
libgcc-4.8.5-4.el7.x86_64
libstdc++-4.8.5-4.el7.x86_64
libstdc++-devel-4.8.5-4.el7.x86_64
libXi-1.7.4-2.el7.x86_64
libXtst-1.2.2-2.1.el7.x86_64
make-3.82-21.el7.x86_64
sysstat-10.1.5-7.el7.x86_64
unixODBC-2.3.1-11.el7.x86_64
unixODBC-devel-2.3.1-11.el7.x86_64
[root@localhost ~]#
如果是内网 请参考CentOS7.2配置本地yum源 https://www.cnblogs.com/yybrhr/p/9914392.html
7、配置内核参数和资源限制
shmall 是全部允许使用的共享内存大小,shmmax 是单个段允许使用的大小。这两个可以设置为内存的 90%。例如 16G 内存,16*1024*1024*1024*90% = 15461882265,shmall 的大小为 15461882265/4k(getconf PAGESIZE可得到) = 3774873。
[root@localhost ~]# vim /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 8073741824
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 生效
8、修改用户的SHELL限制
[root@localhost ~]# vim /etc/security/limits.conf
#添加以下内容
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
9、修改/etc/pam.d/login 文件 ,添加以下内容
[root@localhost ~]# vim /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
10、修改/etc/profile 文件
vim /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
二、安装oracle
(注意 :ZHS16GBK 、 AL32UTF8 整体编码格式一定要设置一致)
1、解压Oracle文件
mkdir /home/oracle/orapackage (以自己建立的为准)
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
或则 在oracle文件目录 直接解压过去
unzip -q linux.x64_11gR2_database_1of2.zip -d /home/oracle/orapackage
unzip -q linux.x64_11gR2_database_2of2.zip -d /home/oracle/orapackage
2、创建一些安装目录,静默安装文件目录和此一致
mkdir -p /home/oracle/app/oracle/product/11.2.0/dbhome_1
mkdir /home/oracle/app/oracle/{oradata,inventory,fast_recovery_area}
chown -R oracle:oinstall /home/oracle/app/oracle
chmod -R 775 /home/oracle/app/oracle
3、设置 oracle 用户环境变量
su - oracle
[oracle@localhost ~]$ vim .bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_BASE=/home/oracle/app/oracle
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LANG=C
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
添加完成后 source .bash_profile 使之生效
4、编辑静默安装文件
先copy一份出来
mkdir -p /home/oracle/response
cp /home/oracle/orapackage/database/response/* /home/oracle/response
cd /home/oracle/response
vim db_install.rsp
设置内容
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=localhost.localdomain (与操作系统hotname一致)
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/home/oracle/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=ZHS16GBK
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.password.ALL=oracle 为了安全请设置一个复杂的密码
DECLINE_SECURITY_UPDATES=true
5、安装
cd /home/oracle/orapackage/database/
./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
6、打开终端,以 root 身份登录,执行脚本
su - root
sh /home/oracle/app/oracle/inventory/orainstRoot.sh
sh /home/oracle/app/oracle/product/11.2.0/dbhome_1/root.sh
7、查看监听响应文件配置信息 oracle用户
egrep -v "(^#|^$)" /home/oracle/response/netca.rsp
#以静默方式配置监听
su - oracle
source .bash_profile
netca /silent /responsefile /home/oracle/response/netca.rsp
8、建库
vim /home/oracle/response/dbca.rsp
设置以下参数
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle" 为了安全请设置一个复杂的密码
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/home/oracle/app/oracle/oradata
RECOVERYAREADESTINATION=/home/oracle/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "6144"
保存后
dbca -silent -responseFile /home/oracle/response/dbca.rsp
9、启动
注意 /home/orcldb/product/11.2.0/network/admin 文件下的 tnsnames.ora listener.ora sqlnet.ora
我附件https://files.cnblogs.com/files/skyapplezhao/admin.zip里传一份HOST以ip配置的监听 ,也可以配置为本地hostname,
以 sysdba 身份登录
sqlplus / as sysdba
启动 oralce 数据库
SQL> startup
退出
lsnrctl status 查看监听状态
10. 设置Oracle开机启动
修改/home/oracle/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改/home/oracle/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改vi /etc/oratab
orcl:/home/oracle/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=/home/oracle/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 /home/oracle/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
cd /var/tmp
chown -R oracle:oinstall .oracle
防火墙配置放开Oracle的端口
firewall-cmd --zone=public --add-port=1521/tcp --permanent firewall-cmd --reload