《Linux 7安装Oracle 11g打怪经历》完成了数据库软件的初始安装,如果要同步复制到多套相同的环境,选择克隆数据库,是个好的选择。
原始数据库
首先,将数据库软件的$ORACLE_HOME路径进行打包,但是要注意,如果使用root打包,会提示错误,
[root@bisal]$ tar zcvf 11g.tar 11.2.0.4
tar: Exiting with failure status due to previous errors
这是因为$ORACLE_HOME/bin/nmb中存在root属主文件,
-rws--x--- 1 root dba 33832 Feb 25 00:02 nmb
改为root打包即可,
[root@bisal]$ 11g.tar
目标数据库
创建用户、用户组,并配置环境变量,
groupadd -g 101 dba
groupadd -g 102 oinstall
useradd -m -u 1001 -g oinstall -G dba -d /home/oracle -s /bin/bash -c "Oracle 11g Software Owner" oracle
还需要创建一些文件夹,并授予权限,
mkdir -p /opt/app/oracle
mkdir -p /u01/app/oracle/product/11.2.0.4
ln -s /opt/app/oracle /u01/app/oracle
chown -R oracle:dba /u01
chown -R oracle:dba /opt/app/oracle
需要一些Package,写了个小脚本,可以直接执行,检查当前系统是否存在这些Package,不存在的yum -y自动进行安装,无需交互,方便快捷,
https://github.com/bisal-liu/oracle/blob/master/install_package_for_oracle11g.sh
配置/etc/sysctl.conf系统参数,
echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "fs.file-max = 6815744" >> /etc/sysctl.conf
echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf
echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf
echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.wmem_max = 1048576" >> /etc/sysctl.conf
sysctl -p
配置/etc/security/limits.conf系统参数,
echo "oracle soft nproc 2047" >> /etc/security/limits.conf
echo "oracle hard nproc 16384" >> /etc/security/limits.conf
echo "oracle soft nofile 65536" >> /etc/security/limits.conf
echo "oracle hard nofile 65536" >> /etc/security/limits.conf
将原始数据库11g.tar,FTP至目标数据库$ORACLE_HOME上级路径进行解压缩,
[oracle@bisal]$ echo $ORACLE_HOM
/u01/app/oracle/product/11.2.0.4
[oracle@bisal]$ pwd
/u01/app/oracle/product
[oracle@bisal]$ tar xvf 11g.tar
进入$ORACLE_HOME/clone/bin路径,执行clone.pl,开始克隆数据库,注意加上-jreLoc指定Oracle JDK的jre,
[oracle@bisal]$ perl clone.pl ORACLE_BASE=$ORACLE_BASE ORACLE_HOME=$ORACLE_HOME
ORACLE_HOME_NAME=OraDb11g_home1 -jreLoc /usr/java/jdk1.7.0_79/jre
./runInstaller
-clone -waitForCompletion "ORACLE_BASE=/u01/app/oracle"
"ORACLE_HOME=/u01/app/oracle/product/11.2.0.4"
"ORACLE_HOME_NAME=OraDb11g_home1" -jreLoc /usr/java/jdk1.7.0_79/jre
-silent -noConfig -nowait
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB. Actual 4095 MB Passed
Preparing
to launch Oracle Universal Installer from
/tmp/OraInstall2020-03-17_12-57-16PM. Please wait ...Oracle Universal
Installer, Version 11.2.0.4.0 Production
Copyright (C) 1999, 2013, Oracle. All rights reserved.
You can find the log of this install session at:
/u01/app/oraInventory/logs/cloneActions2020-03-17_12-57-16PM.log
.................................................................................................... 100% Done.
Installation in progress (Tuesday, March 17, 2020 12:57:22 PM CST)
..............................................................................
78% Done.
Install successful
Linking in progress (Tuesday, March 17, 2020 12:57:24 PM CST)
Link successful
Setup in progress (Tuesday, March 17, 2020 12:57:46 PM CST)
Setup successful
End of install phases.(Tuesday, March 17, 2020 12:58:07 PM CST)
WARNING:A
new inventory has been created in this session. However, it has not yet
been registered as the central inventory of this system.
To register the new inventory please run the script '/u01/app/oraInventory/orainstRoot.sh' with root privileges.
If you do not register the inventory, you may not be able to update or patch the products you installed.
The following configuration scripts need to be executed as the "root" user.
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0.4/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
The cloning of OraDb11g_home1 was successful.
Please check '/u01/app/oraInventory/logs/cloneActions2020-03-17_12-57-16PM.log' for more details.
P.S. Oracle JDK和OpenJDK的区别和联系,可以参考《OpenJDK和Oracle JDK有什么区别和联系?》)
按照提示,使用root,执行这两个脚本,完成克隆数据库的操作,
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0.4/root.sh
概括一下,克隆数据库,需要如下操作,
1.打包原始数据库$ORACLE_HOME文件夹,生成11g.tar。
2.目标数据库中做好准备工作,包括账号、文件夹、系统参数、环境变量等。
3.11g.tar通过FTP目标数据库$ORACLE_HOME上级路径,解压缩11g.tar。
4.执行$ORACLE_HOME/clone/bin/clone.pl。
5.root执行收尾脚本。
当原始和目标数据库服务器环境几乎相同的场景,非常适合使用克隆数据库的方式安装数据库软件,在目标数据库上,消耗的只是一些系统文件链接的时间,安装速度提升,而且如上的操作,其实都可以通过脚本实现自动化,一键克隆安装,不是不可能。
作为技术人员,实现功能的同时,我们应该多考虑下如何通过技术降低工作的难度,降低人的消耗,才可能让我们的工作,更有价值。