介质下载:
https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/index.html
wget https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
安装oracle19c:
准备oracle用户:
[root@localhost ~]# groupadd oinstall
[root@localhost ~]# groupadd dba
[root@localhost ~]# useradd oracle -g oinstall -G dba
[root@localhost ~]# usermod -g oinstall oracle
[root@localhost ~]# usermod -a -G dba oracle
[root@localhost ~]# id oracle
uid=1001(oracle) gid=1002(oinstall) groups=1002(oinstall),1003(dba)
安装19c软件:
yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
yum -y localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm
创建数据库:
[root@localhost ~]# /etc/init.d/oracledb_ORCLCDB-19c configure
建议修改/etc/init.d/oracledb_ORCLCDB-19c脚本为非容器模式。
[root@localhost sysconfig]# cd /etc/init.d/
[root@localhost init.d]# ls
functions netconsole network oracle-database-preinstall-19c-firstboot oracledb_jycdb-19c oracledb_ORCLCDB-19c README
[root@localhost init.d]# ls -lt
total 68
-rwxr-xr-x. 1 root root 10408 Apr 28 09:18 oracledb_jycdb-19c
-rwxr-xr-x. 1 root root 10017 Apr 18 15:22 oracledb_ORCLCDB-19c
-rwx------. 1 root root 1281 Feb 14 15:03 oracle-database-preinstall-19c-firstboot
-rw-r--r--. 1 root root 1160 Oct 31 07:31 README
-rw-r--r--. 1 root root 18281 Aug 24 2018 functions
-rwxr-xr-x. 1 root root 4569 Aug 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 Aug 24 2018 network
[root@localhost init.d]# cat oracledb_jycdb-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=jycdb
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=false
# 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"
$SU -s /bin/bash $ORACLE_OWNER -c "$DBCA -silent -createDatabase -gdbName $ORACLE_SID -templateName $TEMPLATE_NAME -characterSet $CHARSET -createAsContainerDatabase $CREATE_AS_CDB -createListener $LISTENER_NAME:$LISTENER_PORT -datafileDestination $ORACLE_DATA_LOCATION -sid $ORACLE_SID -autoGeneratePasswords -emConfiguration NONE -automaticMemoryManagement false -redoLogFileSize 100"
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-@
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
[root@localhost sysconfig]# pwd
/etc/sysconfig
[root@localhost sysconfig]# more oracledb_jycdb-19c.conf
#This is a configuration file to setup the Oracle Database.
#It is used when running '/etc/init.d/oracledb_ORCLCDB configure'.
#Please use this file to modify the default listener port and the
#Oracle data location.
# LISTENER_PORT: Database listener
LISTENER_PORT=1521
# ORACLE_DATA_LOCATION: Database oradata location
ORACLE_DATA_LOCATION=/opt/oracle/oradata
# EM_EXPRESS_PORT: Oracle EM Express listener
EM_EXPRESS_PORT=5500
连接数据库:
配置环境变量:
[oracle@localhost ~]$ pwd
/home/oracle
[oracle@localhost ~]$ more .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 ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export ORACLE_SID=ORCLCDB
export LANG=en_US.UTF-8
#export LANG=zh_CN.gb18030
export NLS_LANG=american_america.ZHS16GBK
export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss"
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch
export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH=${PATH}:$ORACLE_BASE/common/oracle/bin:/home/oracle/run
export ORACLE_TERM=xterm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=$ORACLE_HOME/JRE
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export THREADS_FLAG=native
export TEMP=/tmp
export TMPDIR=/tmp
umask 022
export TMOUT=0
alias s="sqlplus / as sysdba"
[oracle@localhost ~]$ s
SQL*Plus: Release 19.0.0.0.0 - Production on Sun Apr 28 09:06:09 2019
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> set line 132 wrap off
SQL> show parameter name;
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
cdb_cluster_name string
cell_offloadgroup_name string
db_file_name_convert string
db_name string ORCLCDB
db_unique_name string ORCLCDB
global_names boolean FALSE
instance_name string ORCLCDB
lock_name_space string
log_file_name_convert string
pdb_file_name_convert string
processor_group_name string
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
service_names string ORCLCDB
SQL> !lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 28-APR-2019 09:06:32
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 28-APR-2019 08:42:36
Uptime 0 days 0 hr. 23 min. 56 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=localhost)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORCLCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "878d9b566bd44aede055000000000001" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "ORCLCDB" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "ORCLCDBXDB" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
Service "orclpdb1" has 1 instance(s).
Instance "ORCLCDB", status READY, has 1 handler(s) for this service...
The command completed successfully
SQL>