ORACLE_OCP之ORACLE12c安装先决条件准备,并安装oracle完整过程

ORACLE_OCP之ORACLE12c安装先决条件准备,并安装oracle完整过程

  • 环境准备:CentOS7、oracle12c
  • 目录
    • 关闭防火墙并disable selinux
    • 必要软件包安装
    • 修改LINUX的内核文件(/etc/sysctl.conf)
    • 添加下列参数到/etc/security/limits.conf
    • 添加下列条目到/etc/pam.d/login
    • 环境变量(/etc/profile)
    • 创建文件目录和相应的用户
    • 修改oracle用户的环境变量文件
    • 下载oracle12c安装包,解压安装
    • 创建侦听:netca(在oracle用户下执行)
    • oracle建库:dbca命令
    • 安装rlwrap,实现oracle命令历史翻滚
  1. 关闭防火墙并disable selinux
1.检查主机名和网络并且配置/etc/hosts文件
关闭防火墙
检查防火墙状态
systemctl status firewalld.service
暂时关闭防火墙,下次启动时防火墙仍随系统启动而启动
systemctl stop firewalld.service
彻底永久关闭防火墙
systemctl disable firewalld.service

关闭SELINUX防火墙!
vi /etc/selinux/config
将内容
SELINUX=enforcing
更改为
SELINUX=disabled
  1. 必要软件包安装
yum install -y bc
yum install -y compat-libcap1*
yum install -y compat-libcap*
yum install -y binutils 
yum install -y compat-libstdc++-33 
yum install -y elfutils-libelf 
yum install -y elfutils-libelf-devel 
yum install -y gcc 
yum install -y gcc-c++ 
yum install -y glibc-2.5 
yum install -y glibc-common 
yum install -y glibc-devel 
yum install -y glibc-headers 
yum install -y ksh libaio 
yum install -y libaio-devel 
yum install -y libgcc 
yum install -y libstdc++ 
yum install -y libstdc++-devel 
yum install -y make 
yum install -y sysstat 
yum install -y unixODBC 
yum install -y unixODBC-devel
yum install -y binutils*
yum install -y compat-libstdc*
yum install -y elfutils-libelf*
yum install -y gcc*
yum install -y glibc*
yum install -y ksh*
yum install -y libaio*
yum install -y libgcc*
yum install -y libstdc*
yum install -y make*
yum install -y sysstat*
yum install -y libXp*
yum install -y glibc-kernheaders
yum install -y net-tools-*
  1. 修改LINUX的内核文件(/etc/sysctl.conf)(这个文件除了注释是默认的之外其他的都是我们添加上去的),并执行[root@localhost ~]# sysctl -p使得内核文件生效
[root@localhost ~]# vim /etc/sysctl.conf
[root@localhost ~]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
#
kernel.shmmax = 277495689510912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.file-max = 6815744
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
#net.core.somaxconn = 262144
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_probes = 6
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_timestamps = 0
fs.aio-max-nr = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2

//使得修改后的内存文件生效
[root@localhost ~]# sysctl -p
  1. 添加下列参数到/etc/security/limits.conf,这个文件前面部分其实都是注释(这个文件除了注释是默认的之外其他的都是我们添加上去的),可以直接看最后的有效部分,我们就是添加了有效的部分
[root@localhost ~]# vim /etc/security/limits.conf
[root@localhost ~]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the 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 or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in 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 the following:
#        - 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)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<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

# End of file
oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    16384
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768
oracle   hard   memlock    134217728
oracle   soft   memlock    134217728

  1. 添加下列条目到/etc/pam.d/login 这两个主要是限制使用进程数。
//这里我们只是增加了最后两行,其他都是默认的。
[root@localhost ~]# vim /etc/pam.d/login
[root@localhost ~]# cat /etc/pam.d/login
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth       substack     system-auth
auth       include      postlogin
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    include      postlogin
-session   optional     pam_ck_connector.so
session    required     /lib/security/pam_limits.so
session    required     pam_limits.so
  1. 环境变量(/etc/profile)中添加下列语句,我们的添加放在末尾,只是我们这里将整个环境变量文件都考下来了。最后我们执行[root@localhost ~]# source /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

[root@localhost ~]# vim /etc/profile
[root@localhost ~]# cat /etc/profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`/usr/bin/id -u`
        UID=`/usr/bin/id -ru`
    fi
    USER="`/usr/bin/id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

unset i
unset -f pathmunge

if [ $USER = "oracle" ]; then
   if [ $SHELL = "/bin/ksh" ]; then
      ulimit -p 16384
      ulimit -n 65536
      else
      ulimit -u 16384 -n 65536
   fi
fi

//最后我们使环境变量文件更改生效
[root@localhost ~]# source /etc/profile
  1. 创建文件目录和相应的用户
[root@localhost ~]# source /etc/profile
[root@localhost ~]# groupadd oinstall
[root@localhost ~]# groupadd dba
[root@localhost ~]# groupadd oper
[root@localhost ~]# useradd -g oinstall -G dba,oper oracle
[root@localhost ~]# mkdir -p /u01/app/oracle
[root@localhost ~]# mkdir -p /u01/oraInventory
[root@localhost ~]# chown -R oracle.oinstall /u01
[root@localhost ~]# chown -R oracle:oinstall /u01/app/oracle
[root@localhost ~]# chmod -R 775 /u01/app/oracle

//说明
groupadd oinstall       --创建 oinstall组 安装数据库软件用
groupadd dba            --创建 dba组      管理数据库软件用
groupadd oper           --创建 oper组     操作数据库软件用--但是基本用不到。因为官方文档要求,所以我们最好还是给他建立上
useradd -g oinstall -G dba,oper oracle -g代表的是主组 -G代表的属组 oracle代表的是建立的用户名
这个命令的意思是 我建立一个oracle用户 让他的主组数据oinstall组 让他数组属于dba oper组

mkdir -p /u01/app/oracle           --级联创建/u01/app/oracle目录               
mkdir -p /u01/oraInventory         --级联创建oraInventory目录 这个目录下放置的是安装oracle所需要的的环境
chown -R oracle.oinstall /u01      --该命令为把/u01这个目录的所属用户和所属组变为oracle用户和oracle用户所在的oinstall组
chown -R oracle:oinstall /u01/app/oracle  --该命令为把/u01/app/oracle这个目录所属用户和所属组改成oracle用户和oinstall组
chmod -R 775 /u01/app/oracle   --该命令为把/u01/app/oracle这个目录的权限改为所属用户可对可写可执行 所属用户所在组下的所有同组成员皆为可读可写可执行 其他用户对这个目录只有可读和可执行

//给oracle用户添加一个密码,密码自行指定

[root@localhost ~]# passwd 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.
  1. 修改oracle用户的环境变量文件(注意:此时我们需要切换到oracle用户下)
//添加内容
export EDITOR=vi
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export INVENTORY_LOCATION=/u01/oraInventory
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
umask 022
[root@localhost ~]# su - oracle
[oracle@oracle12 ~]$ vim .bash_profile
[oracle@oracle12 ~]$ cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export EDITOR=vi
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export INVENTORY_LOCATION=/u01/oraInventory
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
umask 022

//生成参数
[oracle@oracle12 ~]$ source .bash_profile
//参数说明
export EDITOR=vi  默认的编辑器是vi
export TMP=/tmp   ORACLE默认的临时目录是/tmp
export TMPDIR=$TMP 临时目录生成
export ORACLE_SID=orcl  ORACLE实例名称是orcl
export ORACLE_BASE=/u01/app/oracle   ORACLE的基本目录 
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1  ORACLE数据库的HOME目录
export INVENTORY_LOCATION=/u01/oraInventory       ORACLE安装时的inventory
export TNS_ADMIN=$ORACLE_HOME/network/admin     ORACLE的网络文件主目录
export LD_LIBRARY_PATH=$ORACLE_HOME/lib         ORACLE的库文件目录
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"  ORACLE的字符集 不过我们弃用 因为我们使用UTF8
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" ORACLE的日期格式 我们使用会话的方式修改 没有上面的NLS_LANG,那么这个参数不会生成
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin 生成相关参数
umask 022
  1. 下载oracle12c安装包,解压安装
//安装过程中需要执行两个提示的脚本,(会有提示,出现提示的时候执行脚本即可)
[root@oracle12 ~]# /u01/oraInventory/orainstRoot.sh
Changing permissions of /u01/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/oraInventory to oinstall.
The execution of the script is complete.
[root@oracle12 ~]# /u01/app/oracle/product/12.2.0/db_1/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/12.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Do you want to setup Oracle Trace File Analyzer (TFA) now ? yes|[no] :

Oracle Trace File Analyzer (TFA - User Mode) is available at :
    /u01/app/oracle/product/12.2.0/db_1/suptools/tfa/release/tfa_home/bin/tfactl

OR

Oracle Trace File Analyzer (TFA - Daemon Mode) can be installed by running this script :
    /u01/app/oracle/product/12.2.0/db_1/suptools/tfa/release/tfa_home/install/roottfa.sh

[root@oracle12 ~]#

  1. 创建侦听:netca(在oracle用户下执行),一直next到finish即可
//创建侦听,并查看侦听状态
[oracle@oracle12 database]$ netca

Oracle Net Services Configuration:
Configuring Listener:LISTENER
Listener configuration complete.
Oracle Net Listener Startup:
    Running Listener Control:
      /u01/app/oracle/product/12.2.0/db_1/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Oracle Net Services configuration successful. The exit code is 0
[oracle@oracle12 database]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 19-DEC-2020 05:35:15

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle12)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                19-DEC-2020 05:34:23
Uptime                    0 days 0 hr. 0 min. 52 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle12/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle12)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
  1. oracle建库:dbca命令
//查看是否正常启动

[oracle@oracle12 database]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sat Dec 19 06:16:54 2020

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select * from dual;

D
-
X

SQL> select sysdate from dual;

SYSDATE
-------------------
2020-12-19 06:17:25

SQL>

  1. 安装rlwrap,实现oracle命令历史翻滚
//安装
[root@oracle12 u01]# rpm -ivh rlwrap-0.37-1.el6.x86_64.rpm

//修改配置文件(这里我们是添加了最后两行)

[oracle@oracle12 ~]$ vim .bash_profile
[oracle@oracle12 ~]$ cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

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

export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export INVENTORY_LOCATION=/u01/oraInventory
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:$PATH:$HOME/bin
umask 022

alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'

//最后生成参数,现在在进入oracle就实现了历史命令上下翻滚的功能了
[oracle@oracle12 ~]$ . ~/.bash_profile
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值