环境:
VM虚拟机
centos7.0(64bit) 30G硬盘 2G内存
oracle11g(官网下载的) linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip 上传至/u01目录下
实施之前查看hostname(我的默认为oracle),虚拟机网络,关闭防火墙,关闭Selinux
#修改hostname vim /etc/hostname #修改虚拟机网络ONBOOT=yes vim /etc/sysconfig/network-scripts/ifcfg-ens33 #防火墙 systemctl status firewalld //查看状态 systemctl stop firewalld //关闭防火墙 systemctl disable firewalld //禁用 systemctl status firewalld //查看状态 #关闭Selinux //将config文件的SELINUX=enforcing替换为SELINUX=disabled [root@oracle ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config //命令临时生效0:不启用 [root@oracle ~]# setenforce 0 //查看Selinux状态 [root@oracle ~]# /usr/sbin/sestatus -v
步骤(转载):
第一个脚本preinstalloracle.sh,以root用户运行。执行完后需要重启电脑,需要注意看一下hostname是否修改好了
修改红色的部分(虚拟机IP hostname)
#!/bin/bash #以root用户运行 #注意修改第三行的ip为自己的ip地址 echo "192.168.48.129 oracle orcl" >> /etc/hosts cat >> /etc/sysconfig/network <<EOF network=yes hostname=oracle EOF
第二个脚本secinstalloracle.sh,以root用户运行
#!/bin/bash #以root用户运行 #内核参数设置kernel.shmall=2097152其中16G物理内存建议设为4194304类推8G应为2097152 #kernel.shmmax=4294967296一般设置为物理内存的一半,8G:4294967296也可以全部用完8*1024*1024*1024 yum install -y binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc gcc-c++ libaio-devel libaio libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel ksh numactl-devel zip unzip cat >> /etc/sysctl.conf <<EOF fs.file-max = 6815744 fs.aio-max-nr = 1048576 kernel.shmall = 2097152 kernel.shmmax = 4294967296 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 4194304 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 EOF sysctl -p #使配置文件生效 cat >> /etc/security/limits.conf <<EOF oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 EOF cat >> /etc/pam.d/login <<EOF session required /lib/security/pam_limits.so session required pam_limits.so EOF cat >> /etc/profile <<EOF if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi EOF groupadd oinstall groupadd dba useradd -g oinstall -G dba oracle mkdir -p /u01/app/oracle/product/11.2.0/db_1 mkdir -p /u01/app/oracle/oradata mkdir -p /u01/app/oraInventory mkdir -p /u01/app/oracle/fast_recovery_area chown -R oracle:oinstall /u01/app/oracle chown -R oracle:oinstall /u01/app/oraInventory chmod -R 755 /u01/app/oracle chmod -R 755 /u01/app/oraInventory systemctl disable firewalld systemctl stop firewalld setenforce 0 sed -i 's/=enforcing/=disabled/g' /etc/selinux/config mv /u01/linux.x64_11gR2_database_1of2.zip /home/oracle mv /u01/linux.x64_11gR2_database_2of2.zip /home/oracle cp thiinstalloracle.sh /home/oracle/ cp fouinstalloracle.sh /home/oracle/
备注:若执行第二个脚本仍然报缺包的错误,可以用如下方法解决:
1.先修改yum源为阿里 cd /etc/yum.repos.d/ ls #备份 mv CentOS-Base.repo CentOS-Base.repo_bak #下载安装工具 yum -y install wget #下载阿里centos7yum源 wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #更新 cache yum clean all yum makecache 2.使用oracle-rdbms-server-11gR2-preinstall包 cd /etc/yum.repos.d #下载public-yum-ol7.repo wget http://public-yum.oracle.com/public-yum-ol7.repo #导入RPM-GPG-KEY-oracle wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle #安装准备神器,快速配置Oracle安装环境 yum install oracle-rdbms-server-11gR2-preinstall -y
第三个脚本thiinstalloracle.sh,以oracle用户运行,su - oracle,进入到家目录 cd ~ 执行 sh thiinstalloracle.sh
#!/bin/bash #以oracle用户运行,su - oracle cat >> ~/.bash_profile <<EOF ORACLE_BASE=/u01/app/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID=orcl export NLS_LANG=AMERICAN_AMERICA.UTF8 PATH=$PATH:$ORACLE_HOME/bin export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH umask 022 EOF source ~/.bash_profile unzip linux.x64_11gR2_database_1of2.zip unzip linux.x64_11gR2_database_2of2.zip chown -R oracle:oinstall database cd database/response cp db_install.rsp db_install.rsp.bak sed -i "s/^oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/g" db_install.rsp sed -i "s/^ORACLE_HOSTNAME=/ORACLE_HOSTNAME= orcl/g" db_install.rsp sed -i "s/^UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/g" db_install.rsp sed -i "s/^INVENTORY_LOCATION=/INVENTORY_LOCATION=/u01/app/oraInventory/g" db_install.rsp sed -i "s/^SELECTED_LANGUAGES=en/SELECTED_LANGUAGES=en,zh_CN/g" db_install.rsp sed -i "s/^ORACLE_HOME=/ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1/g" db_install.rsp sed -i "s/^ORACLE_BASE=/ORACLE_BASE=/u01/app/oracle/g" db_install.rsp sed -i "s/^oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/g" db_install.rsp sed -i "s/^oracle.install.db.DBA_GROUP=/oracle.install.db.DBA_GROUP=dba/g" db_install.rsp sed -i "s/^oracle.install.db.OPER_GROUP=/oracle.install.db.OPER_GROUP=dba/g" db_install.rsp sed -i "s/^DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/g" db_install.rsp
备注:重启之后,需要每次在oracle用户的家目录 cd ~ 执行 source .bash_profile 才能执行sqlplus这种情况可以,可以将 .bash_profile中的参数写入到.bashrc中即可
ORACLE_BASE=/u01/app/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID=orcl export NLS_LANG=AMERICAN_AMERICA.UTF8 PATH=$PATH:$ORACLE_HOME/bin export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH umask 022
在虚拟机终端
su root
xhost +
su oracle
进入到 cd /home/oracle/database 目录中
./runInstaller -silent -responseFile /home/oracle/database/response/db_install.rsp
若报[INS-13013] 错误,加上-ignorePrereq命令,就可以了
./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /home/oracle/database/response/db_install.rsp
没有异常,不报错的话会在三两分钟后出现使用root用户执行orainstRoot.sh和root.sh的提示
第三脚本执行结果截图,需要等到最后那行提示Successfully Step Software才可以回车,大概需要三四分钟
所以,我们接着另开一个端口,以root用户身份执行
sh /u01/app/oraInventory/orainstRoot.sh sh /u01/app/oracle/product/11.2.0/db_1/root.sh
(静默安装监听器)
第四个脚本fouinstalloracle.sh,以oracle用户运行,执行以下脚本之前需要先检测以下oracle用户环境变量是否设置正确,测试方法输入netc然后tab补全,如果不能自动补全为netca,则需要回到家目录 cd ~ 再次执行source .bash_profile,直到可以自动补全netca和dbca等命令为止
#/bin/bash #以oracle用户运行 netca /silent /responseFile /home/oracle/database/response/netca.rsp #静默方式配置监听 ls $ORACLE_HOME/network/admin/ #正常情况下会自动生成listener.ora sqlnet.ora cd /home/oracle/database/response cp dbca.rsp db sed -i '78s/.*/GDBNAME= "orcl"/' dbca.rsp sed -i '170s/.*/SID = "orcl"/' dbca.rsp sed -i '211s/.*/SYSPASSWORD = "123456"/' dbca.rsp sed -i '221s/.*/SYSTEMPASSWORD = "123456"/' dbca.rsp sed -i '252s/.*/SYSMANPASSWORD = "123456"/' dbca.rsp sed -i '262s/.*/DBSNMPPASSWORD = "123456"/' dbca.rsp sed -i '360s/.*/DATAFILEDESTINATION=/u01/app/oracle/oradata/' dbca.rsp sed -i '370s/.*/RECOVERYAREADESTINATION=/u01/app/oracle/fast_recovery_area/' dbca.rsp sed -i '418s/.*/CHARACTERSET= "ZHS16GBK"/' dbca.rsp sed -i '553s/.*/TOTALMEMORY= "3276"/' dbca.rsp #值设置为物理内存的60% dbca -silent -responseFile /home/oracle/database/response/dbca.rsp #开始静默安装,安装结束后会提示100%,数据库也跟着起来了 ps -ef | grep ora_ | grep -v grep #检测oracle进程 lsnrctl status
最后,我们尝试创建一个用户,从外部进行连接,如果可以正常连接,说明没有问题了
sqlplus / as sysdba #进入数据库 select status from v$instance; #查看数据库运行状态 create user test identified by test; #创建数据库用户,连接时数据库实例名为orcl,用户名test密码test grant connect to test; grant resource to test;
完毕后修改oracle用户密码为oracle
su root
paswd oracle