CENTOS7静默安装ORACLE11G及数据泵迁移

202124江苏淮安特钢

CENTOS7静默安装ORACLE11G及数据泵迁移

作者:查小广(北京红河谷时代信息技术有限公司)

 

检化验系统LIMS 数据库迁移

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

lims数据库oracle:192.168.20.6/orcl  管理员密码 zhh:952260  应用:hglims  magpie

 

 

系统版本:Centos X64 7 (3.10.0-1160.11.1.el7.x86_64)

系统配置:8c,16G

 

千万不要使用其他版本,会有一堆奇奇怪怪的问题,使用centos7或者redhat7就好

 

迁移前虚拟机ip为192.168.20.4

迁移前老数据库地址为192.168.20.6

 

配置hostname为LIMSDBSVR2021

        hostnamectl set-hostname oracledb

        echo "127.0.0.1     oracledb" >> /etc/hosts

 

关闭selinux

        sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config 

        setenforce 0

 

检查与安装软件依赖环境

        yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel

        rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel | grep "not installed"

 

创建用户和安装组,设置密码

        groupadd oinstall

        groupadd dba

        useradd -g oinstall -G dba oracle

        passwd oracle

 

        输入密码

 

配置内核参数和资源限制

        在/etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能

        fs.aio-max-nr = 1048576

        fs.file-max = 6815744

        kernel.shmall = 2097152

        kernel.shmmax = 536870912

        kernel.shmmni = 4096

        kernel.sem = 250 32000 100 128

        net.ipv4.ip_local_port_range = 9000 65500

        net.core.rmem_default = 262144

        net.core.rmem_max = 4194304

        net.core.wmem_default = 262144

        net.core.wmem_max = 1048576

       

        使内核参数生效

        sysctl -p

       

        在/etc/security/limits.conf中添加如下参数

        oracle              soft    nproc   2047

        oracle              hard    nproc   16384

        oracle              soft    nofile  1024

        oracle              hard    nofile  65536

       

        在/etc/pam.d/login文件中,添加下面内容

        session required /lib64/security/pam_limits.so

        session required pam_limits.so

 

        /etc/profile 文件中添加如下内容

        if [ $USER = "oracle" ]; then

           if [ $SHELL = "/bin/ksh" ]; then

                    ulimit -p 16384

                    ulimit -n 65536

                 else

                    ulimit -u 16384 -n 65536

           fi

        fi

       

        使用/etc/profile文件生效

        source /etc/profile

       

        禁用使用Transparent HugePages,查看是否启用 如果显示 [always]说明启用了

        cat /sys/kernel/mm/transparent_hugepage/enabled

        禁用Transparent HugePages,在/etc/grub.conf添加如下内容

        echo never > /sys/kernel/mm/transparent_hugepage/enabled

       

挂盘分区等操作

        使用fdisk -l查看虚拟机的硬盘,找到类似 Disk /dev/vdb: 1099.5 GB 字样

        使用fdisk /dev/vdb 命令进行分区,输入n(创建)、p(主分区)、然后默认执行,最后 w 完成     

        格式化分区 mkfs.xfs -f /dev/vdb1

        挂载分区 mount -t xfs /dev/vdb1 /data     

        在/etc/fstab 中加入一行,让系统开机自动挂载

        UUID=8e741650-c98c-4d42-9381-959185885c95 /data                                      xfs     defaults        0 0

        (uuid是 blkid /dev/vdb1 查询来的)

       

创建oracle安装目录

        mkdir -p /data/app/

        chown -R oracle:oinstall /data/app/

        chmod -R 775 /data/app/

       

配置oracle用户环境变量

        直接在root用户编辑:/home/oracle/.bash_profile 添加下面内容(具体值根据实际情况修改)

        export ORACLE_HOSTNAME=LIMSDBSVR2021

        export ORACLE_BASE=/data/app/oracle

        export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/

        export ORACLE_SID=ORCL

        export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH

        export LC_ALL="en_US"

        export LANG="en_US"

        export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"

        export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

 

准备oracle 11g安装文件,确保和源库保持一致版本

        下载后上传到 /data 目录

        解压下载好的两个Oracle数据库文件

        unzip -q linux.x64_11gR2_database_1of2.zip -d /data

        unzip -q linux.x64_11gR2_database_2of2.zip -d /data

        复制与创建响应文件

        mkdir -p /data/etc

        cp /data/database/response/* /data/etc/

       

        修改/data/etc/db_install.rsp修改以下变量的值,注意是按键值修改,不要整体覆盖替换

        oracle.install.option=INSTALL_DB_SWONLY

        DECLINE_SECURITY_UPDATES=true

        UNIX_GROUP_NAME=oinstall

        INVENTORY_LOCATION=/data/app/oracle/inventory

        SELECTED_LANGUAGES=en,zh_CN

        ORACLE_HOSTNAME=oracledb

        ORACLE_HOME=/data/app/oracle/product/11.2.0

        ORACLE_BASE=/data/app/oracle

        oracle.install.db.InstallEdition=EE

        oracle.install.db.isCustomInstall=true

        oracle.install.db.DBA_GROUP=dba

        oracle.install.db.OPER_GROUP=dba

 

开始安装(一定要切换到oracle用户,中间横杠有空格)

        su - oracle

        cd /data/database

        ./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq

        安装需要很长时间(5-10分钟),安装完成后有如下提示,如果有类似如下提示,说明安装完成

       

        The following configuration scripts need to be executed as the "root" user.

        #!/bin/sh

        #Root scripts to run

 

        /data/app/oraInventory/orainstRoot.sh

        /data/app/oracle/product/11.2.0/db_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

 

        Successfully Setup Software.

       

使用root用户执行脚本(切记是root用户)

        su - root

        sh /data/app/oracle/inventory/orainstRoot.sh

        sh /data/app/oracle/product/11.2.0/root.sh

 

配置监听程序(不需要修改响应文件)

        su - oracle

        netca /silent /responsefile /data/etc/netca.rsp

       

        会得到如下结果:

        Parsing command line arguments:

    Parameter "silent" = true

    Parameter "responsefile" = /data/etc/netca.rsp

        Done parsing command line arguments.

        Oracle Net Services Configuration:

        Profile configuration complete.

        Oracle Net Listener Startup:

                 Running Listener Control:

                   /data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER

                 Listener Control complete.

                 Listener started successfully.

        Listener configuration complete.

        Oracle Net Services configuration successful. The exit code is 0

       

        可以检查一下监听

        netstat -tnpl | grep 1521

       

静默创建数据库

      需要编辑应答文件/data/etc/dbca.rsp (这个时候要去查老数据库,保持一致为妥)

        [GENERAL]

        RESPONSEFILE_VERSION = "11.2.0"

        OPERATION_TYPE = "createDatabase"

        [CREATEDATABASE]

        GDBNAME = "orcl"

        SID = "orcl"

        SYSPASSWORD = "zhh:952660"

        SYSTEMPASSWORD = "zhh:952660"

        SYSMANPASSWORD = "zhh:952660"

        DBSNMPPASSWORD = "zhh:952660"

        DATAFILEDESTINATION =/data/app/oracle/oradata

   RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area

        CHARACTERSET = "ZHS16GBK"

        TOTALMEMORY = "12288"

       

        执行静默建库(注意切换到oracle用户)

        su - oracle

        dbca -silent -responseFile /data/etc/dbca.rsp

       

        执行有点慢(1-2分钟),如果很快可能是出错了

        Copying database files

        1% complete

        3% complete

        11% complete

        18% complete

        26% complete

        37% complete

        Creating and starting Oracle instance

        40% complete

        45% complete

        50% complete

        55% complete

        56% complete

        60% complete

        62% complete

        Completing Database Creation

        66% complete

        70% complete

        73% complete

        85% complete

        96% complete

        100% complete

        Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.

 

        查看进程 如果看到一堆oracle进程就成功了

        ps -ef | grep ora_ | grep -v grep

       

        结果:

        oracle   19304     1  0 18:33 ?        00:00:00 ora_pmon_orcl

        oracle   19306     1  0 18:33 ?        00:00:00 ora_vktm_orcl

        oracle   19310     1  0 18:33 ?        00:00:00 ora_gen0_orcl

        oracle   19312     1  0 18:33 ?        00:00:00 ora_diag_orcl

        oracle   19314     1  0 18:33 ?        00:00:00 ora_dbrm_orcl

        oracle   19316     1  0 18:33 ?        00:00:00 ora_psp0_orcl

        oracle   19318     1  0 18:33 ?        00:00:00 ora_dia0_orcl

        oracle   19320     1  0 18:33 ?        00:00:00 ora_mman_orcl

        oracle   19322     1  0 18:33 ?        00:00:00 ora_dbw0_orcl

        oracle   19324     1  0 18:33 ?        00:00:00 ora_lgwr_orcl

        oracle   19326     1  0 18:33 ?        00:00:00 ora_ckpt_orcl

        oracle   19328     1  0 18:33 ?        00:00:00 ora_smon_orcl

        oracle   19330     1  0 18:33 ?        00:00:00 ora_reco_orcl

        oracle   19332     1  0 18:33 ?        00:00:00 ora_mmon_orcl

        oracle   19334     1  0 18:33 ?        00:00:00 ora_mmnl_orcl

        oracle   19336     1  0 18:33 ?        00:00:00 ora_d000_orcl

        oracle   19338     1  0 18:33 ?        00:00:00 ora_s000_orcl

        oracle   19361     1  0 18:34 ?        00:00:00 ora_qmnc_orcl

        oracle   19376     1  0 18:34 ?        00:00:00 ora_cjq0_orcl

        oracle   19396     1  0 18:34 ?        00:00:00 ora_q000_orcl

        oracle   19398     1  0 18:34 ?        00:00:00 ora_q001_orcl

 

 

        查看监听状态

        lsnrctl status

       

        结果:

        LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 04-FEB-2021 16:50:48

        Copyright (c) 1991, 2009, Oracle.  All rights reserved.

        Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))

        STATUS of the LISTENER

        ------------------------

        Alias                     LISTENER

        Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

        Start Date                03-FEB-2021 23:29:06

        Uptime                    0 days 17 hr. 21 min. 42 sec

        Trace Level               off

        Security                  ON: Local OS Authentication

        SNMP                      OFF

        Listener Parameter File   /data/app/oracle/product/11.2.0/network/admin/listener.ora

        Listener Log File         /data/app/oracle/diag/tnslsnr/limsdbsvr2021/listener/alert/log.xml

        Listening Endpoints Summary...

          (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

          (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=limsdbsvr2021)(PORT=1521)))

        Services Summary...

        Service "ORCL" has 1 instance(s).

         Instance "ORCL", status READY, has 1 handler(s) for this service...

        Service "orclXDB" has 1 instance(s).

         Instance "ORCL", status READY, has 1 handler(s) for this service...

        The command completed successfully

       

至此数据库就安装成功了,设置Oracle开机启动

        修改/data/app/oracle/product/11.2.0/bin/dbstart         改 ORACLE_HOME_LISTNER=$1 为 ORACLE_HOME_LISTNER=$ORACLE_HOME

        修改/data/app/oracle/product/11.2.0/bin/dbshut               改 ORACLE_HOME_LISTNER=$1 为 ORACLE_HOME_LISTNER=$ORACLE_HOME

        修改vi /etc/oratab             -->  orcl:/data/app/oracle/product/11.2.0:Y

 

        新建文件/etc/rc.d/init.d/oracle

        #! /bin/bash

        # oracle: Start/Stop Oracle Database 11g R2

        #

        # chkconfig: 345 90 10

        # description: The Oracle Database is an Object-Relational Database Management System.

        #

        # processname: oracle

        . /etc/rc.d/init.d/functions

        LOCKFILE=/var/lock/subsys/oracle

        ORACLE_HOME=/data/app/oracle/product/11.2.0

        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

       

        给/etc/init.d/oracle添加执行权限

        chmod +x /etc/init.d/oracle

       

        开机启动oracle

        chkconfig oracle on

       

        给启动文件加权限

        cd /data/app/oracle/product/11.2.0/bin/

        chmod 6751 oracle

        cd /var/tmp

        chown -R oracle:oinstall .oracle

 

        防火墙配置放开Oracle的端口,或者直接关闭防火墙

        firewall-cmd --zone=public --add-port=1521/tcp --permanent

        firewall-cmd --reload

                

在新的服务器做迁移准备工作:

 

        1、调整redo日志大小为1024MB

        2、调整oracle进程数和连接数为800/1000

        3、修改oracle自动归档并设置归档日志目录为/data/app/oracle/oradata/orcl/archivelog/

 

        重新启动数据库

 

 

查询到老数据库的用户、表空间、字符集 HGLIMS  TS_LIMS 在新数据库创建用户和表空间

 

        create tablespace TS_LIMS datafile '/data/app/oracle/oradata/orcl/data_ts_lims.dbf' size 1024m autoextend on next 50M maxsize unlimited;

        create tablespace TS_MES datafile '/data/app/oracle/oradata/orcl/data_ts_mes.dbf' size 1024m autoextend on next 50M maxsize unlimited;

 

        create user hglims identified by "magpie" default tablespace TS_LIMS;

        grant connect,dba,resource to hglims;

        grant unlimited tablespace to hglims;

 

在测试导入的过程中,发现如下错误,提前解决,以便正式迁移的时候不影响

        ORA-01917: user or role 'HGMES' does not exist

        ORA-01917: user or role 'DANIELI' does not exist 

        ORA-01917: user or role 'QMS' does not exist

        ORA-01917: user or role 'MES_BKD' does not exist

        ORA-01917: user or role 'FR' does not exist  

        ORA-04052: error occurred when looking up remote object JSERP.JYD@LIMS_ERP

        ORA-04052: error occurred when looking up remote object JSERP.U_DJSTCL@LIMS_ERP 

 

        找到老数据库关于这些user和dblink的ddl语句,在新库重建即可

 

 

在老数据库上面准备导出动作(使用防火墙关闭1521端口对外,防止数据库变动)

        查询逻辑导出目录

                select * from dba_directories;

                 查询到有可以使用的 EXPDPBAK f:\expdpbak

                 如果没有可以创建

                create directory EXPDPBAK as 'f:\expdpbak';

                 grant read,write on directory EXPDPBAK to hglims;

 

        使用以下命令导出

                 expdp hglims/magpie@orcl schemas=hglims dumpfile=lims_20210204_1600.dmp DIRECTORY=EXPDPBAK

                 dumpfile可以自己改名,导出大约8分钟,文件存放在f:\expdpbak

                

        上传dmp文件到新服务器192.168.20.4

                 使用xtp工具即可,上传到/data/dump, 切记文件要归属与oracle用户,注意linux大小写

                

        修改老数据库地址为 192.168.20.8

 

在新数据库准备导入工作

        查询逻辑导出目录

        select * from dba_directories;

        如果没有可以创建

        create directory EXPDPBAK as '/data/dump';

        grant read,write on directory EXPDPBAK to hglims;

       

        使用以下命令导入

                 impdp hglims/magpie@orcl directory=EXPDPBAK dumpfile=LIMS_20210204_1600.DMP schemas=hglims

                 dumpfile和之前导出的对应,注意文件名大小写,导入大约5分钟,文件存放在/data/dump

 

导入完成后,修改新数据库地址为192.168.20.6,重启网络

        ifconfig eth0 192.168.20.6 netmask 255.255.255.0

        systemctl start network

 

测试检化验客户端

完成迁移

 

posted @ 2021-02-04 17:39  龙城叫花鸡  阅读(447)  评论(0编辑  收藏  举报