赞
踩
本文记录下从一个新环境从0开始如何安装Oralce及APEX的,基础知识可参考之前文章:
https://blog.csdn.net/x6_9x/article/details/116260464?spm=1001.2014.3001.5501
操作系统:CentOS7
数据库:Oracle 19C
Web服务器 apache-tomcat-9.0.45
ORDS:官网最新
JDK:系统自带的OPEN JDK 11
18C之前安装oracle数据库一步一步有点麻烦,要么使用图形化指导安装或者配置参数文件进行静默安装。oracle"与时俱进"自从18C开始才推出了采用rpm包安装的方式,今天我们来体验一把,只需要5个命令就能得到一个带CDB和PDB的数据库。
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
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
yum -y install oracle-database-preinstall-19c
这个命令做了很多工作,调整内核参数、创建数据库用户和组,安装依赖包。
准备工作:将下载的rpm包放到/tmp目录下,cd到/tmp目录
yum install -y oracle-database-ee-19c-1.0-1.x86_64.rpm
安装完成后,如果需要更改默认数据文件的位置可以到 /etc/sysconfig/oracledb_ORCLCDB-19c.conf 配置文件去修改,修改完成后。可以执行数据库配置工作了。
/etc/init.d/oracledb_ORCLCDB-19c configure
上面这个脚本本质是调用DBCA进行数据库静默配置,只是官方进一步封装了,用起来更友好。
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; /
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
切换到tomcat用户下
java -jar ords.war install advanced # 卸载命令是:java -jar ords.war uninstall
配置如下
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
如果在生产环境建议创建一个ORDS_INSTALL专用用户,然后用ords自带的脚本@ords_installer_privileges.sql授权,来替代用sys连接数据库,参考命令:
create user ords_install
identified by xxxxxx
default tablespace APEX
temporary tablespace TEMP_APEX;
将上一步产生的ords.war及apex的images复制到tomcat的webapps目录下,启动tomcat
可以考虑一键部署,参考Oracle官方封装的vagrant脚本,来源
https://github.com/oracle/vagrant-projects/tree/main/OracleAPEX/scripts
下面粘贴如下,可以参考学习之,看看老外是怎么写shell脚本及注释的,写的是真规范。
#!/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!";
#!/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 => 'your@emailaddress.com', 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'
官方的这个使用的Oracle自带的http网关,没有使用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 ""
本文部分代码复制自下面文章
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。