?一、环境准备
1. CentOS7 64位最小化安装2核4G内存30G磁盘
2. ?JDK8 64位 Linux版安装包
jdk-8u231-linux-x64.tar.gz
3. Oracle 11gR2 64位 Linux版安装包
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
以上安装包用ftp工具root用户上传/root路径。一下均使用root用户执行。
1.1 安装jdk
系统非最小化安装可能需卸载openjdk(可根据 java -version 查看是否已安装openjdk),具体卸载操作请百度。
# 解压JDK安装包
tar -zxvf /root/jdk-8u231-linux-x64.tar.gz -C /usr/share/
# 配置环境变量
cat <<EOF>>/etc/profile
export JAVA_HOME=/usr/share/jdk1.8.0_231
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF
# 使环境变量生效
source /etc/profile
1.2 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
1.3 设置swap
swap区是2倍内存大小
## 设置swap swap区是2倍内存大小
swapoff -a
dd if=/dev/zero of=/home/swap bs=1024 count=8192000
/sbin/mkswap /home/swap
/sbin/swapon /home/swap
# 设置swap永久生效
cat <<EOF>>/etc/fstab
/home/swap swap swap defaults 0 0
EOF
1.4 安装依赖包
yum install -y libnsl make zip bc ?binutils ?compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel ?net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline* psmisc
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
rpm -hvi compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
二、安装Oracle
2.1 添加用户组及用户及设置用户密码
## 添加用户组及用户及设置用户密码
groupadd -g 502 oinstall
groupadd -g 503 dba
groupadd -g 504 oper
groupadd -g 505 asmadmin
useradd -u 502 -g oinstall -G oinstall,dba,asmadmin,oper -s /bin/bash -m oracle
passwd oracle <<EOF
oracle
oracle
EOF
2.2 修改操作系统配置
cat <<EOF>>/etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft nproc 2047
oracle hard nproc 16384
oracle hard memlock 134217728
oracle soft memlock 134217728
EOF
2.3 解压Oracle数据库安装包并赋权
unzip /root/linux.x64_11gR2_database_1of2.zip -d /home/oracle
unzip /root/linux.x64_11gR2_database_2of2.zip -d /home/oracle
chown oracle:oinstall /home/oracle/database/
2.4 修改Oracle用户环境变量
cat <<EOF>>/home/oracle/.bash_profile
export ORACLE_BASE=/home/oracle/app/oracle11g
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export NLS_LANG=.AL32UTF8
export PATH=\${PATH}:\${ORACLE_HOME}/bin/:\$ORACLE_HOME/lib64
EOF
# 使环境变量生效
source /home/oracle/.bash_profile
2.5 创建Oracle安装目录
mkdir -p /home/oracle/app/oracle11g/
chown -R oracle:oinstall /home/oracle/app
2.6 复制配置文件模板并编辑配置文件
cp /home/oracle/database/response/db_install.rsp /home/oracle
chown oracle:oinstall /home/oracle/db_install.rsp
sed -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_AND_CONFIG/' /home/oracle/db_install.rsp
sed -i 's|ORACLE_HOSTNAME=|ORACLE_HOSTNAME=localhost|' /home/oracle/db_install.rsp
sed -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/' /home/oracle/db_install.rsp
sed -i 's|INVENTORY_LOCATION=|INVENTORY_LOCATION=/home/oracle/app/oraInventory|' /home/oracle/db_install.rsp
sed -i 's/SELECTED_LANGUAGES=/SELECTED_LANGUAGES=en,zh_CN/' /home/oracle/db_install.rsp
sed -i 's|ORACLE_HOME=|ORACLE_HOME=/home/oracle/app/oracle11g/product/11.2.0/dbhome_1|' /home/oracle/db_install.rsp
sed -i 's|ORACLE_BASE=|ORACLE_BASE=/home/oracle/app/oracle11g|' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.DBA_GROUP=/oracle.install.db.DBA_GROUP=dba/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.OPER_GROUP=/oracle.install.db.OPER_GROUP=oper/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.type=/oracle.install.db.config.starterdb.type=GENERAL_PURPOSE/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.globalDBName=/oracle.install.db.config.starterdb.globalDBName=orcl/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.SID=/oracle.install.db.config.starterdb.SID=orcl/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.memoryLimit=/oracle.install.db.config.starterdb.memoryLimit=1024/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.password.ALL=/oracle.install.db.config.starterdb.password.ALL=Oracle#123456/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.dbcontrol.emailAddress=/oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.storageType=/oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE/' /home/oracle/db_install.rsp
sed -i 's|oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=|oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/app/oracle11g/oradata|' /home/oracle/db_install.rsp
sed -i 's|oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=|oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/app/oracle11g/fast_recovery_area|' /home/oracle/db_install.rsp
sed -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/' /home/oracle/db_install.rsp
2.7 执行安装
su - oracle -c "/home/oracle/database/runInstaller -silent -responseFile /home/oracle/db_install.rsp -ignorePrereq"
接下来,就是默默的等待Oracle自行安装了,等待一段时间后,如果输出如下信息,则表明Oracle数据库已经安装成功。
The following configuration scripts need to be executed as the "root" user.?
?#!/bin/sh?
?#Root scripts to run
/home/oracle/app/oraInventory/orainstRoot.sh
/home/oracle/app/oracle11g/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:
?? ? 1. Open a terminal window?
?? ? 2. Log in as "root"?
?? ? 3. Run the scripts?
?? ? 4. Return to this window and hit "Enter" key to continue?
Configuration assistants have not been run. This can happen for following reasons - either root.sh is to be run before config or Oracle Universal Installer was invoked with the -noConfig option.
"/home/oracle/app/oracle11g/product/11.2.0/dbhome_1/cfgtoollogs/configToolAllCommands" script contains all commands to be executed by the configuration assistants. This file may be used to run the configuration assistants outside of OUI. Note that you may have to update this script with passwords (if any) before executing the same.
Successfully Setup Software.
输入回车键,完成命令。
2.8 执行Oracle安装生成脚本
根据上一步完成信息提示,执行以下两行命令:
## 执行Oracle安装生成脚本
sudo /home/oracle/app/oraInventory/orainstRoot.sh
sudo /home/oracle/app/oracle11g/product/11.2.0/dbhome_1/root.sh
三、验证安装结果
操作用户oracle,使用dba权限连接Oralce
sqlplus / as sysdba
四、设置Oracle开机自启
su - oracle -c "sed -i 's|ORACLE_HOME_LISTNER=\$1|ORACLE_HOME_LISTNER=\$ORACLE_HOME|' \$ORACLE_HOME/bin/dbstart"
su - oracle -c "sed -i 's|ORACLE_HOME_LISTNER=\$1|ORACLE_HOME_LISTNER=\$ORACLE_HOME|' \$ORACLE_HOME/bin/dbshut"
sed -i 's/dbhome_1:N/dbhome_1:Y/' /etc/oratab
cat <<EOF>>/etc/rc.d/init.d/oracle
#!/bin/bash
# chkconfig: 2345 10 10
# oracle: Start/Stop Oracle Database 11g R2
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/home/oracle/app/oracle11g/product/11.2.0/dbhome_1
ORACLE_USER=oracle
case "\$1" in
'start')
if [ -f \$LOCKFILE ]; then
? ? ? echo \$0 already running.
? ? ? exit 1
? ?fi
? ?echo -n $"Starting Oracle Database:"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/lsnrctl start"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/dbstart \$ORACLE_HOME"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/emctl start dbconsole"
? ?touch \$LOCKFILE
? ?;;
'stop')
? ?if [ ! -f \$LOCKFILE ]; then
? ? ? echo \$0 already stopping.
? ? ? exit 1
? ?fi
? ?echo -n $"Stopping Oracle Database:"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/lsnrctl stop"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/dbshut"
? ?su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/emctl stop dbconsole"
? ?rm -f $LOCKFILE
? ?;;
'restart')
? ?\$0 stop
? ?\$0 start
? ?;;
'status')
? ?if [ -f \$LOCKFILE ]; then
? ? ? echo \$0 started.
? ? ? else
? ? ? echo \$0 stopped.
? ?fi
? ?;;
*)
? ?echo "Usage: \$0 [start|stop|status]"
? ?exit 1
esac
exit 0
EOF
chmod 755 /etc/init.d/oracle
sudo chkconfig oracle on
五、自动安装脚本
完成环境准备,使用 vim?autoInstallOracle.sh 命令编辑安装脚本,脚本如下:
#!/bin/sh
## 安装JDK
# 解压JDK安装包
tar -zxvf /root/jdk-8u231-linux-x64.tar.gz -C /usr/share/
# 配置环境变量
cat <<EOF>>/etc/profile
export JAVA_HOME=/usr/share/jdk1.8.0_231
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF
# 使环境变量生效
source /etc/profile
# 删除安装包
sudo rm -rf /root/jdk-8u231-linux-x64.tar.gz
## 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
## 设置swap swap区是2倍内存大小
swapoff -a
dd if=/dev/zero of=/home/swap bs=1024 count=8192000
/sbin/mkswap /home/swap
/sbin/swapon /home/swap
# 设置swap永久生效
cat <<EOF>>/etc/fstab
/home/swap swap swap defaults 0 0
EOF
## 安装依赖包
installyum() {
if ! rpm -qa|grep -q "^$1"
then
yum install -y $1 --skip-broken
fi
}
for p in libnsl make zip bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline* psmisc;do installyum $p;done
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
rpm -hvi compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
## 添加用户组及用户及设置用户密码
groupadd -g 502 oinstall
groupadd -g 503 dba
groupadd -g 504 oper
groupadd -g 505 asmadmin
useradd -u 502 -g oinstall -G oinstall,dba,asmadmin,oper -s /bin/bash -m oracle
passwd oracle <<EOF
oracle
oracle
EOF
## 修改操作系统配置
cat <<EOF>>/etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft nproc 2047
oracle hard nproc 16384
oracle hard memlock 134217728
oracle soft memlock 134217728
EOF
## 解压Oracle数据库安装包并赋权
unzip /root/linux.x64_11gR2_database_1of2.zip -d /home/oracle
unzip /root/linux.x64_11gR2_database_2of2.zip -d /home/oracle
chown oracle:oinstall /home/oracle/database/
## 修改Oracle用户环境变量
cat <<EOF>>/home/oracle/.bash_profile
export ORACLE_BASE=/home/oracle/app/oracle11g
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export NLS_LANG=.AL32UTF8
export PATH=\${PATH}:\${ORACLE_HOME}/bin/:\$ORACLE_HOME/lib64
EOF
# 使环境变量生效
source /home/oracle/.bash_profile
## 创建Oracle安装目录
mkdir -p /home/oracle/app/oracle11g/
chown -R oracle:oinstall /home/oracle/app
## 复制配置文件模板并编辑配置文件
cp /home/oracle/database/response/db_install.rsp /home/oracle
chown oracle:oinstall /home/oracle/db_install.rsp
sed -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_AND_CONFIG/' /home/oracle/db_install.rsp
sed -i 's|ORACLE_HOSTNAME=|ORACLE_HOSTNAME=localhost|' /home/oracle/db_install.rsp
sed -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/' /home/oracle/db_install.rsp
sed -i 's|INVENTORY_LOCATION=|INVENTORY_LOCATION=/home/oracle/app/oraInventory|' /home/oracle/db_install.rsp
sed -i 's/SELECTED_LANGUAGES=/SELECTED_LANGUAGES=en,zh_CN/' /home/oracle/db_install.rsp
sed -i 's|ORACLE_HOME=|ORACLE_HOME=/home/oracle/app/oracle11g/product/11.2.0/dbhome_1|' /home/oracle/db_install.rsp
sed -i 's|ORACLE_BASE=|ORACLE_BASE=/home/oracle/app/oracle11g|' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.DBA_GROUP=/oracle.install.db.DBA_GROUP=dba/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.OPER_GROUP=/oracle.install.db.OPER_GROUP=oper/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.type=/oracle.install.db.config.starterdb.type=GENERAL_PURPOSE/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.globalDBName=/oracle.install.db.config.starterdb.globalDBName=orcl/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.SID=/oracle.install.db.config.starterdb.SID=orcl/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.memoryLimit=/oracle.install.db.config.starterdb.memoryLimit=1024/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.password.ALL=/oracle.install.db.config.starterdb.password.ALL=Oracle#123456/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.dbcontrol.emailAddress=/oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com/' /home/oracle/db_install.rsp
sed -i 's/oracle.install.db.config.starterdb.storageType=/oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE/' /home/oracle/db_install.rsp
sed -i 's|oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=|oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/app/oracle11g/oradata|' /home/oracle/db_install.rsp
sed -i 's|oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=|oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/app/oracle11g/fast_recovery_area|' /home/oracle/db_install.rsp
sed -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/' /home/oracle/db_install.rsp
## 执行安装
su - oracle -c "/home/oracle/database/runInstaller -silent -responseFile /home/oracle/db_install.rsp -ignorePrereq 1>/home/oracle/installOracle.log 2>&1"
## 监听安装结果
while true; do
cat /home/oracle/installOracle.log | grep sh
if [[ $? == 0 ]];then
netstat -anptu | grep 1521
if [[ $? == 0 ]]; then
echo "Successfully Setup Software"
break
fi
fi
done
## 执行Oracle安装生成脚本
sudo /home/oracle/app/oraInventory/orainstRoot.sh
sudo /home/oracle/app/oracle11g/product/11.2.0/dbhome_1/root.sh
# 删除Oracle安装包
sudo rm -rf unzip /root/linux.x64_11gR2_database_1of2.zip
sudo rm -rf unzip /root/linux.x64_11gR2_database_2of2.zip
## 配置开机启动
su - oracle -c "sed -i 's|ORACLE_HOME_LISTNER=\$1|ORACLE_HOME_LISTNER=\$ORACLE_HOME|' \$ORACLE_HOME/bin/dbstart"
su - oracle -c "sed -i 's|ORACLE_HOME_LISTNER=\$1|ORACLE_HOME_LISTNER=\$ORACLE_HOME|' \$ORACLE_HOME/bin/dbshut"
sed -i 's/dbhome_1:N/dbhome_1:Y/' /etc/oratab
cat <<EOF>>/etc/rc.d/init.d/oracle
#!/bin/bash
# chkconfig: 2345 10 10
# oracle: Start/Stop Oracle Database 11g R2
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/home/oracle/app/oracle11g/product/11.2.0/dbhome_1
ORACLE_USER=oracle
case "\$1" in
'start')
if [ -f \$LOCKFILE ]; then
echo \$0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/lsnrctl start"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/dbstart \$ORACLE_HOME"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/emctl start dbconsole"
touch \$LOCKFILE
;;
'stop')
if [ ! -f \$LOCKFILE ]; then
echo \$0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/lsnrctl stop"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/dbshut"
su - \$ORACLE_USER -c "\$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
'restart')
\$0 stop
\$0 start
;;
'status')
if [ -f \$LOCKFILE ]; then
echo \$0 started.
else
echo \$0 stopped.
fi
;;
*)
echo "Usage: \$0 [start|stop|status]"
exit 1
esac
exit 0
EOF
chmod 755 /etc/init.d/oracle
sudo chkconfig oracle on
执行运行脚本命令:source autoInstallOracle.sh,终端显示安装过程,等待安装结束即可。
|