ORACLE APEX 21.2 installation and one-click deployment

This article records how to install Oralce and APEX from 0 in a new environment. For basic knowledge, please refer to the previous article:
https://blog.csdn.net/x6_9x/article/details/116260464?spm=1001.2014.3001.5501

target environment

Operating system: CentOS7

Database: Oracle 19C

Web server apache-tomcat-9.0.45

ORDS: The latest official website

JDK: OPEN JDK 11 that comes with the system

Install Oracle 19C database - install in the form of RPM package

It is a bit troublesome to install the oracle database step by step before 18C. You can either use the graphical guidance to install or configure the parameter file for silent installation. Oracle "keeps pace with the times" since 18C and has only introduced the way of using rpm package installation. Today we will experience it. It only takes 5 commands to get a database with CDB and PDB.

The configuration key is compatible with ORACLE LINUX

wget https://yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

Configure YUM source

wget -O /etc/yum.repos.d/oracle.repo http://public-yum.oracle.com/public-yum-ol7.repo
wget -O /etc/yum.repos.d/epel.repo  http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache

Install dependent packages and configure system account parameters

yum -y install oracle-database-preinstall-19c

This command does a lot of work, adjusting kernel parameters, creating database users and groups, and installing dependent packages.

install database

Preparations: put the downloaded rpm package in the /tmp directory, and cd to the /tmp directory

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

After the installation is complete, if you need to change the location of the default data file, you can go to the /etc/sysconfig/oracledb_ORCLCDB-19c.conf configuration file to modify it. After the modification is completed. The database configuration work can be performed.

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

The essence of the above script is to call DBCA for silent configuration of the database, but it is further encapsulated by the official, which is more friendly to use.

APEX installation

su - oracle
cd $ORACLE_HOME/apex
--切换到PDB
alter session set container=$ORACLE_PDB;
--创建专用表空间
CREATE TABLESPACE apex DATAFILE '$ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB/apex01.dbf'
        SIZE 300M AUTOEXTEND ON NEXT 1M;
--安装       
@apexins.sql APEX APEX TEMP /i/
--修改管理员密码
@apxchpwd.sql
--解锁APEX_PUBLIC_USER账号及密码
ALTER USER APEX_PUBLIC_USER ACCOUNT UNLOCK;
ALTER USER APEX_PUBLIC_USER IDENTIFIED BY APEX_PUBLIC_USER;
--启用REST(设置APEX_LISTENER 和APEX_REST_PUBLIC_USER  密码)
@apex_rest_config.sql
--安装语言包(APEX_210200 )
cd builder/zh-cn
ALTER SESSION SET CURRENT_SCHEMA = APEX_210200;
@load_zh-cn.sql
--配置网络策略
BEGIN
    DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
        host => '*',
        ace => xs$ace_type(privilege_list => xs$name_list('connect'),
                           principal_name => 'APEX_210200',
                           principal_type => xs_acl.ptype_db));
END;
/

Tomcat installation

tar -zxvf apache-tomcat-9.0.45.tar.gz
useradd -d /data/tomcat/home -s /bin/bash tomcat
chown -R tomcat:tomcat /data/tomcat


cat > /etc/systemd/system/tomcat.service << "EOF"
[Unit]
Description=Apache Tomcat 9 Servlet Container
Wants=network.target
After=network.target

[Service]
User=tomcat
Group=tomcat
Type=forking
UMask=0007
RestartSec=10
ExecStart=/data/tomcat/apache-tomcat-9.0.45/bin/startup.sh
ExecStop=/data/tomcat/apache-tomcat-9.0.45/bin/shutdown.sh
SuccessExitStatus=143
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

Configure ORDS

Switch to the tomcat user

java -jar ords.war install advanced # 卸载命令是:java -jar ords.war uninstall

The configuration is as follows

This Oracle REST Data Services instance has not yet been configured.
Please complete the following prompts


Enter the location to store configuration data: config
Specify the database connection type to use.
Enter number for [1] Basic  [2] TNS  [3] Custom URL [1]:
Enter the name of the database server [localhost]:localhost
Enter the database listen port [1521]:
Enter 1 to specify the database service name, or 2 to specify the database SID [1]:
Enter the database service name:UAT
Enter 1 if you want to verify/install Oracle REST Data Services schema or 2 to skip this step [1]:
Enter the database password for ORDS_PUBLIC_USER:
Confirm password:
Requires to login with administrator privileges to verify Oracle REST Data Services schema.

Enter the administrator username:sys
Enter the database password for sys:
Confirm password:
Connecting to database user: sys url: jdbc:oracle:thin:@//localhost:1521/UAT

Retrieving information.
Enter the default tablespace for ORDS_METADATA [SYSAUX]:APEX_INSTALL
Enter the temporary tablespace for ORDS_METADATA [TEMP1]:TEMP_APEX
Enter the default tablespace for ORDS_PUBLIC_USER [SYSAUX]:APEX_INSTALL
Enter the temporary tablespace for ORDS_PUBLIC_USER [TEMP1]:TEMP_APEX
Enter 1 if you want to use PL/SQL Gateway or 2 to skip this step.
If using Oracle Application Express or migrating from mod_plsql then you must enter 1 [1]:
Enter the PL/SQL Gateway database user name [APEX_PUBLIC_USER]:APEX_PUBLIC_USER
Enter the database password for APEX_PUBLIC_USER:
Confirm password:
Enter 1 to specify passwords for Application Express RESTful Services database users (APEX_LISTENER, APEX_REST_PUBLIC_USER) or 2 to skip this step [1]:
Enter the database password for APEX_LISTENER:
Confirm password:
Enter the database password for APEX_REST_PUBLIC_USER:
Confirm password:
Enter a number to select a feature to enable:
   [1] SQL Developer Web  (Enables all features)
   [2] REST Enabled SQL
   [3] Database API
   [4] REST Enabled SQL and Database API
   [5] None
Choose [1]:
2021-04-22T05:43:10.479Z INFO        reloaded pools: []
Installing Oracle REST Data Services version 20.4.3.r0501904
... Log file written to /home/tomcat/ords_install_core_2021-04-22_134310_00605.log
... Verified database prerequisites
... Created Oracle REST Data Services proxy user
... Created Oracle REST Data Services schema
... Granted privileges to Oracle REST Data Services
... Created Oracle REST Data Services database objects
... Log file written to /home/tomcat/ords_install_datamodel_2021-04-22_134331_00645.log
... Log file written to /home/tomcat/ords_install_apex_2021-04-22_134332_00859.log
Completed installation for Oracle REST Data Services version 20.4.3.r0501904. Elapsed time: 00:00:23.882 

Enter 1 if you wish to start in standalone mode or 2 to exit [1]:2

If it is recommended to create a dedicated user for ORDS_INSTALL in the production environment, and then use the script @ords_installer_privileges.sql that comes with ords to authorize instead of using sys to connect to the database, refer to the command:

create user ords_install
  identified by xxxxxx
  default tablespace APEX
  temporary tablespace TEMP_APEX;

Configure Tomcat

Copy the ords.war and apex images generated in the previous step to the webapps directory of tomcat, and start tomcat

Optimization: One-click deployment

You can consider one-click deployment, refer to the vagrant script officially packaged by Oracle, source

https://github.com/oracle/vagrant-projects/tree/main/OracleAPEX/scripts

Paste below as follows, you can refer to the study to see how foreigners write shell scripts and comments, what is written is really standardized.

Install the database

#!/bin/bash
#
# LICENSE UPL 1.0
#
# Copyright © 1982-2019 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
#    NAME
#      database.sh
#
#    DESCRIPTION
#      Install and Configure Oracle Database XE 18.4
#
#    NOTES
#       DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
#    AUTHOR
#       Simon Coter
#
#    MODIFIED   (MM/DD/YY)
#    scoter     03/19/19 - Creation
#

# set environment variables
echo "export ORACLE_BASE=/opt/oracle" >> /home/oracle/.bashrc && \
echo "export ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE" >> /home/oracle/.bashrc && \
echo "export ORACLE_SID=XE" >> /home/oracle/.bashrc && \
echo "export PATH=\$PATH:\$ORACLE_HOME/bin" >> /home/oracle/.bashrc

timedatectl set-timezone "$SYSTEM_TIMEZONE"
echo 'INSTALLER: Timezone updated'

echo 'INSTALLER: Environment variables set'

echo 'INSTALLER: Oracle Database Installation Started up'

# Install Oracle
yum -y localinstall /vagrant/oracle-database-xe-18c-*.x86_64.rpm

echo 'INSTALLER: Oracle software installed'

# Auto generate ORACLE PWD if not passed on
export ORACLE_PWD=${ORACLE_PWD:-"`openssl rand -base64 8`1"}

# Create database
mv /etc/sysconfig/oracle-xe-18c.conf /etc/sysconfig/oracle-xe-18c.conf.original && \
cp /vagrant/ora-response/oracle-xe-18c.conf.tmpl /etc/sysconfig/oracle-xe-18c.conf && \
chmod g+w /etc/sysconfig/oracle-xe-18c.conf && \
sed -i -e "s|###ORACLE_CHARACTERSET###|$ORACLE_CHARACTERSET|g" /etc/sysconfig/oracle-xe-18c.conf && \
sed -i -e "s|###ORACLE_PWD###|$ORACLE_PWD|g" /etc/sysconfig/oracle-xe-18c.conf

# required for database creation
. /home/oracle/.bashrc
su - oracle -c "mkdir -p $ORACLE_BASE/admin"

# start listener and datbase configuration
/etc/init.d/oracle-xe-18c configure

echo 'INSTALLER: Database created'

# add tns entry for XEPDB1
chmod o+r /opt/oracle/product/18c/dbhomeXE/network/admin/tnsnames.ora

# add tnsnames.ora entry for PDB
echo 'XEPDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XEPDB1)
    )
  )
' >> /opt/oracle/product/18c/dbhomeXE/network/admin/tnsnames.ora

echo 'INSTALLER: TNS entry added'

# configure systemd to start oracle instance on startup
systemctl daemon-reload
systemctl enable oracle-xe-18c
systemctl restart oracle-xe-18c
echo "INSTALLER: Created and enabled oracle-xe-18c systemd's service"

# enable global port for EM Express
su -l oracle -c 'sqlplus / as sysdba <<EOF
   EXEC DBMS_XDB_CONFIG.SETGLOBALPORTENABLED (TRUE);
   exit
EOF'

echo 'INSTALLER: Global EM Express port enabled'

echo $ORACLE_PWD > /vagrant/apex-pwd

echo "ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: $ORACLE_PWD";

echo "INSTALLER: Installation complete, database ready to use!";

Install APEX

#!/bin/bash
#
# LICENSE UPL 1.0
#
# Copyright © 1982-2019 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
#    NAME
#      apex.sh
#
#    DESCRIPTION
#      Execute Oracle Application Express installation and configuration
#
#    NOTES
#       DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
#    AUTHOR
#       Simon Coter
#
#    MODIFIED   (MM/DD/YY)
#    scoter     03/19/19 - Creation
#

. /home/oracle/.bashrc 

export ORACLE_PWD=`cat /vagrant/apex-pwd`
ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`"
echo "export ORACLE_PDB=$ORACLE_PDB" >> /home/oracle/.bashrc

# Install new apex release
cd $ORACLE_HOME
APEX_INSTALL=$(find /vagrant -maxdepth 1 -name "apex_*.*.zip" -type f | tail -1)

if [[ -z ${APEX_INSTALL} || ! -r "${APEX_INSTALL}" ]]; then
  echo 'INSTALLER: Could not find APEX installer file. Exiting.'
  exit 1
fi

unzip $APEX_INSTALL
chown -R oracle:oinstall $ORACLE_HOME/apex
cd -

echo 'INSTALLER: Updated APEX extracted to the ORACLE_HOME'

# Prepare APEX tablespaces
su -l oracle -c "sqlplus / as sysdba <<EOF
	ALTER DATABASE DATAFILE '$ORACLE_BASE/oradata/$ORACLE_SID/system01.dbf' resize 1024m;
	ALTER DATABASE DATAFILE '$ORACLE_BASE/oradata/$ORACLE_SID/sysaux01.dbf' resize 1024m;
	alter session set container=$ORACLE_PDB;
	CREATE TABLESPACE apex DATAFILE '$ORACLE_BASE/oradata/$ORACLE_SID/$ORACLE_PDB/apex01.dbf'
        SIZE 300M AUTOEXTEND ON NEXT 1M;
	exit;
EOF"

echo 'INSTALLER: APEX tablespaces created'

# Install APEX into the PDB Oracle Database
su -l oracle -c "cd $ORACLE_HOME/apex; sqlplus / as sysdba <<EOF
	alter session set container=$ORACLE_PDB;
	@apexins.sql APEX APEX TEMP /i/
	exit;
EOF"

echo 'INSTALLER: Oracle APEX Installation completed'

# unlock APEX_PUBLIC_USER
su -l oracle -c "cd $ORACLE_HOME/apex; sqlplus / as sysdba <<EOF
	alter session set container=$ORACLE_PDB;
	alter user APEX_PUBLIC_USER identified by \"${ORACLE_PWD}\" account unlock;
	exit;
EOF"

# Create the APEX Instance Administration user and set the password
su -l oracle -c "sqlplus / as sysdba <<EOF
	alter session set container=$ORACLE_PDB;
	begin
	    apex_util.set_security_group_id( 10 );
	    apex_util.create_user(
	        p_user_name => 'ADMIN',
	        p_email_address => '[email protected]',
	        p_web_password => '${ORACLE_PWD}',
	        p_developer_privs => 'ADMIN' );
	    apex_util.set_security_group_id( null );
	    commit;
	end;
	/
	exit;
EOF"

# config APEX REST and set the passwords of APEX_REST_PUBLIC_USER and APEX_LISTENER
su -l oracle -c "cd $ORACLE_HOME/apex; sqlplus / as sysdba <<EOF
        alter session set container=$ORACLE_PDB;
        @apex_rest_config_core.sql $ORACLE_HOME/apex/ ${ORACLE_PWD} ${ORACLE_PWD}
        exit;
EOF"

# Create a network ACE for APEX (this is used when consuming Web services or sending outbound mail)
cat > /tmp/apex-ace.sql << EOF
        alter session set container=$ORACLE_PDB;
        declare
            l_acl_path varchar2(4000);
            l_apex_schema varchar2(100);
        begin
            for c1 in (select schema
                         from sys.dba_registry
                        where comp_id = 'APEX') loop
                l_apex_schema := c1.schema;
            end loop;
            sys.dbms_network_acl_admin.append_host_ace(
                host => '*',
                ace => xs\$ace_type(privilege_list => xs\$name_list('connect'),
                principal_name => l_apex_schema,
                principal_type => xs_acl.ptype_db));
            commit;
        end;
	/
	exit;
EOF
su -l oracle -c "sqlplus / as sysdba @/tmp/apex-ace.sql"
rm -f /tmp/apex-ace.sql

echo 'INSTALLER: Oracle APEX Configuration completed'

ORDS configuration

The official one uses Oracle's own http gateway instead of tomcat.

#!/bin/bash
#
# LICENSE UPL 1.0
#
# Copyright © 1982-2019 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
#    NAME
#      ords.sh
#
#    DESCRIPTION
#      Execute Oracle Rest Data Services installation and configuration
#
#    NOTES
#       DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
#    AUTHOR
#       Simon Coter
#
#    MODIFIED   (MM/DD/YY)
#    scoter     03/19/19 - Creation
#

. /home/oracle/.bashrc 

export ORACLE_PWD=`cat /vagrant/apex-pwd`
rm -f /vagrant/apex-pwd

# Install ORDS
mkdir $ORACLE_BASE/ords
export ORDS_HOME=$ORACLE_BASE/ords
echo "export ORDS_HOME=$ORACLE_BASE/ords" >> /home/oracle/.bashrc
cd  $ORDS_HOME
ORDS_INSTALL=$(find /vagrant -maxdepth 1 -name "ords[_-]*.*.zip" -type f | tail -1)

if [[ -z ${ORDS_INSTALL} || ! -r "${ORDS_INSTALL}" ]]; then
  echo 'INSTALLER: Could not find ORDS installer file. Exiting.'
  exit 1
fi

unzip $ORDS_INSTALL
chown -R oracle:oinstall $ORDS_HOME

echo 'INSTALLER: Oracle Rest Data Services extracted to ORACLE_BASE'

# Create config directory
su -l oracle -c "$ORACLE_HOME/jdk/bin/java -jar $ORDS_HOME/ords.war configdir $ORDS_HOME/config"
su -l oracle -c "mkdir -p $ORDS_HOME/config/ords/standalone"
su -l oracle -c "mkdir -p $ORDS_HOME/config/ords/doc_root"

# Configure ORDS
cat > $ORDS_HOME/params/ords_params.properties << EOF
db.hostname=localhost
db.port=1521
# CUSTOMIZE db.servicename
db.servicename=${ORACLE_PDB}
db.username=APEX_PUBLIC_USER
db.password=${ORACLE_PWD}
migrate.apex.rest=false
plsql.gateway.add=true
rest.services.apex.add=true
rest.services.ords.add=true
schema.tablespace.default=SYSAUX
schema.tablespace.temp=TEMP
sys.user=sys
sys.password=${ORACLE_PWD}
standalone.mode=TRUE
standalone.http.port=8080
standalone.use.https=false
# CUSTOMIZE standalone.static.images to point to the directory 
# containing the images directory of your APEX distribution
standalone.static.images=${ORACLE_HOME}/apex/images
user.apex.listener.password=${ORACLE_PWD}
user.apex.restpublic.password=${ORACLE_PWD}
user.public.password=oracle
user.tablespace.default=SYSAUX
user.tablespace.temp=TEMP
EOF

su -l oracle -c "cd $ORACLE_HOME/apex; sqlplus / as sysdba <<EOF
        alter session set container=$ORACLE_PDB;
        alter user APEX_LISTENER identified by \"${ORACLE_PWD}\" account unlock;
        alter user APEX_REST_PUBLIC_USER identified by \"${ORACLE_PWD}\" account unlock;
        exit;
EOF"

cat > $ORDS_HOME/config/ords/standalone/standalone.properties << EOF
jetty.port=8080
standalone.context.path=/ords
standalone.doc.root=$ORDS_HOME/config/ords/doc_root
standalone.scheme.do.not.prompt=true
standalone.static.context.path=/i
standalone.static.path=$ORACLE_HOME/apex/images
EOF

# Fix permissions on ORDS standalone directories
chown -R oracle:oinstall $ORACLE_BASE/ords

echo 'INSTALLER: Oracle Rest Data Services configuration created'

# Create and configure ORDS Database Users/Objects
su -l oracle -c "$ORACLE_HOME/jdk/bin/java -jar $ORDS_HOME/ords.war setup --parameterFile $ORDS_HOME/params/ords_params.properties --silent"

echo 'INSTALLER: Oracle Rest Data Services installation completed'

# Start ORDS service
export JAVA_HOME=$ORACLE_HOME/jdk/bin
cat > /etc/systemd/system/ords.service << EOF
[Unit]
Description=Start Oracle REST Data Services
After=oracle-xe-18c.service

[Service]
User=oracle
ExecStart=${JAVA_HOME}/java -jar ${ORDS_HOME}/ords.war
StandardOutput=syslog
SyslogIdentifier=ords

[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now ords
echo 'INSTALLER: Oracle Rest Data Services started'

echo ""
echo "INSTALLER: APEX/ORDS Installation Completed";
echo "INSTALLER: You can access APEX by your Host Operating System at following URL:";
echo "INSTALLER: http://localhost:8080/ords/";
echo "INSTALLER: Access granted with:";
echo "INSTALLER: Workspace: internal";
echo "INSTALLER: Username:  admin";
echo "INSTALLER: Password:  ${ORACLE_PWD}";
echo ""

References

Part of the code in this article is copied from the following article

https://blog.csdn.net/shilukun/article/details/107055848

https://blog.csdn.net/bisal/article/details/100909708

https://yum.oracle.com/getting-started.html#installing-software-from-oracle-linux-yum-server

https://yum.oracle.com/faq.html#a10

Guess you like

Origin blog.csdn.net/x6_9x/article/details/121289095