CentOS7.6 安装 Oracle19c

下载oracle-database安装包

官方地址:https://www.oracle.com/database/technologies/oracle19c-linux-downloads.html

CentOS7.6 安装 Oracle19c

先下载需要的版本,我用的是rpm包 

然后使用sftp将下载好的rpm包上传到linux上

下载preinstall包解决依赖问题

官方地址:http://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/

wget http://yum.Oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm

使用yum本地安装

安装preinstall

yum localinstall -y oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm 

安装oracle-databse

yum localinstall -y oracle-database-ee-19c-1.0-1.x86_64.rpm

配置环境变量

vim /etc/init.d/oracledb_ORCLCDB-19c

文件内容如下

#!/bin/bash
#
# chkconfig: 2345 80 05
# Description: This script is responsible for taking care of configuring the Oracle Database and its associated services.
#
# processname: oracledb_ORCLCDB-19c
# Red Hat or SuSE config: /etc/sysconfig/oracledb_ORCLCDB-19c
#

# Set path if path not set
case $PATH in
    "") PATH=/bin:/usr/bin:/sbin:/etc
         export PATH ;;
esac

# Check if the root user is running this script
if [ $(id -u) != "0" ]
then
    echo "You must be root user to run the configurations script. Login as root user and try again."
    exit 1
fi

# Setting the required environment variables
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 

export ORACLE_VERSION=19c 
export ORACLE_SID=ORCLCDB
export TEMPLATE_NAME=General_Purpose.dbc
export CHARSET=AL32UTF8
export PDB_NAME=ORCLPDB1
export LISTENER_NAME=LISTENER
export NUMBER_OF_PDBS=1
export CREATE_AS_CDB=true

# General exports and vars
export PATH=$ORACLE_HOME/bin:$PATH
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
DBCA=$ORACLE_HOME/bin/dbca
NETCA=$ORACLE_HOME/bin/netca
ORACLE_OWNER=oracle
RETVAL=0
CONFIG_NAME="oracledb_$ORACLE_SID-$ORACLE_VERSION.conf"
CONFIGURATION="/etc/sysconfig/$CONFIG_NAME"

# Commands
if [ -z "$SU" ];then SU=/bin/su; fi
if [ -z "$GREP" ]; then GREP=/usr/bin/grep; fi
if [ ! -f "$GREP" ]; then GREP=/bin/grep; fi

# To start the DB
start()
{
    check_for_configuration
    RETVAL=$?
    if [ $RETVAL -eq 1 ]
    then
        echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
        exit
    fi
    # Check if the DB is already started
    pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
    if [ "$pmon" = "" ];
    then

        # Unset the proxy env vars before calling sqlplus
        unset_proxy_vars

        echo "Starting Oracle Net Listener."
        $SU -s /bin/bash $ORACLE_OWNER -c "$LSNR  start $LISTENER_NAME" > /dev/null 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ]
        then
            echo "Oracle Net Listener started."
        fi

        echo "Starting Oracle Database instance $ORACLE_SID."
        $SU -s /bin/bash  $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
                                                                connect / as sysdba
                                                                startup
                                                                alter pluggable database all open
                                                                exit;
                                                                EOF" > /dev/null 2>&1
        RETVAL1=$?
        if [ $RETVAL1 -eq 0 ]
        then
            echo "Oracle Database instance $ORACLE_SID started."
        fi
    else
        echo "The Oracle Database instance $ORACLE_SID is already started."
        exit 0
    fi

    echo
    if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ]
    then
        return 0
     else
        echo "Failed to start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
        exit 1
    fi
}

# To stop the DB
stop()
{
    check_for_configuration
    RETVAL=$?
    if [ $RETVAL -eq 1 ]
    then
        echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-$ORACLE_VERSION configure' as the root user to configure the database."
        exit 1
    fi
    # Check if the DB is already stopped
    pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
    if [ "$pmon" = "" ]
    then
        echo "Oracle Database instance $ORACLE_SID is already stopped."
        exit 1
    else

        # Unset the proxy env vars before calling sqlplus
        unset_proxy_vars

        echo "Shutting down Oracle Database instance $ORACLE_SID."
        $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog << EOF
                                                                connect / as sysdba
                                                                shutdown immediate
                                                                exit;
                                                                EOF" > /dev/null 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ]
        then
            echo "Oracle Database instance $ORACLE_SID shut down."
        fi

        echo "Stopping Oracle Net Listener."
        $SU -s /bin/bash  $ORACLE_OWNER -c "$LSNR stop $LISTENER_NAME" > /dev/null 2>&1
        RETVAL1=$?
        if [ $RETVAL1 -eq 0 ]
        then
            echo "Oracle Net Listener stopped."
        fi
    fi

    echo
    if [ $RETVAL -eq 0 ] && [ $RETVAL1 -eq 0 ]
    then
        return 0
    else
        echo "Failed to stop Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr and Oracle Database using $ORACLE_HOME/bin/sqlplus."
        exit 1
    fi
}

# To call DBCA to configure the DB
configure_perform()
{
    # Unset the proxy env vars before calling dbca
    unset_proxy_vars

    echo "Configuring Oracle Database $ORACLE_SID."

    $SU -s /bin/bash  $ORACLE_OWNER -c "$DBCA -silent -createDatabase -gdbName $ORACLE_SID -templateName $TEMPLATE_NAME -characterSet $CHARSET -createAsContainerDatabase $CREATE_AS_CDB -numberOfPDBs $NUMBER_OF_PDBS -pdbName $PDB_NAME -createListener $LISTENER_NAME:$LISTENER_PORT -datafileDestination $ORACLE_DATA_LOCATION -sid $ORACLE_SID -autoGeneratePasswords -emConfiguration DBEXPRESS -emExpressPort $EM_EXPRESS_PORT"

    RETVAL=$?

    echo
    if [ $RETVAL -eq 0 ]
    then
        echo "Database configuration completed successfully. The passwords were auto generated, you must change them by connecting to the database using 'sqlplus / as sysdba' as the oracle user."
        return 0
    else
        echo "Database configuration failed."
        exit 1
    fi
}

# Enh 27965939 - Unsets the proxy env variables
unset_proxy_vars()
{
    if [ "$http_proxy" != "" ]
    then
        unset http_proxy
    fi

    if [ "$HTTP_PROXY" != "" ]
    then
        unset HTTP_PROXY
    fi

    if [ "$https_proxy" != "" ]
    then
        unset https_proxy
    fi

    if [ "$HTTPS_PROXY" != "" ]
    then
        unset HTTPS_PROXY
    fi
}

# Check if the DB is already configured
check_for_configuration()
{
    configfile=`$GREP --no-messages $ORACLE_SID:$ORACLE_HOME /etc/oratab` > /dev/null 2>&1
    if [ "$configfile" = "" ]
    then
        return 1
    fi
    return 0
}

read_config_file()
{
    if [ -f "$CONFIGURATION" ]
    then
        . "$CONFIGURATION"
    else
        echo "The Oracle Database is not configured. Unable to read the configuration file '$CONFIGURATION'"
        exit 1;
    fi
}

# Entry point to configure the DB
configure()
{
    check_for_configuration
    RETVAL=$?
    if [ $RETVAL -eq 0 ]
    then
        echo "Oracle Database instance $ORACLE_SID is already configured."
        exit 1
    fi
    read_config_file
    check_port_availability
    check_em_express_port_availability
    configure_perform
}

check_port_availability()
{
    port=`netstat -n --tcp --listen | $GREP :$LISTENER_PORT`
    if [ "$port" != "" ]
    then
        echo "Port $LISTENER_PORT appears to be in use by another application. Specify a different port in the configuration file '$CONFIGURATION'"
        exit 1;
    fi
}

# Validation method to check for port availability for Oracle EM Express
check_em_express_port_availability()
{
    port=`netstat -n --tcp --listen | $GREP :$EM_EXPRESS_PORT`
    if [ "$port" != "" ]
    then
         echo "Port $EM_EXPRESS_PORT appears to be in use by another application. Specify a different Oracle EM Express port in the configuration file '$CONFIGURATION'"
         exit 1;
    fi
}

restart()
{
    # Check if the DB is already stopped
    pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | $GREP -v grep`
    if [ "$pmon" = "" ]
    then
        start
    else
        stop
        start
    fi
}

configure_delete()
{
    # Unset the proxy env vars before calling dbca and netca
    unset_proxy_vars
    ORABASE=`$ORACLE_HOME/bin/orabase`
    NETCA_LOG_DIR="$ORABASE/cfgtoollogs/netca"
    LSNR_CONFIG_FILE="$ORACLE_HOME/network/admin/listener.ora"
    if [ ! -d "$NETCA_LOG_DIR" ]
    then
       $SU -s /bin/bash $ORACLE_OWNER -c "$MKDIR_CMD -p $NETCA_LOG_DIR"
    fi
    NETCA_LOG="$NETCA_LOG_DIR/netca_deinst_out.log"

    echo "Detecting existing Listeners..."
    if [ -f "$LSNR_CONFIG_FILE" ]
    then
      NUMBER_OF_LISTENERS=`grep -w "DESCRIPTION_LIST" $LSNR_CONFIG_FILE | wc -l`
      if [ "$NUMBER_OF_LISTENERS" == "1" ]
      then
        echo "Deleting Oracle Listener...."
        $SU -s /bin/bash $ORACLE_OWNER -c "$LSNR  stop $LISTENER_NAME" > /dev/null 2>&1
        $SU -s /bin/bash $ORACLE_OWNER -c "$NETCA /deinst >>$NETCA_LOG"
      else
        if [ "$NUMBER_OF_LISTENERS" != "0" ]
        then
          echo "There were more Listeners detected. Verify and remove them manually so the service can be safely deleted"
          exit
        else
          echo "No Listeners were detected. Proceeding with Database removal"
        fi
      fi
    else
      echo "No Listener configuration file found. Proceeding with Database removal"
    fi

    #Then proceed to remove the database
    echo "Detecting existing Oracle Databases..."
    check_for_configuration
    RETVAL=$?
    if [ $RETVAL -eq 0 ]
    then
      echo "Deleting Oracle Database $ORACLE_SID."
      $SU -s /bin/bash  $ORACLE_OWNER -c "$DBCA -silent -deleteDatabase -sourceDB $ORACLE_SID -skipSYSDBAPasswordPrompt true"
    else
      echo "The Oracle Database is not configured. You must run '/etc/init.d/oracledb_$ORACLE_SID-@<DBNRMAJVSNLETTER_STR>@ configure' as the root user to configure the database"
      exit
    fi
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    configure)
        configure
    ;;
    delete)
        configure_delete
    ;;
    restart)
        restart
    ;;
    *)
        echo $"Usage: $0 {start|stop|restart|configure|delete}"
        exit 1
    ;;
esac

exit 0

需要修改部分

CentOS7.6 安装 Oracle19c

只需要修改下面几个即可,包括字符集,服务标识,可插拔数据库名字

export ORACLE_BASE=/opt/oracle
export ORACLE_SID=ORA19C export CHARSET=ZHS16GBK export PDB_NAME=ORA19CPDB

去sysconfg文件夹下复制一份配置,对应上前面修改的服务名称

cd /etc/sysconfig
cp oracledb_ORCLCDB-19c.conf  oracledb_ORA19C-19c.conf

然后使用root用户进行配置

/etc/init.d/oracledb_ORCLCDB-19c configure

CentOS7.6 安装 Oracle19c

报错Oracle Net Services配置失败

这里报错VM-0-12-centos没有返回有效ip,查看/etc/hosts

CentOS7.6 安装 Oracle19c

这里发现VM-0-12-centos绑定的是127.0.0.1的ip地址,包含127的网段是不合法的

所以才会报错无效的ip地址

只需要把VM-0-12-centos那两行用#注释掉就可以

添加环境变量

vim /etc/profile.d/oracle19c.sh

增加内容

export  ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export  PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin
export  ORACLE_SID=ORA19C

profile.d和profile的区别:https://www.cnblogs.com/YC-L/p/14602415.html

启动Oracle

切换到oracle用户

su - oracle

输入指令启动监听

lsnrctl start

CentOS7.6 安装 Oracle19c

使用sysdba免密登陆添加用户,修改密码等

首先要切换到oracle,前面启动监听已经切换过,所以不用再切换

执行以下命令

sqlplus / as sysdba

CentOS7.6 安装 Oracle19c

修改密码

alter user sys identified by root

CentOS7.6 安装 Oracle19c

oracle not available

需要启动一下oracle

startup

然后进入sqlplus使用startup启动一下,报错

CentOS7.6 安装 Oracle19c

内存自动管理的参数MEMORY_TARGET,它能自动调整SGA和PGA

需要用到/dev/shm共享文件系统,而且要求/dev/shm必须大于MEMORY_TARGET,如果/dev/shm比MEMORY_TARGET小,就会报错

我的是自己买的测试机

CentOS7.6 安装 Oracle19c

先查看/dev/shm的大小

df -h

CentOS7.6 安装 Oracle19c

可以看到是919M,默认/dev/shm是内存大小的两倍,可以配置为一半的1.5倍--1378M

打开配置文件

vim /etc/fstab

然后追加或者修改

tmpfs /dev/shm     tmpfs   defaults,size=1378M  0 0

重新挂载/dev/shm使配置生效

mount -o remount /dev/shm

如果有报错打印一下错误信息

CentOS7.6 安装 Oracle19c

我之前没有写1378M,而是用了1.5G,查了一下该参数必须是整数,不能有小数点,改过以后就没有报错了

挂载完后确认一下容量

CentOS7.6 安装 Oracle19c

/dev/shm是做什么的:

至此,oracle19c就安装完成了,后面登陆进行操作就可以了

上一篇:MFC 获取DC和输出文字、获取指定区域


下一篇:CentOS8通过RPM安装Oracle19c