Oracle® VM Template Builder Installation and User's Guide Release 2.1 Part Number E14391-01 |
|
|
PDF · Mobi · ePub |
This Appendix contains examples of Oracle VM Template Builder configuration and cleanup scripts, and contains:
This example configuration script is used in the Oracle Database 11g templates.
#!/bin/sh # # functions fail () { echo ovm_error "$*" ovm_error "Failed to install Oracle Database." press_anykey exit 1 } relink_binaries () { echo ovm_info "Relinking Oracle Binaries..." su -s /bin/bash oracle -c \ "export ORACLE_HOME=$ORACLE_HOME; \ cd $ORACLE_HOME/bin && ./relink all >/home/oracle/relink.log 2>&1" if [ `grep -ic -e "undefined reference" \ -e " failed " /home/oracle/relink.log` -gt 0 ]; then ovm_error "Oracle Relinking Failed. Logs: /home/oracle/relink.log" echo "To build again do :" echo "cd $ORACLE_HOME/bin " echo "./relink all " fail "relink error." else ovm_info "Oracle Relinking Completed Successfully" ovm_info "Logs: /home/oracle/relink.log" fi } configure_ask() { cat <<EOF Oracle Database Configuration ------------------------------------------------- This will configure on-boot properties of Oracle Database. The following questions will determine whether the database should be starting upon system boot, the ports it will use, and the passwords that will be used for database accounts. Press <Enter> to accept the defaults. EOF # prompt for relink or not while true; do echo -n "Do you want to relink binaries? (y/n) [n] " && read n case "$n" in y|Y|yes|Yes|YES) DO_RELINK=true break;; ""|n|N|no|No|NO) DO_RELINK=false break;; *) continue;; esac done echo #get the http port value while true; do while true; do echo -n Specify the HTTP port that will be used for Oracle Application Express [8080]: read LINE if [ -z $LINE ]; then LINE=8080 fi port=`netstat -n --tcp --listen | grep :$LINE | awk '{print $4}' | cut -d':' -f2` if [ "$port" = "$LINE" ]; then echo Port $port appears to be in use by another application.\ Please specify a different port. else break; fi done case "$LINE" in "") break ;; *[^0-9]*) echo "Invalid http port: $LINE" ;; *) HTTP_PORT=$LINE break ;; esac done #get the listener port value while true; do echo while true; do echo -n Specify a port that will be used for the database listener [1521]: read LINE if [ -z $LINE ]; then LINE=1521 fi echo port=`netstat -n --tcp --listen | grep :$LINE | awk '{print $4}' | cut -d':' -f2` if [ "$port" = "$LINE" ]; then echo Port $port appears to be in use by another application.\ Please specify a different port. else break; fi done case "$LINE" in "") break ;; *[^0-9]*) echo "Invalid port: $LINE" >&2 ;; *) if [ "$HTTP_PORT" != "$LINE" ] then LISTENER_PORT=$LINE break else echo Database listener cannot be configured on the same port as APEX. fi ;; esac done #get the database password while true; do echo -n "Specify a password to be used for database accounts. Note that the same password will be used for SYS, SYSTEM and ADMIN for APEX. Oracle recommends the use of different passwords for each database account. This can be done after initial configuration:" while true; do /bin/stty -echo > /dev/null 2>&1 temp=`echo $IFS` export IFS="\n " while true; do read LINE while [ -z "$LINE" ]; do echo echo -n "Password can't be null. Enter password:" read LINE done result=`expr index "$LINE" [\'\"]` if [ $result != 0 ]; then echo echo -n "The password you entered contains invalid characters. Enter password: " else break fi done echo echo -n "Confirm the password:" read LINE1 echo if [ "$LINE" != "$LINE1" ]; then echo echo -n "Passwords do not match. Enter the password:" else break fi done /bin/stty echo > /dev/null 2>&1 ORACLE_PASSWORD=$LINE export IFS=$temp break; done # get option enable or not while true; do if [ "$ORACLE_DBENABLED" = "true" ]; then CUR=y else CUR=n fi echo echo -n "Do you want Oracle Database to be started on boot (y/n) [y]:" read LINE if [ -z $LINE ]; then ORACLE_DBENABLED=true fi echo case "$LINE" in "") break ;; y|Y) ORACLE_DBENABLED=true break ;; n|N) ORACLE_DBENABLED=false break ;; *) echo "Invalid response: $LINE " >&2 break esac done } configure_perform () { ret=0 # replace the strings sed -e "s/%hostname%/$(hostname)/g" \ -e "s/%port%/$LISTENER_PORT/g" \ $ORACLE_CONFIG_HOME/listener.ora > $ORACLE_HOME/network/admin/listener.ora sed -e "s/%hostname%/$(hostname)/g" \ -e "s/%port%/$LISTENER_PORT/g" \ $ORACLE_CONFIG_HOME/tnsnames.ora > $ORACLE_HOME/network/admin/tnsnames.ora sed -e "s/%hostname%/$(hostname)/g" \ -e "s/%port%/$LISTENER_PORT/g" \ $ORACLE_CONFIG_HOME/initorcl.ora > $ORACLE_HOME/config/initorcl.ora chown oracle:dba $ORACLE_HOME/network/admin/listener.ora \ $ORACLE_HOME/network/admin/tnsnames.ora \ $ORACLE_HOME/config/initorcl.ora export ORACLE_HOME #start listener su -s /bin/bash $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" > /dev/null 2>&1 # start ASM instance # wait for cssd automatically startup. 30 secs. echo "Waiting for CSS available." ct=0 while ! $ORACLE_HOME/bin/crsctl check css >/dev/null 2>&1; do sleep 3 ct=$(($ct+1)) [ $ct -gt 10 ] && break done if ! $ORACLE_HOME/bin/crsctl check css >/dev/null 2>&1; then echo "Starting Cluster Synchronization Services." /etc/init.d/init.cssd start; init q # 30 tries with 10 secs interval => 5 mins timeout echo "Waiting for CSS available." ct=0 while ! $ORACLE_HOME/bin/crsctl check css >/dev/null 2>&1; do sleep 10 ct=$(($ct+1)) if [ $ct -gt 30 ]; then fail "Failed to start CSS." fi done fi if [ "$ORACLE_RNAME" = oracle10g ]; then su -s /bin/bash $ORACLE_OWNER -c "ORACLE_SID=+ASM $ORACLE_HOME/bin/sqlplus -s /nolog" <<SQL connect / as sysdba startup quit SQL ret=$? elif [ "$ORACLE_RNAME" = oracle11g ]; then su -s /bin/bash $ORACLE_OWNER -c "ORACLE_SID=+ASM $ORACLE_HOME/bin/sqlplus -s /nolog" <<SQL connect / as sysasm startup quit SQL ret=$? else fail "Unknown database." fi if [ $ret -ne 0 ]; then fail "Failed to start up ASM instance." fi # run post creation sql # 1. create spfile with configured pfile # 2. change sys/system password. # 3. change APEX ADMIN password # 4. enable XML DB HTTP Service su -s /bin/bash $ORACLE_OWNER -c "ORACLE_SID=orcl $ORACLE_HOME/bin/sqlplus -s /nolog" <<SQL connect / as sysdba startup nomount pfile="$ORACLE_HOME/config/initorcl.ora"; create spfile='+DATA/orcl/spfileorcl.ora' FROM pfile='$ORACLE_HOME/config/initorcl.ora'; alter database mount; alter database open; shutdown immediate; startup; alter user sys identified by "$ORACLE_PASSWORD"; alter user system identified by "$ORACLE_PASSWORD"; ALTER USER ANONYMOUS ACCOUNT UNLOCK; ALTER SYSTEM SET SHARED_SERVERS = 5 SCOPE=BOTH; @$ORACLE_HOME/apex/apxxepwd "$ORACLE_PASSWORD"; begin dbms_xdb.sethttpport('$HTTP_PORT'); dbms_xdb.setftpport('0'); end; / commit; exec dbms_xdb.cfg_refresh; quit; SQL if [ $? -ne 0 ]; then fail "Failed to run post database creation script." fi # open http port and database port, sshd port as well system-config-securitylevel-tui --quiet \ --port=$LISTENER_PORT \ --port=$HTTP_PORT \ --port=ssh # add ASM and database instances to /etc/oratab if [ -f "$ORATAB" ]; then if grep -q "^+ASM:$ORACLE_HOME" $ORATAB ; then sed -i "s|+ASM:$ORACLE_HOME:.|+ASM:$ORACLE_HOME:Y|g" $ORATAB else echo "+ASM:$ORACLE_HOME:Y" >> $ORATAB fi if grep -q "^orcl" $ORATAB; then sed -i "s|orcl:$ORACLE_HOME:.|orcl:$ORACLE_HOME:W|g" $ORATAB else echo "orcl:$ORACLE_HOME:W" >> $ORATAB fi else echo "+ASM:$ORACLE_HOME:Y" >> $ORATAB echo "orcl:$ORACLE_HOME:W" >> $ORATAB chown oracle:root $ORATAB fi return 0 } write_sysconfig() { cat >"$CONFIGURATION" <<EOF #This is a configuration file for automatic starting of the Oracle #Database and listener at system startup. # ORACLE_DBENABLED:'true' means to load the Database at system boot. ORACLE_DBENABLED=${ORACLE_DBENABLED:-false} EOF ovm_log "Wrote to $CONFIGURATION" } # tmpfs check only for 11g check_tmpfs() { tmpfs_name=tmpfs tmpfs_size=0 tmpfs_used_size=0 if df | grep -q /dev/shm ; then tmpfs_name=$(df | grep /dev/shm | awk '{print $1}') tmpfs_size=$(df | grep /dev/shm | awk '{print $2}') tmpfs_used_size=$(df | grep /dev/shm | awk '{print $3}') fi [ $tmpfs_size -ge 2097152 ] && return 0 ovm_log "set 2GB tmpfs" sed -i '/tmpfs/s/defaults/defaults,size=2g/' /etc/fstab [ $tmpfs_used_size -eq 0 ] && umount /dev/shm >/dev/null 2>&1 mount -t tmpfs $tmpfs_name -o size=2g /dev/shm } ############################################################################ case "$ORACLE_TRACE" in T) set -x;; *) ;; esac # source functions from ovm-template-config package . /usr/lib/oraclevm-template/functions . /usr/lib/oraclevm-template/functions # oracle databse env variables . /u01/db-config # display script version if [ "$1" = "-v" -o "$1" = "--version" ]; then echo $VERSION exit 0 fi ####################################################################### # prerequisites check # check if oracle-validated has been installed if ! rpm -q oracle-validated >/dev/null 2>&1; then fail "oracle-validated not installed." fi # check if required packages have been installed if ! rpm -q oracleasm-`uname -r` >/dev/null 2>&1; then fail "oracleasm-`uname -r` not installed." fi if ! rpm -q oracleasmlib >/dev/null 2>&1; then fail "oracleasmlib not installed." fi # configure and enable asmlib /etc/init.d/oracleasm configure >/dev/null <<-EOF oracle dba y y EOF # check if asm disk available if ! /etc/init.d/oracleasm listdisks | grep -q VOL1; then fail "ASM disk 'VOL1' not exist." fi if ! /etc/init.d/oracleasm listdisks | grep -q VOL2; then fail "ASM disk 'VOL2' not exist." fi # prerequistes check done ######################################################################## # configure network DHCP/static IP ovm_configure_network ######################################################################## # start db reconfiguration ovm_info "Starting Oracle database reconfiguration." # get configuration from user input configure_ask write_sysconfig if [ "$DO_RELINK" = true ]; then relink_binaries else ovm_log "Relinking skipped." fi # run orainstRootsh and root.sh echo ovm_info "Running orainstRoot.sh and root.sh..." sed -i 's/localconfig reset/localconfig add/g' $ORACLE_HOME/root.sh $ORACLE_INVENTORY/orainstRoot.sh $ORACLE_HOME/root.sh # check/set tmpfs only for 11g if [ "$ORACLE_RNAME" = 'oracle11g' ]; then # check/re-configure tmpfs size check_tmpfs fi # configure and start css # localconfig is hacked to fix bug, see Note:264235.1 if ! $ORACLE_HOME/bin/crsctl check css >/dev/null 2>&1; then echo ovm_info "Starting CSS." $ORACLE_HOME/bin/localconfig add >/dev/null 2>&1 fi # reconfiguration configure_perform # startup init script [ ! -e /etc/init.d/dbstart ] && \ ln -sf "$ORACLE_INIT_PATH" /etc/init.d/dbstart # enable dbstart service if ! chkconfig --list | grep -q dbstart; then ovm_log "Enabling Oracle Database service" chkconfig --add dbstart chkconfig --level 35 dbstart on fi if [ "$ORACLE_DBENABLED" != true ]; then /etc/init.d/dbstart stop fi # set env variables for oracle user cat >> $ORACLE_PROFILE <<-EOF # variables for oracle database environment ORACLE_BASE=$ORACLE_BASE ORACLE_HOME=$ORACLE_HOME ORACLE_SID=orcl SAVE_LLP=$LD_LIBRARY_PATH LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$SAVE_LLP PATH=\$PATH:\$ORACLE_HOME/bin/ export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH EOF echo echo ovm_info "Configuration Completed Successfully." # if get a invalid hostname, then give IP address. host=$(hostname) if [ "$host" = "localhost.localdomain" ]; then host=$(ifconfig eth0 | grep "inet addr" | sed 's/.*inet addr:\([^ ]*\).*/\1/') fi ovm_info "To access the Oracle Application Express go to \"http://$host:$HTTP_PORT/apex\"" press_anykey
This example clean up script is used in the Oracle Database 11g template.
#!/bin/sh # # functions fail () { echo ovm_error "$*" ovm_error "Failed to install Oracle Database." press_anykey exit 1 } case "$ORACLE_TRACE" in T) set -x;; *) ;; esac # source functions from ovm-template-config package . /usr/lib/oraclevm-template/functions . /usr/lib/oraclevm-template/functions # oracle databse env variables . /u01/db-config # display script version if [ "$1" = "-v" -o "$1" = "--version" ]; then echo $VERSION exit 0 fi ######################################################################## # start db reconfiguration ovm_info "Cleanup Oracle database reconfiguration." service network restart /etc/rc.d/init.d/dbstart stop $ORACLE_HOME/bin/localconfig delete chkconfig dbstart off /bin/rm -f /etc/rc.d/init.d/dbstart /bin/rm -rf /etc/ora* /bin/rm -f /etc/sysconfig/$ORACLE_RNAME /bin/rm -rf $ORACLE_HOME/localhost.localdomain_orcl* /bin/rm -rf $ORACLE_BASE/diag/rdbms/orcl if [ "$ORACLE_RNAME" = oracle10g ]; then /bin/rm -f $ORACLE_BASE/admin/orcl/bdump/* $ORACLE_BASE/admin/orcl/udump/* $ORACLE_BASE/admin/orcl/adump/* /bin/rm -f $ORACLE_BASE/admin/+ASM/bdump/* $ORACLE_BASE/admin/+ASM/udump/* fi /bin/rm -f /usr/local/bin/* sed -i '/database env/,$d' /home/oracle/.bash_profile /bin/rm -f /home/oracle/relink.log cat /dev/null > /home/oracle/.bash_history ovm_cleanup_os
This example configuration script is used in the Oracle Database 11g templates.
#!/bin/bash case "$ORACLE_TRACE" in T) set -x ;; *) ;; esac # oms_connection function interactively collects user's input for # OMS hostnam, ip, and port values oms_connection () { local oms_hostname local oms_ip local oms_host local oms_port # ask for oms connection infomation. echo echo "Provide Management Service hostname that the Management Agent will communicate with." while true; do # oms hostname while true; do echo -n "Enter OMS hostname: " read oms_hostname if [ -z $oms_hostname ]; then continue fi break done # if can not resolve the hostname, then require IP address if ! ping -c 3 $oms_hostname >/dev/null 2>&1; then echo "*Can not resolve hostname $oms_hostname." while true; do echo -n "Enter OMS IP address: " read oms_ip if [ -z $oms_ip ]; then continue fi break done fi if [ ! -z $oms_ip ]; then oms_host=$oms_ip else oms_host=$oms_hostname fi # oms port echo -n "Enter OMS port: [4889] " read oms_port if [ -z "$oms_port" ]; then oms_port=4889 fi # test connection if ! nc -w 3 -z $oms_host $oms_port >/dev/null; then echo "*Can NOT connect to $oms_host:$oms_port, please enter OMS information again." oms_ip= continue else OMS_HOST=$oms_hostname OMS_PORT=$oms_port if [ ! -z "$oms_ip" ]; then /bin/cp -f /etc/hosts /etc/hosts.orabak$$ sed -i "/^$oms_ip/d" /etc/hosts echo "$oms_ip $OMS_HOST ${OMS_HOST%%.*}" >> /etc/hosts fi fi break done # enter password echo echo "Provide the Agent Registration password so that the Management Agent can communicate with Secure Management Service." while true; do echo -n "Enter Agent Registration Password: " stty -echo read secure_passwd stty echo echo if [ -z $secure_passwd ]; then continue fi break done SECURE_PASSWD=$secure_passwd } # source functions that are part of standard JeOS template . /usr/lib/oraclevm-template/functions # ovm_configure_network finction is part of JeOS function library # this function interactively collects user's input for the virtual # machine network configuration: IP address, host name, gateway, # netmask, DNS ovm_configure_network # Reconfigure agent echo echo "Reconfiguring Agent..." # Parameters to be reconfigured OMS_HOST= OMS_PORT= SECURE_PASSWD= # Get parameters from user input oms_connection AGENT_HOME=/u01/app/oracle/product/agent10g # replace OMS hostname, port and this hostname in emd.properties sed -i "/^emdWalletSrcUrl/s|%OMS_HOST%|$OMS_HOST|" $AGENT_HOME/sysman/config/emd.properties sed -i "/^emdWalletSrcUrl/s|%OMS_PORT%|$OMS_PORT|" $AGENT_HOME/sysman/config/emd.properties sed -i "/^REPOSITORY_URL/s|%OMS_HOST%|$OMS_HOST|" $AGENT_HOME/sysman/config/emd.properties sed -i "/^REPOSITORY_URL/s|%OMS_PORT%|$OMS_PORT|" $AGENT_HOME/sysman/config/emd.properties sed -i "/^EMD_URL/s|%HOSTNAME%|$(hostname)|" $AGENT_HOME/sysman/config/emd.properties # Reconfigure agent done # Allow ports open for Agent and ssh services. system-config-securitylevel-tui --quiet \ --port=3872 \ --port=ssh # reconfigure and rediscover targets echo su oracle -c "$AGENT_HOME/bin/agentca -f -d -t" # secure agent echo echo "Securing Agent..." su oracle -c "$AGENT_HOME/bin/emctl secure agent $SECURE_PASSWD" # Start agent echo echo "Starting Agent..." /etc/init.d/gcstartup start # create startup script at runlevel 3 5 ln -sf /etc/rc.d/init.d/gcstartup /etc/rc.d/rc3.d/S99gcstartup ln -sf /etc/rc.d/init.d/gcstartup /etc/rc.d/rc5.d/S99gcstartup # set env varible for user 'oracle' cat >> /home/oracle/.bash_profile <<-EOF # oracle env variables AGENT_HOME=$AGENT_HOME ORACLE_HOME=\$AGENT_HOME JAVA_HOME=\$ORACLE_HOME/jdk PATH=\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:\$PATH EM_SECURE_VERBOSE=1 export ORACLE_HOME AGENT_HOME JAVA_HOME EM_SECURE_VERBOSE PATH alias cdo='cd \$ORACLE_HOME' EOF echo echo "Reconfiguration of OEL5.2 and EM Agent 10.2.0.4 Comepleted." press_anykey
This example clean up script is used in the Oracle Enterprise Manager Agent template.
#!/bin/bash AGENT_HOME=/u01/app/oracle/product/agent10g/ # parameters substitution sed -i \ -e '/^REPOSITORY_URL=/s|=.*|=http://%OMS_HOST%:%OMS_PORT%/em/upload|' \ -e '/^emdWalletSrcUrl=/s|=.*|=http://%OMS_HOST%:%OMS_PORT%/em/wallets/emd|' \ -e '/^EMD_URL/s|=.*|=https://%HOSTNAME%:3872/emd/main/|' \ $AGENT_HOME/sysman/config/emd.properties # remove log files rm -f $AGENT_HOME/sysman/log/* # remove old targets data rm -f $AGENT_HOME/sysman/emd/upload/* rm -rf $AGENT_HOME/sysman/emd/state/* rm -f $AGENT_HOME/sysman/emd/lastupld.xml # remove the runlevel startup script rm -f /etc/rc.d/rc3.d/S99gcstartup rm -f /etc/rc.d/rc5.d/S99gcstartup
This example configuration script is used to create the Oracle VM Template Builder guest virtual machine.
#!/bin/bash #set -x TB_VERSION="2.1.0" . /usr/lib/oraclevm-template/functions ovm_configure_network ovm_info "Configuring Oracle VM Template Builder" TB_HOME=/var/www/html/ovmtb SCRIPTS_HOME=$TB_HOME/scripts ovm_info "Initializing database." cd $TB_HOME python manage.py syncdb #chmod a+w $TB_HOME/db/ovmtb.db # start ovmtb daemon #service ovmtb start # init, change sites domain name export PYTHONPATH=/var/www/html export DJANGO_SETTINGS_MODULE=ovmtb.settings cd $SCRIPTS_HOME ovm_log "Changing site name" python ovmtb-init.py -n $(hostname) -d $(hostname) ovm_log "Restarting httpd" service httpd restart service ovmtb restart # open httpd and sshd port for firewall system-config-securitylevel-tui --quiet \ --port=http \ --port=ssh echo ovm_info "Oracle VM Template Builder $TB_VERSION configuration completed." site=$(hostname) # if get a invalid hostname, then give IP address. if [ "$site" = "localhost.localdomain" ]; then site=$(ifconfig eth0|grep "inet addr" | sed 's/.*inet addr:\([^ ]*\).*/\1/') fi ovm_info "Please go to http://$site/ovmtb" press_anykey