centos7无界面静默安装oracle11 100%成功

导言

好久没有更新博客了,主要是不知道写点什么好。那干脆做一些软件安装的教程吧。

本文主要是介绍centos 7 下安装oracle 11的过程,在看了很多网上教程,加上自己摸索总结出一些容易出错的点。在本文中进行展示

oracle 11g下载

网上的教程一般是先下载ios然后解压通过ssh上传什么的,这种办法也不是不可以,只是太慢了,我这里给大家推荐一种快捷的办法,直接在服务器上用wget下载,只要服务器网速好,很快就能把安装包下载好。

首先访问:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

找到对应的包,本次教程是11.2.0.1.0的安装,所以找到Linux x86-64版本的下载地址

https://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip
https://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip

一共两个卷 然后点击之后会同意条款,同意之后会提示登录oracle账号,如果之前你们从oracle下载过java jdk 那就可以使用那个账号登陆,如果没有可以直接注册一个。
注册或者登陆之后再回到那个页面点击下载这个时候浏览器会自动开始下载,但是别急,我们现在使用浏览器的开发者工具,打开网络面板,找一个oracle网页的html请求,把其中请求头中的cookies 复制出来
像这样:
image

然后我们使用wget来构造一个带cookies的请求

1
wget --no-cookies --header "Cookie:s_fid=03CA6261D2D9521A-25568A66A7B3D73A; s_cc=true; ORA_WWW_MRKT=v:1~g:3769290A8D127500E050E60AD27F2320~t:NOT_FOUND~c:LP05; ORA_WWW_PERSONALIZE=v:1~i:NOT_FOUND~r:NOT_FOUND~g:APAC~l:zh-CN~cs:NOT_FOUND~cn:??????; ORASSO_AUTH_HINT=v1.0~20191018130524; ORA_UCM_INFO=3~3769290A8D127500E050E60AD27F2320~Zuoliang~Zhang~onlyxx@outlook.com; OAMAuthnCookie_edelivery.oracle.com:443=f5cc3fbcce63f859cbb1bfa04d3721abf645acb3%7EW%2BGVYBhwJckCVHYJnCYILorhEIWfRUtbRIk%2BubrMdLfaAp9rc29hvQOJbjkPYjvSpnLke7OgU3XNKyY1HfC7I893qrHBTU7qMQuFHlC4GlvwH1p%2FS0xyT%2F8GChoLIhoXn%2FHSGWOjqqCdxdqhVtOtVUU7TGJeLPNKsLEG4ilw6acJKS7gWVcmsGXsClHvA0KlNU%2BpYqTf8fe%2BGatJBuCaKktK6rLf0RDNUvWXafl7mImSYyGspMvNY6q0B%2FGh2oVUdtlwctFSf%2Fz6D6oTVLQukfydt4p04h7s0bFth8PjAeoU7R6Wtlz%2BucL3QBUe6YyzOHPpynEeRVjtONzzZP6gAGtPIhCaVCZpmlcA0pwqL9IMEbkU0TfQFb4qTKbEQg%2F8QZM4RZvnA1UhHn7MINjMVsvHkAm5K1r2wpHCzQWyHGQCW6A0t0PxhUDqyy1ORw7%2BMCQuUQNJoJNXZUUEr1YOS%2FJMGJhcgQDZaui%2B%2BuTLVs%2FyA2py2n4e5k%2BrJBf6cplBOKEXnqt%2F0MV4RbzlpmxLK%2BCVjfim%2FmVMsNTEwSEvBxs%3D; OAMAuthnHintCookie=1; ORA_WWW_MRKT=v:1~g:3769290A8D127500E050E60AD27F2320~t:NOT_FOUND~c:LP05; ORA_WWW_PERSONALIZE==?UTF-8?B?djoxfmk6......这里是复制出来的cookis" https://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip 这里是下载地址根据到时候的实际情况而定

安装环境准备

下载好之后会得到2个zip的文件
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip

解压

1
2
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

复制到安装目录

1
2
3
[root@devops oracle]# ls database/
install readme.html response rpm runInstaller sshsetup stage welcome.html
[root@devops oracle]# mv database/ /tmp/

安装依赖

1
2
3
4
5
6
// centos 7 没有相关安装包可用,可下载 pdksh 的 rpm 包
[root@devops oracle]# wget http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
// 安装 pdksh 出现依赖问题的话,使用 rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm --nodeps --force 安装
[root@devops oracle]# rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
//安装其他的依赖
[root@devops oracle]# yum -y install 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 unixODBC unixODBC-devel

检查是否依赖安装完毕

1
[root@devops oracle]# 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 unixODBC unixODBC-devel | grep "not installed"

都ok之后,创建oracle的用户和组

1
2
3
[root@devops oracle]# groupadd oinstall
[root@devops oracle]# groupadd dba
[root@devops oracle]# useradd -g oinstall -G dba -d /home/oracle oracle

优化系统内核参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@devops oracle]# vim /etc/pam.d/login
session required pam_limits.so

[root@devops oracle]# vim /etc/security/limits.conf
oracle soft nproc 8192
oracle hard nproc 16384
oracle soft nofile 32768
oracle hard nofile 65535

[root@devops oracle]# vim /etc/sysctl.conf
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 6815744
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=1048576
fs.aio-max-nr = 1048576
[root@devops oracle]# sysctl -p

[root@devops oracle]# vim /etc/profile
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65535
else
ulimit -u 16384 -n 65535
fi
fi
[root@devops oracle]# source /etc/profile

创建 oracle 相关目录

1
2
3
4
5
6
7
8
[root@devops oracle]# mkdir /data/oracle

[root@devops oracle]# mkdir /data/oracle/product/11.2.0/dbhome_1 -p
[root@devops oracle]# mkdir /data/oracle/oraInventory -p
[oracle@devops ~]$ mkdir -p /data/oracle/oradata
[oracle@devops ~]$ mkdir -p /data/oracle/fast_recovery_area
[root@devops oracle]# chown -R oracle:oinstall /data/oracle/
[root@devops oracle]# chmod -R 775 /data/oracle/

配置 swap 空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@devops oracle]# dd if=/dev/zero of=/data/swap bs=1M count=8192
[root@devops oracle]# mkswap /data/swap
[root@devops oracle]# swapon /data/swap
//追加到最后
[root@devops oracle]# vim /etc/rc.local
swapon -a
[root@devops oracle]# echo 10 > /proc/sys/vm/swappiness
[root@devops oracle]# vim /etc/sysctl.conf
vm.swappiness = 10
[root@devops oracle]# sysctl -p
[root@devops oracle]# vim /etc/fstab
/data/swap swap swap defaults 0 0
[root@devops oracle]# free -m
total used free shared buff/cache available
Mem: 32013 328 16740 0 14944 31274
Swap: 8191 0 8191

配置 oracle 用户环境变量

1
2
3
4
5
6
7
8
9
[root@devops oracle]# su - oracle
[oracle@devops ~]$ vim .bash_profile
umask 022
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=/data/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=finance
[oracle@devops ~]$ source .bash_profile
[oracle@devops ~]$ exit

安装 oracle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@devops oracle]# cp /tmp/database/response/dbca.rsp /home/oracle/
[root@devops oracle]# cp /tmp/database/response/db_install.rsp /home/oracle/
[root@devops oracle]# cp /tmp/database/response/netca.rsp /home/oracle/
[root@devops oracle]# chown -R oracle:oinstall /home/oracle/*.rsp

// 修改 db_install.rsp 的参数,以实现静默安装 这里的参数如果不明白最好不要修改!!!
[root@devops oracle]# vim /home/oracle/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=devops
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/data/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=finance
oracle.install.db.config.starterdb.SID=finance
oracle.install.db.config.starterdb.characterSet=ZHS16GBK
oracle.install.db.config.starterdb.password.ALL=oracle
DECLINE_SECURITY_UPDATES=true


[root@devops oracle]# su - oracle
[oracle@devops ~]$ cd /tmp/database/
// 开始静默安装 oracle 执行这句话之后过一会会提示安装正在进行可以看某一个日志文件例如 /data/oracle/oraInventory/logs/installActions2019-10-19_03-06-35PM.log
// 通过tail -f 可以看到日志然后等提示shudown install 输入exit退出oracle账号
// 执行 sh /data/oracle/oraInventory/orainstRoot.sh sh /data/oracle/product/11.2.0/dbhome_1/root.sh 完成最后的安装
[oracle@devops database]$ ./runInstaller -silent -ignorePrereq -responseFile /home/oracle/db_install.rsp

[root@devops tmp]# sh /data/oracle/oraInventory/orainstRoot.sh
[root@devops tmp]# sh /data/oracle/product/11.2.0/dbhome_1/root.sh

安装监听

1
2
3
[root@devops tmp]#  su - oracle
[oracle@devops ~]$ netca /silent /responseFile /home/oracle/netca.rsp
//如果这里提示找不到 netca去看看 上面export ORACLE_HOME 这个路径的文件夹是不是没有文件,修改为正确的文件夹即可,如果按照教程来,创建的文件夹则不会

静默模式创建实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
[oracle@devops ~]$ vim dbca.rsp
//请一个一个的找到这些配置并修改为下面提到的值,如果直接复制下面的配置可能会导致无法安装,记得备份dbca.rsp
[root@devops ~]# egrep -v "^$|^#" /home/oracle/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "finance"
SID = "finance"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION = /data/oracle/oradata
RECOVERYAREADESTINATION=/data/oracle/flash_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "13107"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:finance"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "finance"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "finance"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "finance"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "finance"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "finance"
INSTANCENAME = "finance"
SYSDBAUSERNAME = "sys"

//执行静默安装
[oracle@devops ~]$ dbca -silent -responseFile /home/oracle/dbca.rsp
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
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/data/oracle/cfgtoollogs/dbca/finance/finance.log" for further details.
//到这里就算安装完成了

测试安装

1
2
3
4
5
6
7
8
9
10
11
12
[oracle@devops ~]$ sqlplus / as sysdba
sys@FINANCE> select * from v$Version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

5 rows selected.

如果是阿里云服务器要想远程访问数据库记得打开 安全组的1521端口开放

配置远程连接

1
2
3
4
5
6
7
[oracle@oracledb ~]$ sqlplus / as sysdba

//激活scott账户
SQL> alter user scott account unlock;

SQL> alter user scott identified by fpEeB07zuCqz;
//fpEeB07zuCqz是密码这个最好使用自己的密码不要复制我的。

配置

Navicat远程连接Oracle
官方网站

http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

下载 instantclient-basic,解压压缩文件

下载Navicat

http://pan.baidu.com/s/1c2GP9U4

打开Navicat,工具→选项

打开OCI界面,在右侧OCI library一栏中选择instantclient-basic解压目录下的oci.dll,然后点击确定
image
mac 的直接使用下面的连接方式即可
用户名使用刚激活的scott,密码为fpEeB07zuCqz,填完以上信息后点击连接测试
image

更新开机启动

安装之后发现服务器内存太小了,加了内存重启之后发现oracle没有自动启动,这里加一个开机启动的方法

  1. 首先到安装oracle之后的路径就是/data/oracle/product/11.2.0/dbhome_1/bin中修改dbstart的ORACLE_HOME_LISTNER属性
    修改为 $ORACLE_HOME 原值为$1

    1
    2
    3
    4
     cd /data/oracle/product/11.2.0/dbhome_1/bin
    vim dbstart
    # First argument is used to bring up Oracle Net Listener
    ORACLE_HOME_LISTNER=$ORACLE_HOME
  2. 修改另一个dbshut文件 将ORACLE_HOME_LISTNER的值改成$ORACLE_HOME

1
2
3
vim dbshut

ORACLE_HOME_LISTNER=$ORACLE_HOME
  1. 第三步修改/etc/oratab 将最后的N 改成Y

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    vi /etc/oratab

    # The first and second fields are the system identifier and home
    # directory of the database respectively. The third filed indicates
    # to the dbstart utility that the database should , "Y", or should not,
    # "N", be brought up at system boot time.
    #
    # Multiple entries with the same $ORACLE_SID are not allowed.
    #
    #
    finance:/data/oracle/product/11.2.0/dbhome_1:Y
  2. 新建开机启动脚本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    vi /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=/data/oracle/product/11.2.0/dbhome_1
    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
  3. 设置执行权限

1
chmod a+x /etc/init.d/oracle
  1. 设置开机启动,运行oracle
1
2
3
systemctl enable oracle

service oracle start

好了,如果严格按照之前的安装来,在按照这个步骤应该就可以成功启动oracle了
注意启动的$ORACLE_HOME 要设置正确!!!

参考:

  1. CentOS 7 命令行方式安装 Oracle 11.2.0.4.0
  2. CentOS 7静默(无图形化界面)安装Oracle 11g