帮我写一个自动化部署Oracle数据库脚本
时间: 2024-04-30 19:24:27 浏览: 213
oracle数据库自动化部署shell脚本
好的,以下是一个简单的自动化部署Oracle数据库脚本,供您参考:
```bash
#!/bin/bash
# 设置环境变量
export ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
# 检查是否已经安装Oracle客户端
if ! rpm -qa | grep -qw oracle-instantclient12.2-basic; then
echo "请先安装Oracle客户端"
exit 1
fi
# 创建数据库目录
mkdir -p /u01/app/oracle/oradata
chown -R oracle:oinstall /u01/app/oracle
# 解压Oracle安装文件
unzip /path/to/oracle-12.2.0.1.0.zip -d /tmp
# 进入Oracle安装目录
cd /tmp/database
# 执行安装
./runInstaller -ignorePrereq -waitforcompletion -silent \
-responseFile /path/to/response/db_install.rsp \
oracle.install.option=INSTALL_DB_SWONLY \
ORACLE_HOSTNAME=oracle-server.example.com \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/u01/app/oraInventory \
SELECTED_LANGUAGES=en,en_GB,zh_CN,zh_TW,ja \
ORACLE_HOME=$ORACLE_HOME \
ORACLE_BASE=/u01/app/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.OSDBA_GROUP=dba \
oracle.install.db.OSOPER_GROUP=dba \
oracle.install.db.OSBACKUPDBA_GROUP=dba \
oracle.install.db.OSDGDBA_GROUP=dba \
oracle.install.db.OSKMDBA_GROUP=dba \
oracle.install.db.OSRACDBA_GROUP=dba \
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \
DECLINE_SECURITY_UPDATES=true
# 配置监听器
cp /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora.bak
echo "LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle-server.example.com)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl.example.com)
(ORACLE_HOME = /u01/app/oracle/product/12.2.0/dbhome_1)
(SID_NAME = orcl)
)
)
ADR_BASE_LISTENER = /u01/app/oracle" > /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
# 启动监听器
lsnrctl start
# 创建数据库
dbca -silent -createDatabase \
-templateName General_Purpose.dbc \
-gdbname orcl.example.com -sid orcl \
-sysPassword syspassword123 \
-systemPassword systempassword123 \
-createAsContainerDatabase true \
-numberOfPDBs 1 \
-pdbName pdb1 \
-pdbAdminPassword pdbpassword123 \
-databaseType MULTIPURPOSE \
-automaticMemoryManagement false \
-totalMemory 2048 \
-storageType FS \
-characterSet AL32UTF8 \
-nationalCharacterSet AL16UTF16 \
-recoveryAreaDestination /u01/app/oracle/fast_recovery_area \
-redoLogFileSize 50 \
-emConfiguration NONE
# 启动数据库
sqlplus / as sysdba << EOF
startup;
exit;
EOF
echo "Oracle数据库部署完成"
```
请注意,此脚本仅供参考,您需要根据实际情况进行修改和调整。同时,为了保证安全性和可靠性,请在测试环境中先进行测试,并在生产环境中谨慎使用。
阅读全文