17092301_CentOS7安装Oracle11gR2图文详解

        最近有一个项目需要在Linux环境下通过Tomcat+ Oracle环境进行发布,之前的项目多以Windows server上配置发布为主,借此机会正好学习一下Linux下的项目发布。本文先介绍Oracle11gR2在CentOS上的安装与配置,之后将陆续推出Tomcat安装与配置及项目部署发布。在自己学习和实践的过程中,参照了网上朋友的一些资料,由衷感谢每一个乐于共享知识的人,谢谢!

1. 环境准备

1.1 系统

操作系统:CentOS7(64位)

1.2 软件工具

linux.x64_11gR2_database_1of2.zip

linux.x64_11gR2_database_2of2.zip

推荐下载地址:Oracle官方网站

2. 方法/步骤

2.1、安装Oracle前准备

2.1.1 创建运行oracle数据库的系统用户和用户组

[[email protected] ~]$ su root                #切换到root

Password:

[[email protected] zm]# groupadd oinstall   #创建用户组oinstall

[[email protected] zm]# groupadd dba      #创建用户组dba

[[email protected] zm]# useradd -g oinstall -g dba -m oracle #创建oracle用户,并加入到oinstall和dba用户组

[[email protected] zm]# passwd oracle #设置用户oracle的登陆密码,不设置密码,在CentOS的图形登陆界面没法登陆

Changing password for user oracle.

New password:                 # 设定密码,密码必须8位,且数字字母组合

Retype new password:          # 确认密码

passwd: all authentication tokensupdated successfully.

[[email protected] zm]# id oracle      # 查看新建的oracle用户

uid=1001(oracle) gid=1002(dba)groups=1002(dba)

[[email protected] zm]#

为啥要创建oinstall用户组及dba组? 参考:http://www.oracle.com/technetwork/cn/articles/hunter-rac11gr2-iscsi-2-092412-zhs.html#13

理论上按照官网的描述需要3种用户组,实际只建两个oinstall和dba,后面再安装oracle数据库的时候把OSOPER组也设置是dba组。

a.oracle 清单组(一般为oinstall):

OINSTALL 组的成员被视为 Oracle 软件的“所有者”,拥有对 Oracle *清单 (oraInventory) 的写入权限。在一个 Linux 系统上首次安装 Oracle 软件时,OUI 会创建 /etc/oraInst.loc 文件。该文件指定 Oracle 清单组的名称(默认为 oinstall)以及 Oracle *清单目录的路径。

b.数据库管理员(OSDBA,一般为 dba):

OSDBA 组的成员可通过操作系统身份验证使用 SQL 以 SYSDBA 身份连接到一个 Oracle 实例。该组的成员可执行关键的数据库管理任务,如创建数据库、启动和关闭实例。该组的默认名称为dba。SYSDBA 系统权限甚至在数据库未打开时也允许访问数据库实例。对此权限的控制完全超出了数据库本身的范围。不要混淆 SYSDBA系统权限与数据库角色 DBA。DBA 角色不包括 SYSDBA 或SYSOPER 系统权限。

c.数据库操作员组(OSOPER,一般为 oper):

OSOPER 组的成员可通过操作系统身份验证使用 SQL 以 SYSOPER 身份连接到一个 Oracle 实例。这个可选组的成员拥有一组有限的数据库管理权限,如管理和运行备份。该组的默认名称为oper。SYSOPER 系统权限甚至在数据库未打开时也允许访问数据库实例。对此权限的控制完全超出了数据库本身的范围。要使用该组,选择 Advanced 安装类型来安装 Oracle 数据库软件。

2.1.2 创建oracle数据库安装目录

[[email protected] ~]$ su root

Password:

[[email protected] zm]# mkdir -p /data/oracle  #创建oracle数据库安装目录

[[email protected] zm]# mkdir -p /data/oraInventory #创建oracle数据库配置文件目录

[[email protected] zm]# mkdir -p /data/database  #创建oracle数据库软件包解压目录

[[email protected] zm]# cd /data

[[email protected] data]# ls  #创建完毕检查一下

database oracle  oraInventory

[[email protected] data]# chown -R oracle:oinstall /data/oracle  #设置目录所有者为oinstall用户组的oracle用户

[[email protected] data]# chown -R oracle:oinstall /data/oraInventory

[[email protected] data]# chown -R oracle:oinstall /data/database

[[email protected] data]# 

2.1.3 修改OS系统标识

oracle默认不支持CentOS系统安装,Oracle Database 11g Release 2 的 OS要求参考:

 https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#LADBI1106

 我安装是64位数据库,On Linux x86-64:Red Hat Enterprise Linux 7  (RHEL 7)

 另外,CentOS7.0.1511 基于 RHEL7.2  参考:http://www.linuxidc.com/Linux/2015-12/126283.htm

 修改文件 /etc/RedHat-release

[[email protected] data]$ su root

Password:

[[email protected] data]# cat /proc/version

Linux version 3.10.0-327.el7.x86_64([email protected]) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9)(GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015

[[email protected] data]# cat /etc/redhat-release  

CentOS Linux release 7.2.1511 (Core)

[[email protected] data]# vi /etc/redhat-release

[[email protected] data]# cat /etc/redhat-release

redhat-7

[[email protected] data]#

2.1.4 安装oracle数据库所需要的软件包

重复一遍,我安装时OracleDatabase 11g Release 2 64位数据库。

Oracle DatabasePackage Requirements for Linux x86-64 如下:(参考:https://docs.oracle.com/cd/E11882_01/install.112/e47689/pre_install.htm#BABCFJFG

操作系统:OracleLinux 7 and Red Hat Enterprise Linux 7

The followingpackages (or later versions) must be installed:

binutils-2.23.52.0.1-12.el7.x86_64

compat-libcap1-1.10-3.el7.x86_64

compat-libstdc++-33-3.2.3-71.el7.i686  # 32位软件不需要

compat-libstdc++-33-3.2.3-71.el7.x86_64

gcc-4.8.2-3.el7.x86_64

gcc-c++-4.8.2-3.el7.x86_64

glibc-2.17-36.el7.i686

glibc-2.17-36.el7.x86_64

glibc-devel-2.17-36.el7.i686  # 32位软件不需要

glibc-devel-2.17-36.el7.x86_64

ksh

libaio-0.3.109-9.el7.i686  # 32位软件不需要

libaio-0.3.109-9.el7.x86_64

libaio-devel-0.3.109-9.el7.i686  # 32位软件不需要

libaio-devel-0.3.109-9.el7.x86_64

libgcc-4.8.2-3.el7.i686  # 32位软件不需要

libgcc-4.8.2-3.el7.x86_64

libstdc++-4.8.2-3.el7.i686# 32位软件不需要

libstdc++-4.8.2-3.el7.x86_64

libstdc++-devel-4.8.2-3.el7.i686 # 32位软件不需要

libstdc++-devel-4.8.2-3.el7.x86_64

libXi-1.7.2-1.el7.i686    # 32位软件不需要

libXi-1.7.2-1.el7.x86_64

libXtst-1.2.2-1.el7.i686   # 32位软件不需要

libXtst-1.2.2-1.el7.x86_64

make-3.82-19.el7.x86_64

sysstat-10.1.5-1.el7.x86_64

一个一个的安装,文档要求高版本也可以:

[[email protected]]$ su root

Password:

[[email protected]]# yum install binutils
省略...

 

2.1.5 关闭防火墙firewall

CentOS 7.2默认使用的是firewall作为防火墙,

 

[[email protected] /]$ su root

Password:

[[email protected] /]# systemctl status firewalld.service#查看防火墙状态,运行中

● firewalld.service - firewalld -dynamic firewall daemon

  Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled;vendor preset: enabled)

  Active: active(running) since Thu 2016-04-07 18:54:29 PDT; 2h 20min ago

 Main PID: 802 (firewalld)

  CGroup: /system.slice/firewalld.service

           └─802 /usr/bin/python -Es/usr/sbin/firewalld --nofork --nopid

 

Apr 07 18:54:25 localhost.localdomainsystemd[1]: Starting firewalld - dynamic firewall daemon...

Apr 07 18:54:29 localhost.localdomainsystemd[1]: Started firewalld - dynamic firewall daemon.

[[email protected] /]# systemctl stop firewalld.service   #关闭防火墙

[[email protected] /]# systemctl status firewalld.service  #再次查看防火墙状态,发现已关闭

●firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded(/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

   Active: inactive (dead) since Thu 2016-04-07 21:15:34 PDT; 9sago

 Main PID: 802 (code=exited, status=0/SUCCESS)

 

Apr 07 18:54:25localhost.localdomain systemd[1]: Starting firewalld - dynamic firewalldaemon...

Apr 07 18:54:29localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

Apr 07 21:15:33localhost systemd[1]: Stopping firewalld - dynamic firewall daemon...

Apr 07 21:15:34localhost systemd[1]: Stopped firewalld - dynamic firewall daemon.

[[email protected]/]# systemctl disable firewalld.service  #禁止使用防火墙(重启也是禁止的)

Removed symlink/etc/systemd/system/dbus-org.Fedoraproject.FirewallD1.service.

Removed symlink/etc/systemd/system/basic.target.wants/firewalld.service.

[[email protected]/]#

 

此处先禁用防火墙,在进行客户端配置时,通过iptables进行配置。

2.1.6 关闭selinux(需重启生效)

[[email protected]/]# vi /etc/selinux/config

[[email protected]/]# cat /etc/selinux/config

 

# This filecontrols the state of SELinux on the system.

# SELINUX= cantake one of these three values:

#     enforcing - SELinux security policy isenforced.

#     permissive - SELinux prints warningsinstead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled   #此处enforcing修改为disabled

# SELINUXTYPE=can take one of three two values:

#     targeted - Targeted processes areprotected,

#     minimum - Modification of targeted policy.Only selected processes are protected.

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

[[email protected]/]#

为啥要关闭selinux?本人查找了一下Oracle的官方安装Guide,并没有看到关于selinux的要求,不过参照网上的资料,基本都是关闭,我也就关闭了,等有空了再研究。

[[email protected]/]# reboot   # 重启生效

2.1.7 修改内核参数(红色部分为添加代码)

[[email protected]/]$ su root

Password:

[[email protected]/]# vi /etc/sysctl.conf

 [[email protected] /]# cat /etc/sysctl.conf

# System defaultsettings live in /usr/lib/sysctl.d/00-system.conf.

# To overridethose settings, enter new settings here, or in an/etc/sysctl.d/<name>.conf file

#

# For moreinformation, 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 #共享内存的总量,8G内存设置:2097152*4k/1024/1024

kernel.shmmax = 1073741824   #最大共享内存段的大小 根据Oracle官网安装Guide要求,推荐为物理内存的一半,我的内存为2G,所以这里设置为1G:1073741824/1024/1024=1024M=1G

kernel.shmmni = 4096 #整个系统共享内存端的最大数

kernel.sem = 250 32000 100 128

net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4端口范围

net.core.rmem_default = 262144

net.core.rmem_max= 4194304

net.core.wmem_default= 262144

net.core.wmem_max= 1048576

[[email protected]/]#

使配置参数生效

[[email protected]/]# sysctl -p

fs.aio-max-nr =1048576

fs.file-max =6815744

kernel.shmall =2097152

kernel.shmmax =1073741824

kernel.shmmni =4096

kernel.sem = 25032000 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

[[email protected]/]# 

2.1.8 对oracle用户设置限制,提高软件运行性能(红色为添加部分)

可参考Oracle官网安装Guide:http://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#CEGIHDBF

[[email protected] /]$ su root

Password:

[[email protected] /]# vi /etc/security/limits.conf

[[email protected] /]# cat /etc/security/limits.conf

# /etc/security/limits.conf

#

#This file sets the resource limits forthe users logged in via PAM.

#It does not affect resource limits ofthe system services.

#

#Also note that configuration files in/etc/security/limits.d directory,

#which are read in alphabetical order,override the settings in this

#file in case the domain is the same ormore specific.

#That means for example that setting alimit for wildcard domain here

#can be overriden with a wildcardsetting in a config file in the

#subdirectory, but a user specificsetting here can be overriden only

#with a user specific setting in thesubdirectory.

#

#Each line describes a limit for a userin the form:

#

#<domain>        <type>  <item> <value>

#

#Where:

#<domain> can be:

#       - a user name

#       - a group name, with @group syntax

#       - the wildcard *, for default entry

#       - the wildcard %, can be also used with %group syntax,

#                 for maxlogin limit

#<type> can have the two values:

#       - "soft" for enforcing the soft limits

#       - "hard" for enforcing hard limits

#

#<item> can be one of thefollowing:

#       - core - limits the core file size (KB)

#       - data - max data size (KB)

#       - fsize - maximum filesize (KB)

#       - memlock - max locked-in-memory address space (KB)

#       - nofile - max number of open file descriptors

#       - rss - max resident set size (KB)

#       - stack - max stack size (KB)

#       - cpu - max CPU time (MIN)

#       - nproc - max number of processes

#       - as - address space limit (KB)

……

#<domain>      <type>  <item>         <value>

#*               soft    core            0

#*               hard    rss             10000

#@student        hard   nproc           20

#@faculty        soft   nproc           20

#@faculty        hard   nproc           50

#ftp             hard    nproc           0

#@student        -      maxlogins       4

oracle soft nproc 2047

oracle hard nproc 16384

oracle soft nofile 1024

oracle hard nofile 65536

 

# End of file

[[email protected] /]#  

2.1.9 配置用户的环境变量(红色部分为添加代码)

[[email protected] /]# vim /home/oracle/.bash_profile

[[email protected] /]# cat /home/oracle/.bash_profile

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

   . ~/.bashrc

fi

# User specific environment and startupprograms

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export ORACLE_BASE=/data/oracle #oracle数据库安装目录

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 #oracle数据库路径

export ORACLE_SID=orcl #oracle启动数据库实例名

export ORACLE_TERM=xterm  #xterm窗口模式安装

export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH #添加系统环境变量

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #添加系统环境变量

export LANG=C #防止安装过程出现乱码

export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK  #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致,如:ZHS16GBK,否则出现数据导入导出中文乱码问题

[[email protected] /]#  

使上述配置立即生效:

[[email protected] /]# source /home/oracle/.bash_profile

[[email protected] /]#

2.1.10 完成上述配置后,上传安装包,将oracle安装包上传到/usr/local/src

[[email protected] src]# cd /usr/local/src/

[[email protected] src]# ls linux*

linux.x64_11gR2_database_1of2.zip 

linux.x64_11gR2_database_2of2.zip

[[email protected] src]#

2.1.11.解压安装包

[[email protected] /]# su oracle    #切换至oracle用户

[[email protected] /]$ cd /usr/local/src  #进入/usr/local/src目录

[[email protected] src]$ ls

linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip

[[email protected] src]$ unzip linux.x64_11gR2_database_1of2.zip -d /data/database/   #解压

(省略...)

[[email protected] src]$ unzip linux.x64_11gR2_database_2of2.zip -d /data/database/   #解压

(省略...)

[[email protected] src]$ su root

Password:

[[email protected] src]# chown -R oracle:oinstall /data/database/database/

[[email protected] src]#

2.2. oracle安装 

2.2.1 图形界面登陆oracle用户:

17092301_CentOS7安装Oracle11gR2图文详解

2.2.2 启动oralce安装,到/data/database/database/目录下,执行runInstaller

17092301_CentOS7安装Oracle11gR2图文详解

2.2.3 去掉勾,个人使用环境不需要自动接收Oracle的安全更新。

17092301_CentOS7安装Oracle11gR2图文详解

17092301_CentOS7安装Oracle11gR2图文详解

选yes

2.2.4 下一步,只安装数据库软件,个人用不要那些玩意~~

17092301_CentOS7安装Oracle11gR2图文详解

2.2.5 选择单例安装,前面的所有配置均为单例安装。

17092301_CentOS7安装Oracle11gR2图文详解

2.2.6 添加语言

17092301_CentOS7安装Oracle11gR2图文详解

2.2.7 默认安装版本企业版-Enterprise Edition 

17092301_CentOS7安装Oracle11gR2图文详解

2.2.8 确定数据软件的安装路径,自动读取前面Oracle环境变量中配置的值

17092301_CentOS7安装Oracle11gR2图文详解

2.2.9 创建安装清单目录

17092301_CentOS7安装Oracle11gR2图文详解

2.2.10 理论上要创建Database OperationOSOPERGroup:oper ,个人用,懒得建,就使用dba用户组

17092301_CentOS7安装Oracle11gR2图文详解

2.2.11 安装检查,按照提示信息一个一个解决。

17092301_CentOS7安装Oracle11gR2图文详解

swap空间不足解决 :(要求2.67G实际2G

本人安装过程中未出现此问题,此处参考文章中遇到过该问题,并提供了解决方案,避免其他同学遇到同样的问题,此处也就一并贴出。

[[email protected] oracle]# free -m    #查看当前虚拟内存

              total        used        free      shared buff/cache   available

Mem:           1824        1369          93          10         361         250

Swap:          2048          20        2028

[[email protected] oracle]# dd if=/dev/zero of=/home/swap bs=1024 count=1024000  #将当前swap空间由2048M增加到3048M新增一个2014swap文件

1024000+0 records in

1024000+0 records out

1048576000 bytes (1.0 GB) copied,29.4051 s, 35.7 MB/s

[[email protected] oracle]# mkswap /home/swap

Setting up swapspace version 1, size =1023996 KiB

no label,UUID=5e3d39d7-285e-4c74-b321-1e2b3ffabf83

[[email protected] oracle]# free -m

              total        used        free      shared buff/cache   available

Mem:           1824        1275          95          10         454         342

Swap:          2048         141        1907

[[email protected] oracle]# swapon /home/swap  #增加并启用虚拟内容

swapon: /home/swap: insecure permissions0644, 0600 suggested.

[[email protected] oracle]# free -m  #再次查看

              total        used        free      shared buff/cache   available

Mem:           1824        1275          94          10        454         342

Swap:          3048         141        2907 

2.2.12 一个一个检查package,在准备阶段中漏掉的,此处再安装,有些系统报错是因为现有的包的版本比检测要高,最后忽略即可。(点击Check_Again多检查几次)

17092301_CentOS7安装Oracle11gR2图文详解

2.2.13 准备完毕,“Finish”开始安装。

17092301_CentOS7安装Oracle11gR2图文详解

2.2.14 安装过程中提示用root 用户执行脚本程序。

17092301_CentOS7安装Oracle11gR2图文详解
17092301_CentOS7安装Oracle11gR2图文详解
17092301_CentOS7安装Oracle11gR2图文详解

直接按回车即可。

17092301_CentOS7安装Oracle11gR2图文详解

2.2.15 安装完成

17092301_CentOS7安装Oracle11gR2图文详解

最后,说明下本文章的内容是结合网上的一些资料和自己的实践整理完成的,仅供学习之用。感谢每一个乐于共享知识的人。如有错误或建议,请多多指正。谢谢!