精华内容
下载资源
问答
  • redis 集群 每个节点有一主一备 这个“一主一备”是什么意思?
  • 数据库升级需要将线上11.2.0.1升级到11.2.0.4,而且尽量做到少步骤迁移能实时同步数据,所以想到一个方案,已经有了oracle 11.2.0.1的一主一备库的数据库了,现在需要再搭建一个备库s2,而且备库需要11.2.0.4,做成...

     

    数据库升级需要将线上11.2.0.1升级到11.2.0.4,而且尽量做到少步骤迁移能实时同步数据,所以想到一个方案,已经有了oracle 11.2.0.1的一主一备库的数据库了,现在需要再搭建一个备库s2,而且备库需要11.2.0.4,做成一主两备的架构,在s2上升级版本,大概步骤过程如下

     

    (1),先搭建S2,版本为11.2.0.4

    (2),从M1实时同步数据到S2,S2启动到mount状态

    (3),在业务低峰期间,比如凌晨2点,停止应用,断掉业务往数据库里面写

    (4),在S2上做failover操作,将S2从standby切换成主库,S2变成M2

    (5),在新的M2上做upgrade升级操作

    (6),将应用连接到新的主库M2上

    (7),将S1重做成S2,连接M2上。

     

     

    1、修改监听配置文件

    1.1在备库2上配置listener.ora

    # Generated by Oracle configuration tools.

     

    LISTENER =

      (DESCRIPTION_LIST =

        (DESCRIPTION =

          (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.71)(PORT = 1521))

        )

      )

     

     

    SID_LIST_LISTENER =

      (SID_LIST =

        (SID_DESC =

          (SID_NAME = PLSExtProc)

          (ORACLE_HOME = /oracle/app/oracle/product/11.2.0.4/dbhome_1)

          (PROGRAM = extproc)

        )

        (SID_DESC =

          (SID_NAME = powerdes)

          (ORACLE_HOME = /oracle/app/oracle/product/11.2.0.4/dbhome_1)

        )

      )

     

     

    ADR_BASE_LISTENER = /oracle/app/oracle

     

     

    1.2 在备库2上设置tnsnames.ora

             # tnsnames.ora Network Configuration File: /oracle/app/oracle/product/11.2.0.4/dbhome_1/network/admin/tnsnames.ora

             # Generated by Oracle configuration tools.

     

             POWERDES =

               (DESCRIPTION =

                       (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

                       (CONNECT_DATA =

                         (SERVER = DEDICATED)

                         (SERVICE_NAME = powerdes)

                       )

               )

     

     

             PD1 =

               (DESCRIPTION =

                       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.62)(PORT = 1521))

                       (CONNECT_DATA =

                         (SERVER = DEDICATED)

                         (SERVICE_NAME = powerdes)

                       )

               )

              

             PD2 =

               (DESCRIPTION =

                       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.63)(PORT = 1521))

                       (CONNECT_DATA =

                         (SERVER = DEDICATED)

                         (SERVICE_NAME = powerdes)

                       )

               )

     

             PD3 =

               (DESCRIPTION =

                       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.71)(PORT = 1521))

                       (CONNECT_DATA =

                         (SERVER = DEDICATED)

                         (SERVICE_NAME = powerdes)

                       )

               )

     

     

             ADR_BASE_LISTENER = /oracle/app/oracle

     

     

     

    1.3在主库、备库1、添加配置PD3的tns配置

    vim tnsnames.ora

    PD3 =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.71)(PORT = 1521))

        (CONNECT_DATA =

          (SERVER = DEDICATED)

          (SERVICE_NAME = powerdes)

        )

      )

     

     

     

     

    2,设置密码 

    在主库传输备库密码到备库2

    [oracle@hch_test_dbm1_121_62 dbs]$ scp orapwpowerdes 192.168.121.71:/oracle/app/oracle/product/11.2.0.4/dbhome_1/dbs/

    oracle@192.168.121.71's password:

    orapwpowerdes                                                                                                                                                                                                                                100% 2560     2.5KB/s   00:00   

    [oracle@hch_test_dbm1_121_62 dbs]$

     

     

    3,配置参数

    3.1 在主库执行

    搭建dg的主要目的是为了防止主库宕机,备库能够切换为主库,但是当备库切换为主库后,那么客户端tns也要保证和原来的主库一样,一般通俗来讲,需要改变tns配置,如果客户端比多比如应用程序比较多,那么需要改变的更多,特别是有的应用已经嵌入连接方式,一改就要重启应用,那么这样改起来就非常麻烦了。那么针对dns里面2个核心要点:

    (1)是IP地址,

    (2)是oracle_sid;我们可以采用如下的方案,

    (2.a)切换后,修改新主库即是原来的备库的ip地址为主库ip地址

    (2.b)保证备库主库的oracle_sid一致也就是service_name一致。

    # 主库的db_unique_name 为powerdes_m1,备库1的db_unique_name为powerdes_s1 ,备库2的db_unique_name设置成powerdes_s2.

     

    #(1)设置参数

    SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(powerdes_m1,powerdes_s1,powerdes_s2)' SCOPE=BOTH;  

                                                           

    SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_3='SERVICE=PD3 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=powerdes_s2' SCOPE=BOTH;   

     

    SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_3='ENABLE';  

     

    #(2) fal_server 指定为主库即primary的网络服务名,fal_client 指定为备库即standby的网络服务名,通常来说,主库和备库是反过来的,便于主备库的切换。

    SQL> ALTER SYSTEM SET FAL_SERVER='PD2,PD3' SCOPE=BOTH;

    SQL> ALTER SYSTEM SET FAL_CLIENT='PD1'  SCOPE=BOTH;

     

     

    #(3)写入启动参数文件

    SQL> create pfile from spfile;

     

     

     

    3.2 在备库2上执行操作,修改备库启动参数

    (1)创建临时文件

    create pfile='/oracle/p1.ora' from spfile;

     

    (2)添加配置

    vim /oracle/p1.ora

    #DG CONFIG

    *.log_archive_config='dg_config=(powerdes_m1,powerdes_s2)'

    *.log_archive_dest_1='LOCATION=/oracle/app/oracle/flash_recovery_area/archivelog LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=powerdes_s2'

    *.log_archive_dest_3='SERVICE=PD1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=powerdes_m1'

    *.standby_file_management='AUTO'

    *.log_archive_dest_state_1=enable

    *.log_archive_dest_state_3=enable

    *.fal_server=PD1

    *.fal_client=PD3

    *.db_unique_name=powerdes_s2

    *.standby_file_management=auto

     

    (3)然后加入到启动里面

    SQL> create spfile from pfile='/oracle/p1.ora';

     

    File created.

     

    SQL> create pfile from pfile;

    create pfile from pfile

                      *

    ERROR at line 1:

    ORA-00922: missing or invalid option

     

     

    SQL> create pfile from spfile;

     

    File created.

     

    SQL>

     

     

     

    4,开始搭建

    4.1 在备库2上启动到no mount状态

    启动命令:startup nomount

    SQL> startup nomount

    ORACLE instance started.

     

    Total System Global Area 2.0176E+10 bytes

    Fixed Size              2261928 bytes

    Variable Size              3422555224 bytes

    Database Buffers    1.6710E+10 bytes

    Redo Buffers                41463808 bytes

    SQL>

     

     

    4.2 在主库上执行

    同步命令:rlwrap rman target sys/sys0418@PD1 auxiliary sys/sys0418@PD3

     

    rman上执行

             RMAN> duplicate target database for standby from active database nofilenamecheck;

     

             Starting Duplicate Db at 27-MAR-17

             using target database control file instead of recovery catalog

             allocated channel: ORA_AUX_DISK_1

             channel ORA_AUX_DISK_1: SID=1776 device type=DISK

     

             contents of Memory Script:

             {

                backup as copy reuse

                targetfile  '/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwpowerdes' auxiliary format

              '/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwpowerdes'   ;

             }

             executing Memory Script

     

             ......#这里有很多步骤,需要一步步同步数据文件,花费时间也比较长,过程略过,在这一步的同时,可以去看后台alert的log日志,随时观察进展。

     

             datafile 16 switched to datafile copy

             input datafile copy RECID=23 STAMP=939752404 file name=/home/oradata/powerdes/dw02.DBF

             datafile 17 switched to datafile copy

             input datafile copy RECID=24 STAMP=939752404 file name=/home/oradata/powerdes/timdba01.DBF

             Finished Duplicate Db at 27-MAR-17

     

             RMAN>

     

     

     

    4.3 将主库的LOG_ARCHIVE_DEST_STATE_2设置为ENABLE

    # alter system set log_archive_dest_state_3='enable';

    SQL> alter system set log_archive_dest_state_3='enable';

     

    System altered.

     

    SQL>

     

     

     

    4.4 在备库2上添加standby文件(主库上已经有了standby文件就不需要再添加咯)

    alter database add standby logfile group 4 ('/home/oradata/powerdes/redo_dg_021.log') size 300M;

    alter database add standby logfile group 5 ('/home/oradata/powerdes/redo_dg_022.log') size 300M;

    alter database add standby logfile group 6 ('/home/oradata/powerdes/redo_dg_023.log') size 300M;

     

     

     

    5,开启备库应用

    启动standby的redo应用的两种方式:

    (1)默认的物理DG启动应用后,在主库arch日志被完整写入后才会开始应用该arch log

    SQL> alter database recover managedstandby database disconnect from session;

     

    (2)可以添加current logfile参数,使得应用当前正在读写,还没有完成归档的日志

    SQL> alter database recover managedstandby database using current logfile disconnect from session;

     

    (3)开启多个并行度提高应用效率

    SQL> alter database recover managedstandby database parallel 8 using current logfile disconnect from session;

     

    (4)关闭REDO应用

    SQL> alter database recover managedstandby database using current logfile disconnect from session nodelay;

     

    (5)取消延时应用

    SQL> alter database recover managedstandby database cancel;

     

    实际操作:去备库操作

    SQL> alter database recover managed standby database disconnect from session;

     

    Database altered.

     

    SQL>  select sequence#,applied from v$archived_log order by sequence# asc;

     

     SEQUENCE# APPLIED

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

           138 YES

     

    SQL>

     

     

     

     

     

     

    6,打开备库

    # 在mount状态应用

    SQL> alter database recovermanagedstandby database using current logfile disconnect from session;

     

    Database altered.

    # 取消延时应用

    SQL> alter database recovermanagedstandby database cancel;

     

    Database altered.

    # 打开库

    SQL> alter database open;

    Database altered.

    # 再次应用redo,添加currentlogfile参数,使得应用当前正在读写,还没有完成归档的日志

    SQL> alter database recovermanagedstandby database using current logfile disconnect from session;

    Database altered.

     

    SQL>

     

     

    7,备库failover

    因为备库是高版本11.2.0.4,主库是低版本11.2.0.1,所以不能通过swithover的方式来操作切换备库s2成为主库。

    如果返回的有记录,按照列出的记录号复制对应的归档文件到待转换的standby 服务器。这一步非常重,要,必须确保所有已生成的归档文件均已存在于standby 服务器,不然可能会数据不一致造成转换时报错。

     

    查询待转换standby 数据库的V$ARCHIVE_GAP 视图,确认归档文件是否连接,如果没有记录,就表明可以进行切换,否则需要等待现有记录转换完成再切换。

     

    (1)文件复制之后,通过下列命令将其加入数据字典:

    ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';

    SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

     

    no rows selected

     

    SQL>

     

    (2)检查归档文件是否完整,分别在primary/standby 执行下列语句:

    SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;

     

       THREAD#       A

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

              1       139

     

    SQL>

     

    (3)启动failover 在standby也就是S2上执行

    执行下列语句:alter database recover managed standby database finish force;

    SQL> alter database recover managed standby database finish force;

     

     

    Database altered.

     

    SQL>

    FORCE 关键字将会停止当前活动的RFS 进程,以便立刻执行failover。剩下的步骤就与一般的switchover 很相似了

     

    (4)切换物理standby 角色为primary

    SQL> alter database commit to switchover to primary;

     

     

    Database altered.

     

     

    SQL>

     

    (5)启动新的primary 数据库。

    如果当前数据库已mount,直接open 即可,如果处于read-only 模式,需要首先shutdown immediate,然后再直接startup。

    先查看db的模式,命令为:select open_mode,database_role from v$database;

    SQL> select open_mode,database_role from v$database;

     

    OPEN_MODE        DATABASE_ROLE

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

    MOUNTED           PRIMARY

     

    SQL>

     

     

    8,准备升级

    为mount,所以需要open,但是open之前需要升级操作,因为dg过来的是11.2.0.1的版本的数据。

     

    升级步骤:

             (1)特殊方式启动

    SQL> shutdown immediate;   

    SQL> startup upgrade;

              

             (2)查看预升级信息

             SQL> @$ORACLE_HOME/rdbms/admin/utlu112i.sql

              

             (3)执行升级脚本

             SQL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql       1小时左右

             startup

             SQL> @$ORACLE_HOME/rdbms/admin/utlu112s.sql

             SQL> @$ORACLE_HOME/rdbms/admin/catuppst.sql               8分钟左右

             SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql             2分钟左右

              

             SQL>  ALTER SYSTEM SET CLUSTER_DATABASE=true SCOPE=SPFILE;

              

             (4)重启数据库

             SQL> shutdown immediate;

             ORA-01109: database not open

             Database dismounted.

             ORACLE instance shut down.

             SQL> startup;

     

     

     

     

     

     

     

    问题1------

    SQL> startup;

    ORA-00439: feature not enabled: RealApplication Clusters

    SQL> startup upgrade;

    ORA-00439: feature not enabled: RealApplication Clusters

    SQL>

    SQL>

    SQL> create pfile='/oracle/p2.ora' fromspfile;

     

    File created.

     

    SQL> exit

    Disconnected

    [oracle@hch_test_dbm2_121_71 archivelog]$vim /oracle/p2.ora   注视掉/oracle/p2.ora里面的

    [oracle@hch_test_dbm2_121_71 archivelog]$

     

     

     

     

     

    --1---------------------------------------

    问题报错统计

    查询了一下METALINK,发现这个问题从9i到11g,任何一个版本都可能会出现。造成这个问题的原因是,实例虽然启动,但是没有注册到监听。实例是通过PMON进程注册到监听上的,而PMON进程需要在MOUNT状态下才会启动。因此造成了上面的错误。

    [oracle@hch_test_dbm1_121_63 admin]$ rlwraprman target sys/sys0418@PD1 auxiliary sys/sys0418@PD2

     

    Recovery Manager: Release 11.2.0.1.0 -Production on Mon Mar 27 16:29:23 2017

     

    Copyright (c) 1982, 2009, Oracle and/or itsaffiliates.  All rights reserved.

     

    connected to target database: POWERDES(DBID=3391761643)

    RMAN-00571: ===========================================================

    RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============

    RMAN-00571:===========================================================

    RMAN-00554: initialization of internalrecovery manager package failed

    RMAN-04006: error from auxiliary database:ORA-12528: TNS:listener: all appropriate instances are blocking new connections

    [oracle@hch_test_dbm1_121_63 admin]$

    [oracle@hch_test_dbm1_121_63 admin]$

    [oracle@hch_test_dbm1_121_63 admin]$tnsping PD1

     

    TNS Ping Utility for Linux: Version11.2.0.1.0 - Production on 27-MAR-2017 16:29:33

     

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

     

    Used parameter files:

     

     

    Used TNSNAMES adapter to resolve the alias

    Attempting to contact (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.62)(PORT = 1521)) (CONNECT_DATA= (SERVER = DEDICATED) (SERVICE_NAME = powerdes)))

    OK (0 msec)

    [oracle@hch_test_dbm1_121_63 admin]$ vimlistener.ora

    [oracle@hch_test_dbm1_121_63 admin]$

     

    Oracle给出了两种解决方案,一种方法是对AUXILIARY数据库直接使用/ ,对TARGET数据库通过网络访问。===我上面使用的PD2 (推荐)

    问题解决,在standby库执行

    [oracle@hch_test_dbm1_121_63 admin]$ rlwraprman target sys/sys0418@PD1 auxiliary /

     

    Recovery Manager: Release 11.2.0.1.0 -Production on Mon Mar 27 16:49:30 2017

     

    Copyright (c) 1982, 2009, Oracle and/or itsaffiliates.  All rights reserved.

     

    connected to target database: POWERDES(DBID=3391761643)

    connected to auxiliary database: POWERDES(not mounted)

     

    RMAN>

     

     

    --2---------------------------------

    RMAN> duplicate target database for standby from active databasenofilenamecheck;

     

    Starting Duplicate Db at 27-MAR-17

    RMAN-00571:===========================================================

    RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============

    RMAN-00571:===========================================================

    RMAN-03002: failure of Duplicate Db commandat 03/27/2017 17:26:19

    RMAN-06217: not connected to auxiliarydatabase with a net service name

     

    RMAN>

    去主库执行

     

     

     

    ---3----------------------------

    Fri Mar 31 09:58:35 2017

    Errors in file/oracle/app/oracle/diag/rdbms/powerdes_m1/powerdes/trace/powerdes_arc2_30172.trc:

    ORA-16057: server not in Data Guardconfiguration

    PING[ARC2]: Heartbeat failed to connect tostandby 'PD2'. Error is 16057.

    Fri Mar 31 09:59:36 2017

    Errors in file/oracle/app/oracle/diag/rdbms/powerdes_m1/powerdes/trace/powerdes_arc2_30172.trc:

    ORA-16057: server not in Data Guardconfiguration

    PING[ARC2]: Heartbeat failed to connect tostandby 'PD2'. Error is 16057.

    Fri Mar 31 10:00:36 2017

     

    在主库上查看db_unique_name:

    SQL> show parameter db_unique_name;

     

    NAME                                        TYPE       VALUE

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

    db_unique_name                           string     powerdes_m1

    SQL>

     

    Ok,重新设置LOG_ARCHIVE_CONFIG,设置前面的为powerdes,

    ALTER SYSTEM SETLOG_ARCHIVE_CONFIG='DG_CONFIG=(powerdes_m1,powerdes_s1)';

     

     

    ---4----------------------------

    *** 2017-03-31 10:19:49.225

    Redo shipping client performing standbylogin

    *** 2017-03-31 10:19:49.257 4539 krsu.c

    Logged on to standby successfully

    Client logon and security negotiationsuccessful!

    This database DGID not in Data Guardconfiguration at 'PD2'

    Error 16057 attaching to destinationLOG_ARCHIVE_DEST_2 standby host 'PD2'

    ORA-16057: server not in Data Guardconfiguration

    *** 2017-03-31 10:19:49.260 2747 krsi.c

    krsi_dst_fail: dest:2 err:16057 force:0blast:1

    kcrrwkx: unknown error:16057

    ORA-16055: FAL request rejected

     

     

     

    ---5---------------------------

    FAL[client]: All defined FAL servers havebeen attempted.

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

    Check that theCONTROL_FILE_RECORD_KEEP_TIME initialization

    parameter is defined to a value that issufficiently large

    enough to maintain adequate log switchinformation to resolve

    archivelog gaps.

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

     

    ---6-------

    报错状况:

    Fri Mar 31 11:07:38 2017

    Errors in file/oracle/app/oracle/diag/rdbms/powerdes_m1/powerdes/trace/powerdes_arc1_23696.trc:

    ORA-16057: server not in Data Guardconfiguration

    PING[ARC1]: Heartbeat failed to connect tostandby 'PD2'. Error is 16057.

    Fri Mar 31 11:08:38 2017

    Errors in file/oracle/app/oracle/diag/rdbms/powerdes_m1/powerdes/trace/powerdes_arc1_23696.trc:

    ORA-16057: server not in Data Guardconfiguration

    PING[ARC1]: Heartbeat failed to connect tostandby 'PD2'. Error is 16057.

     

     

    这些告警在ADG的环境中已经多次遇到,请注意类似报错的错误ID,这里的ID是16057,Oracle对该错误是这样解释的

    ORA-16057: DGID from server not in DataGuard configuration

     

    Cause: The Data Guard name of the primarydatabase or the FAL server is not in the Data Guard configuration of thestandby.

     

    Action: In order for the primary databaseor the FAL server to archive logs to the standby database, the Data Guard nameof the primary or FAL server must be in the Data Guard configuration of thestandby.

     

     

    积极排查问题

     

             主库通道备状况

             SQL>show parameter  log_archive_dest_state_2;

     

             NAME                                        TYPE       VALUE

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

             log_archive_dest_state_2           string     ENABLE

             log_archive_dest_state_20        string     enable

             log_archive_dest_state_21        string     enable

             log_archive_dest_state_22        string     enable

             log_archive_dest_state_23        string     enable

             log_archive_dest_state_24        string     enable

             log_archive_dest_state_25        string     enable

             log_archive_dest_state_26        string     enable

             log_archive_dest_state_27        string     enable

             log_archive_dest_state_28        string     enable

             log_archive_dest_state_29        string     enable

             SQL>

             SQL>

             SQL>

             SQL>  show parameter  log_archive_dest_state_2;

     

             NAME                                        TYPE       VALUE

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

             log_archive_dest_state_2           string     ENABLE

             log_archive_dest_state_20        string     enable

             log_archive_dest_state_21        string     enable

             log_archive_dest_state_22        string     enable

             log_archive_dest_state_23        string     enable

             log_archive_dest_state_24        string     enable

             log_archive_dest_state_25        string     enable

             log_archive_dest_state_26        string     enable

             log_archive_dest_state_27        string     enable

             log_archive_dest_state_28        string     enable

             log_archive_dest_state_29        string     enable

             SQL>

     

             ALTERSYSTEM SET log_archive_dest_state_2='DEFER' SCOPE=BOTH;

             ALTERSYSTEM SET log_archive_dest_state_2='ENABLE' SCOPE=BOTH;

     

            

             [oracle@hch_test_dbm1_121_62dbs]$ scp orapwpowerdes192.168.121.63:/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/orapwpowerdes.m1

             oracle@192.168.121.63'spassword:

             orapwpowerdes                                                                                                                                                                                                                               100% 2560     2.5KB/s   00:00   

             [oracle@hch_test_dbm1_121_62dbs]$

             [oracle@hch_test_dbm1_121_63dbs]$ diff orapwpowerdes orapwpowerdes.m1

             [oracle@hch_test_dbm1_121_63dbs]$

     

             ALTERSYSTEM SET log_archive_dest_state_2='defer' SCOPE=BOTH;

             ALTERSYSTEM SET log_archive_dest_state_2='enable' SCOPE=BOTH;

                      

             主库配置状况

             SQL>show parameter log_archive_config;

     

             NAME                                        TYPE       VALUE

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

             log_archive_config               string     DG_CONFIG=(powerdes_m1,powerde

                                                                      s_s1)

             SQL>

     

     

             备库配置状况

             SQL>show parameter log_archive_config;

     

             NAME                                        TYPE       VALUE

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

             log_archive_config               string     dg_config=(powerdes,powerdes_s

                                                                      1)

             SQL>

             看到这里有差异,所以需要重新设置下

             ALTERSYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(powerdes_m1,powerdes_s1)'SCOPE=BOTH;                                                          

            

             再次应用日志

             SQL>  alter database recover managed standbydatabase using current logfile disconnect from session;

     

             Databasealtered.

     

             SQL>

     

             OK,主库成功连接到备库,已经开始传输归档日志了,后台alert如下所示:

             ArchivedLog entry 62 added for thread 1 sequence 134 ID 0xd12c9f55 dest 1:

             Primarydatabase is in MAXIMUM PERFORMANCE mode

             RFS[68]:Selected log 4 for thread 1 sequence 135 dbid -903205653 branch 939330809

             FriMar 31 13:10:31 2017

             RFS[69]:Assigned to RFS process 17588

             RFS[69]:Identified database type as 'physical standby': Client is ARCH pid 23696

             FriMar 31 13:11:25 2017

              alter database recover managed standbydatabase using current logfile disconnect from session

             Attemptto start background Managed Standby Recovery process (powerdes)

             FriMar 31 13:11:25 2017

             MRP0started with pid=31, OS id=17590

             MRP0:Background Managed Standby Recovery process started (powerdes)

              started logmerger process

             FriMar 31 13:11:30 2017

             ManagedStandby Recovery starting Real Time Apply

             FriMar 31 13:11:31 2017

             RFS[70]:Assigned to RFS process 17634

             RFS[70]:Identified database type as 'physical standby': Client is ARCH pid 23696

             ParallelMedia Recovery started with 32 slaves

             Waitingfor all non-current ORLs to be archived...

             Allnon-current ORLs have been archived.

             Completed:  alter database recover managed standbydatabase using current logfile disconnect from session

             MediaRecovery Log/oracle/app/oracle/flash_recovery_area/archivelog1_73_939330809.dbf

             MediaRecovery Log /oracle/app/oracle/flash_recovery_area/archivelog1_74_939330809.dbf

             MediaRecovery Log/oracle/app/oracle/flash_recovery_area/archivelog1_75_939330809.dbf

             MediaRecovery Log/oracle/app/oracle/flash_recovery_area/archivelog1_76_939330809.dbf

             MediaRecovery Log/oracle/app/oracle/flash_recovery_area/archivelog1_77_939330809.dbf

             MediaRecovery Log/oracle/app/oracle/flash_recovery_area/archivelog1_78_939330809.dbf

            

     

                      

    移动redo文件路径

             SQL>select member from v$logfile;

     

             MEMBER

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

             /oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log

     

             /oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfksto61_.log

     

             /oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_1_dfksto1q_.log

     

             /home/oradata/powerdes/redo_dg_021.log

             /home/oradata/powerdes/redo_dg_022.log

     

             MEMBER

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

             /home/oradata/powerdes/redo_dg_023.log

     

             6rows selected.

     

             SQL>

     

     

             SQL>shutdown immediate;

             ORA-01109:database not open

     

     

             Databasedismounted.

             ORACLEinstance shut down.

             SQL>

     

             cp文件地址:

             [oracle@hch_test_dbm1_121_63~]$ mv/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log/home/oradata/powerdes/redo03.log

             [oracle@hch_test_dbm1_121_63~]$ mv /oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfksto61_.log/home/oradata/powerdes/redo02.log

             [oracle@hch_test_dbm1_121_63~]$ mv/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_1_dfksto1q_.log/home/oradata/powerdes/redo01.log

            

             cp  /home/oradata/powerdes/redo03.log /oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log

             cp  /home/oradata/powerdes/redo02.log/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfkstobl_.log

             cp  /home/oradata/powerdes/redo01.log/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_1_dfkstobl_.log

            

             数据库启动mount

             alterdatabase rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log'to '/home/oradata/powerdes/redo03.log';

             alterdatabase rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfksto61_.log'to '/home/oradata/powerdes/redo02.log';

             alterdatabase rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_1_dfksto1q_.log'to '/home/oradata/powerdes/redo01.log';

     

             执行报错

             SQL>alter database rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log'to '/home/oradata/powerdes/redo03.log';

             alterdatabase rename file '/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log'to '/home/oradata/powerdes/redo03.log'

             *

             ERRORat line 1:

             ORA-01511:error in renaming log/data files

             ORA-01275:Operation RENAME is not allowed if standby file management is

             automatic.

     

             命令执行报错,提示说standbyfile maangement参数为自动,自动情况下不允许修改,好吧,听它的,修改成手动的,这样我们就可以移动它的目录地址了

             SQL>show parameter standby;

     

             NAME                                        TYPE       VALUE

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

             standby_archive_dest                   string     ?/dbs/arch

             standby_file_management        string     AUTO

             SQL>alter system set standby_file_management = MANUAL;

     

             Systemaltered.

     

             SQL>      

            

             SQL>alter database rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_3_dfkstobl_.log'to '/home/oradata/powerdes/redo03.log';

     

             Databasealtered.

     

             SQL>

     

             执行第一个成功,但是执行第二个报错,记录如下:

             SQL>alter database rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfkstobl_.log'to '/home/oradata/powerdes/redo02.log';

             alterdatabase rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfkstobl_.log'to '/home/oradata/powerdes/redo02.log'

             *

             ERRORat line 1:

             ORA-01511:error in renaming log/data files

             ORA-01516:nonexistent log file, data file, or temporary file

             "/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfkstobl_.

             log"

     

     

             SQL>

            

             看提示,这个文件nonexiststent log file,看是文件不存在,check下,修改成正确的文件名,再次执行。

            

             再次执行

             SQL>alter database rename file'/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_2_dfksto61_.log'to '/home/oradata/powerdes/redo02.log';

     

             Databasealtered.

     

             SQL>alter database rename file '/oracle/app/oracle/flash_recovery_area/POWERDES_S1/onlinelog/o1_mf_1_dfksto1q_.log'to '/home/oradata/powerdes/redo01.log';

     

             Databasealtered.

     

             SQL>

            

             查看当前路径:

             SQL>show parameter db_file_name_convert;

     

             NAME                                        TYPE       VALUE

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

             db_file_name_convert                   string

             SQL>

             SQL>  select member from v$logfile;

     

             MEMBER

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

             /home/oradata/powerdes/redo03.log

             /home/oradata/powerdes/redo02.log

             /home/oradata/powerdes/redo01.log

             /home/oradata/powerdes/redo_dg_021.log

             /home/oradata/powerdes/redo_dg_022.log

             /home/oradata/powerdes/redo_dg_023.log

     

             6rows selected.

     

             SQL>select name from v$datafile;

     

             NAME

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

             /home/oradata/powerdes/system01.dbf

             /home/oradata/powerdes/sysaux01.dbf

             /home/oradata/powerdes/undotbs01.dbf

             /home/oradata/powerdes/users01.dbf

             /home/oradata/powerdes/powerdesk01.dbf

             /home/oradata/powerdes/plas01.dbf

             /home/oradata/powerdes/pl01.dbf

             /home/oradata/powerdes/help01.dbf

             /home/oradata/powerdes/adobelc01.dbf

             /home/oradata/powerdes/sms01.dbf

             /home/oradata/powerdes/plcrm01.dbf

     

             NAME

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

             /home/oradata/powerdes/powerdesk02.dbf

             /home/oradata/powerdes/datagm01.dbf

             /home/oradata/powerdes/plimp01.DBF

             /home/oradata/powerdes/dwetl01.DBF

             /home/oradata/powerdes/dw02.DBF

             /home/oradata/powerdes/timdba01.DBF

     

             17rows selected.

     

             SQL>

     

             重启查看新的是否生效

             SQL>shutdown immediate;

             ORA-01109:database not open

     

     

             Databasedismounted.

             ORACLEinstance shut down.

             SQL>startup mount;

             ORACLEinstance started.

     

             TotalSystem Global Area 2.6991E+10 bytes

             FixedSize              2213976 bytes

             VariableSize              1.9059E+10 bytes

             DatabaseBuffers    7784628224 bytes

             RedoBuffers               145174528 bytes

             Databasemounted.

             SQL>

             SQL>select member from v$logfile;

     

             MEMBER

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

             /home/oradata/powerdes/redo03.log

             /home/oradata/powerdes/redo02.log

             /home/oradata/powerdes/redo01.log

             /home/oradata/powerdes/redo_dg_021.log

             /home/oradata/powerdes/redo_dg_022.log

             /home/oradata/powerdes/redo_dg_023.log

     

             6rows selected.

     

             SQL>

     

            

            

    如果主库备库都是一致的话,需要修改

    ----处理方法:

    ----主库上:

    alter system setlog_archive_dest_2='service=dg_22 sync affirm net_timeout=10valid_for=(online_logfile,primary_role) db_unique_name=dg_22';

     

    ----备库上:

    alter system set db_unique_name=dg_22scope=spfile;

    shut immediate

    startup mount

    alter system set service_names=orcl;     ----服务名和主库一致

    最后再开启日志应用,这时主库切换日志后,可以看到备库能正常应用日志,并且主库没有出现任何异常了。

    展开全文
  • redis集群安装步骤(一主一备

    千次阅读 2018-11-18 11:21:24
    redis集群安装步骤(一主一备) 后面需要用到 ruby 脚本 # yum install ruby -y 安装 ruby 包管理器 # yum install rubygems -y 脚本需要 ruby 其他包,所以安装这个 redis.gem # gem install redis-3.0.0....

    redis集群安装步骤(一主一备)

    1. 后面需要用到 ruby 脚本
     # yum install ruby -y
    
    1. 安装 ruby 包管理器
    # yum install rubygems -y
    
    1. 脚本需要 ruby 其他包,所以安装这个 redis.gem
    # gem install redis-3.0.0.gem
    
    1. 在/usr/local 中新建 redis-cluster 文件夹(非必须)
    # mkdir reids-cluster
    
    1. 把之前安装好的 redis/bin 复制到 redis-cluster 中并起名为 redis01
    # cp -r bin ../redis-cluster/redis01
    
    1. 删除掉 redis01 中 dump.rdb 数据库文件
    #  rm -rf dump.rdb
    
    1. 修改 redis01 中端口号为 7001, 找到 port 后面修改为 7001
      去掉 cluster-enabled yes 前面的注释
      如果之前设置过密码,注释掉密码.如果没有设置过过略 7.3 这步骤
    #  vim redis.conf
    
    1. 把 redis01 文件夹在复制 5 份,分别起名为 redis02,redis03,redis04,redis05,redis06
    #  cp -r redis01 redis02
    	cp -r redis01 redis03
    	cp -r redis01 redis04
    	cp -r redis01 redis05
    	cp -r redis01 redis06
    
    1. 修改6个文件夹中的redis.conf中的端口号
    # vi redis01/redis.conf
    # vi redis02/redis.conf
    # vi redis03/redis.conf
    # vi redis04/redis.conf
    # vi redis05/redis.conf
    # vi redis06/redis.conf
    
    1. 去 redis 解压目录中 src 下执行此命令
      把 redis-trib.rb 复制到 reids-cluster 中.
    #cp *.rb /usr/local/redis-cluster/
    
    1. 创建一个批量启动文件
    # vi startall.sh
    
    1. 把下面内容粘贴到文件中
    	cd redis01
    ./redis-server redis.conf
    cd ..
    cd redis02
    ./redis-server redis.conf
    cd ..
    cd redis03
    ./redis-server redis.conf
    cd ..
    cd redis04
    ./redis-server redis.conf
    cd ..
    cd redis05
    ./redis-server redis.conf
    cd ..
    cd redis06
    ./redis-server redis.conf
    cd ..
    
    1. 给脚本设置一个可启动权限
    # chmod a+x startall.sh
    
    1. 执行脚本,启动所有 redis 服务
    # ps aux|grep redis
    
    1. 查看所有服务是否启动成功
    #ps -ef | grep redis
    
    1. 创建集群
      在执行时按照提示输入’yes’(IP地址改为自己的虚拟机ip地址)
    	# ./redis-trib.rb create --replicas 1 192.168.192.130:7001 192.168.192.130:7002 192.168.192.130:7003 192.168.192.130:7004 192.168.192.130:7005 192.168.192.130:7006
    
    1. 进入任意节点测试
    	# ./redis01/redis-cli -h 192.168.10.128 -p 7001 -c
    
    1. 关闭其中一个 redis
    	# redis01/redis-cli -p 7001 shutdown
    
    1. 新建一个关闭redis集群的脚本文件,并赋予权限
    # vim shutdown.sh
    #chmod a+x shutdown.sh
    
    1. 往shutdown.sh里面写入以下内容
    ./redis01/redis-cli -p 7001 shutdown
    ./redis02/redis-cli -p 7002 shutdown
    ./redis03/redis-cli -p 7003 shutdown
    ./redis04/redis-cli -p 7004 shutdown
    ./redis05/redis-cli -p 7005 shutdown
    ./redis06/redis-cli -p 7006 shutdown
    
    展开全文
  • springboot+mycat数据库中间件+mysql(一主一备)主从复制 硬件:3台linux系统虚拟主机,Ip分别为192.168.43.23做主库(读写,192.168.43.12备库(读),192.168.43.155(安装mycat数据库中间件)  1.mycat读写...

                   springboot+mycat数据库中间件+mysql(一主一备)主从复制

    硬件:3台linux系统虚拟主机,Ip分别为192.168.43.23做主库(读写,192.168.43.12备库(读),192.168.43.155(安装mycat数据库中间件)

     1.mycat读写分离架构图


                                           


           主要实现原理:




    2. linux下使用yum安装mysql


    (mastr192.168.43.23,slave192.168.43.12)


      2.1安装mysql 服务器端:

              yuminstall mysql-server

              yuminstall mysql-devel


     2.2编辑mastr192.168.43.23 mysql配置文件

         vim  /etc/my.conf  加入

        default-character-set=utf8//设置字符集

        server_id=23//服务id

        log-bin=mysql-bin//开启日志


    2.3编辑slave192.168.43.12配置文件

       vim  /etc/my.conf  加入

      default-character-set=utf8

      server_id=12

      log-bin=mysql-bin

      binlog_do_db=everyday//表示要同步的主机数据库实例是everyday


    2.4创建root管理员

     mysqladmin -u root password 123456


    2.5登录

      mysql -uroot -p输入密码即可。


    3.开放远程连接权限(开放所有IP以root账号连接)

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'  WITH GRANT OPTION;


    4同步主从数据库


    4.1主服务器给从服务器授权


     登录mysql主服务器,执行sql:

     grant replication slave on *.* to 'root'@'192.168.43.12'identified by '123456';FLUSH PRIVILEGES; 

    然后执行此语句SHOW MASTER STATUS


    4.2登录mysql从服务器,执行sql

    STOP SLAVE;

    change master tomaster_host='192.168.43.23',master_user='root',master_password='123456',

    master_log_file='mysql-bin.000007',master_log_pos=2070;

    START SLAVE;

    然后执行该语句:SHOW SLAVE STATUS查询到结果yes,yes 说明同步成功

    数据同步原理:通过同步2进制sql文件mysql-bin.000007进行同步,包含delete,insert,update等操作记录。


    5.安装mycat数据库中间件

    什么是mycat

    一个彻底开源的,面向企业应用开发的大数据库集群

    支持事务、ACID、可以替代MySQL的加强版数据库

    一个可以视为MySQL集群的企业级数据库,用来替代昂贵的Oracle集群

    一个融合内存缓存技术、NoSQL技术、HDFS大数据的新型SQLServer

    结合传统数据库和新型分布式数据仓库的新一代企业级数据库产品

    一个新颖的数据库中间件产品


    5.1.安装mycat(192.168.43.155)

    解压  tar zxvfMycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/

    移动到/usr/local目录  mv  mycat/usr/local

    cd /usr/local/mycat/bin

    ./mycatstart启动
    ./mycat stop
    停止


    5.2配置mycat实现读写分离

    # vim /usr/local/mycat/conf/server.xml  //新增2个账号用来登录mycat,添加以下内容

     <username="mycatread">  //mycat用户名
    
     <propertyname="password">mycat</property> //mycat密码
    
     <propertyname="schemas">mydb</property>  //mycat虚拟数据库名
    
     <propertyname="readOnly">true</property>  //只读
    
     </user>
    
     
    
     <username="mycat">
    
     <propertyname="password">mycat</property>
    
     <propertyname="schemas">mydb</property>
    
     </user>

    在这里要注意,默认的虚拟数据名是TESTDB,如果schema.xml里面没有配置testdb,那就要把testdb改成schema.xml里面有的虚拟数据名。这里定义的用户名和密码,虚拟数据库名,并不是在mysql中真实存在的。

    :wq 保存退出

    vim schema.xml

    配置schema.xml

    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://io.mycat/">
     
    <schema name="mydb" checkSQLschema="false" sqlMaxLimit="100" dataNode="my1" />//定义虚拟数据库名mydb
    <dataNode name="my1" dataHost="test1" database="everyday" /> //真实数据库名test
    <dataHost name="test1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" >
    <heartbeat>select user()</heartbeat>
    <writeHost host="hostM1" url="192.168.43.23:3306" user="root" password="123456" > //真实数据库的连接方式
        <readHost host="hostS1" url="192.168.43.12:3306" user="root" password="123456" /> //同上
    </writeHost>
    </dataHost>
    </mycat:schema>
    
    mycat的配置参数,相当的多。重点说一下 balance="1"与writeType="0"

    a.balance 属性负载均衡类型,目前的取值有 4 种:

    1.balance="0",不开启读写分离机制,所有读操作都发送到当前可用的 writeHost上。

    2.balance="1",全部的 readHost与 stand by writeHost 参与 select 语句的负载均衡,简单的说,当双主双从模式(M1 ->S1 , M2->S2,并且 M1 与M2 互为主备),正常情况下, M2,S1,S2 都参与 select 语句的负载均衡。

    3.balance="2",所有读操作都随机的在 writeHost、 readhost 上分发。

    4.balance="3", 所有读请求随机的分发到 wiriterHost对应的 readhost 执行,writerHost 不负担读压力,注意 balance=3 只在 1.4 及其以后版本有, 1.3 没有。

    b.writeType属性

    负载均衡类型,目前的取值有 3种:

    1.writeType="0",所有写操作发送到配置的第一个 writeHost,第一个挂了切到还生存的第二个

    writeHost,重新启动后已切换后的为准,切换记录在配置文件中:dnindex.properties.

    2.writeType="1",所有写操作都随机的发送到配置的 writeHost

    3. writeType="2",没实现。

    # ./mycat start
    
    Starting Mycat-server...
    
     
    
    # netstat -tpnl |grep 8066
    
    tcp 0 0 :::8066 :::* LISTEN 31728/java
    
     
    
    # ./mycat status
    
    
    Mycat-server is running (31726).

    6 配置完成之后添加数据测试

    登录windows系统中的mysql客户端进行连接

    mycat连接方式如下:


     


    mycat中间件做读写分离完成


             

    7springboot通过application.yml文件配置mycat连接池

    项目目录

     

    项目依赖pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.sunyard</groupId>
    	<artifactId>spboot</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    
    	<!--必须要引入继承 spring-boot-starter-parent 帮我们实现很多jar的依赖,不需要写jar版本 -->
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>1.5.3.RELEASE</version>
    	</parent>
    
    	<dependencies>
    		<!-- springmvc springboot默认集成,添加springboot-web依赖即可 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
    
    		<!--引入freeMarker依赖 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-freemarker</artifactId>
    		</dependency>
    
    		<!-- 引入mysql驱动jar包 -->
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    		</dependency>
    
    		<!-- springboo与mybatis整合包 -->
    		<dependency>
    			<groupId>org.mybatis.spring.boot</groupId>
    			<artifactId>mybatis-spring-boot-starter</artifactId>
    			<version>1.1.1</version>
    		</dependency>
    
                     <!-- jdbc -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-jdbc</artifactId>
    		</dependency>
    
    		<!-- yml支持 @ConfigurationProperties 注解 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-configuration-processor</artifactId>
    		</dependency>
    	</dependencies>
    </project>

    application.yml

     

    spring:  
      datasource:  
        url: jdbc:mysql://192.168.43.155:8066/mydb  
        username: mycat  
        password: mycat 
        driverClassName: com.mysql.jdbc.Driver

    controller

     

    package com.spboot.controller;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.spboot.pojo.Ticket;
    import com.spboot.service.TicketService;
    
    @Controller
    public class TicketController {
    
    	@Autowired
    	private TicketService ticketService;
    
    	@RequestMapping("/getTicketList.do")
    	public ModelAndView getTicketList() {
    		List<Ticket> ticketList = ticketService.getTicketList();
    		ModelAndView mav = new ModelAndView();
    		mav.setViewName("index");
    		mav.addObject("ticketList", ticketList);
    		return mav;
    	};
    
    	@RequestMapping("/getFtl.do")
    	public ModelAndView getFtl(ModelAndView mav) {
    		mav.addObject("name", "ss");
    		mav.setViewName("index");
    		return mav;
    	};
    
    	@RequestMapping("/index")
    	public String getFtlt(ModelMap map) {
    		map.addAttribute("name", "你妈");
    		return "index";
    	};
    
    }
    

     

    service

    package com.spboot.service;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import com.spboot.mapper.TicketMapper;
    import com.spboot.pojo.Ticket;
    import com.spboot.utils.common.TimeUtils;
    
    @Service
    public class TicketService {
    	@Autowired
    	private TicketMapper ticketMapper;
    	public List<Ticket> getTicketList() {
    		List<Ticket> ticketList = ticketMapper.getTicketList();
    		for (Ticket ticket : ticketList) {
    			String beginTimeStr = TimeUtils.getISOTime(ticket.getBeginTime());
    			String endTimeStr = TimeUtils.getISOTime(ticket.getEndTime());
    			ticket.setBeginTimeStr(beginTimeStr);
    			ticket.setEndTimeStr(endTimeStr);
    		}
    		return ticketList;
    	}
    }
    

     

    mapper

     

    package com.spboot.mapper;
    
    import java.util.List;
    
    import org.apache.ibatis.annotations.Select;
    
    import com.spboot.pojo.Ticket;
    
    public interface TicketMapper {
    	
        @Select("select * from ticket;")
    	List<Ticket> getTicketList();
    
    }
    

    ticket

     

    package com.spboot.pojo;
    
    import java.util.Date;
    /**
     * 
     * @ClassName: Ticket 
     * @Description: 车票信息实体类
     * @author wenf.jiao
     * @date 2018年1月14日 下午7:29:17 
     *
     */
    public class Ticket {
    	/*
    	 * 车票ID
    	 */
        private Integer ticketID;
        /*
    	 * 开车地点
    	 */
        private String startting;
        /*
    	 * 到站地点
    	 */
        private String destination;
        /*
    	 * 价钱
    	 */
        private Integer price;
        /*
    	 * 开车时间
    	 */
        private Date beginTime;
        /*
    	 * 到站时间
    	 */
        private Date endTime;
        /*
      	 * 开车时间字符串
      	 */
          private String beginTimeStr;
          /*
      	 * 到站时间字符串
      	 */
          private String endTimeStr;
    
        public Integer getTicketID() {
            return ticketID;
        }
    
        public void setTicketID(Integer ticketID) {
            this.ticketID = ticketID;
        }
    
        public String getStartting() {
            return startting;
        }
    
        public void setStartting(String startting) {
            this.startting = startting;
        }
    
        public String getDestination() {
            return destination;
        }
    
        public void setDestination(String destination) {
            this.destination = destination;
        }
    
        public Integer getPrice() {
            return price;
        }
    
        public void setPrice(Integer price) {
            this.price = price;
        }
    
        public Date getBeginTime() {
            return beginTime;
        }
    
        public void setBeginTime(Date beginTime) {
            this.beginTime = beginTime;
        }
    
        public Date getEndTime() {
            return endTime;
        }
    
        public void setEndTime(Date endTime) {
            this.endTime = endTime;
        }
    
    	public String getBeginTimeStr() {
    		return beginTimeStr;
    	}
    
    	public void setBeginTimeStr(String beginTimeStr) {
    		this.beginTimeStr = beginTimeStr;
    	}
    
    	public String getEndTimeStr() {
    		return endTimeStr;
    	}
    
    	public void setEndTimeStr(String endTimeStr) {
    		this.endTimeStr = endTimeStr;
    	}
        
    }

    index.ftl(模板引擎)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <div align="center">
    	<table class="table" border="2">
    		<thead>
    			<tr>
    				<th>车票编号</th>
    				<th>出发地点</th>
    				<th>目的地</th>
    				<th>价钱</th>
    				<th>发车时刻</th>
    				<th>到达时刻</th>
    			</tr>
    		</thead>
    		<tbody>
    		<#list ticketList as ticket>
            <tr>
    		<td>${ticket.ticketID}</td>
    		<td>${ticket.startting}</td>
    		<td>${ticket.destination}</td>
    		<td>${ticket.price}</td>
    		<td>${ticket.beginTimeStr}</td>
    		<td>${ticket.endTimeStr}</td>
    		</tr>
            </#list>
    		</tbody>
    	</table>
    </body>
    </html>

    全局捕获异常

    package com.spboot.spexception;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.core.annotation.AnnotationUtils;
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.bind.annotation.ExceptionHandler;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.bind.annotation.ResponseStatus;
    
    /**
     * 
     * @ClassName: GlobalExceptionHandler 
     * @Description: springboot全局异常捕获
     * @author 
     * @date 2018年1月26日  
     *
     */
    @ControllerAdvice
    public class GlobalExceptionHandler {
    	@ResponseBody
    	@ExceptionHandler(Exception.class)
    	public Map<String, Object> exceptionHandler(HttpServletRequest request,HttpServletResponse response,Exception e){
    		if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class)!=null) {
    			try {
    				throw e;
    			} catch (Exception e1) {
    				e1.printStackTrace();
    			}
    		}
    		Map<String, Object> resMap=new HashMap<>();
    		resMap.put("url", request.getRequestURL());
    		resMap.put("class",e.getClass());
    		resMap.put("cause",e.getCause());
    		resMap.put("message",e.getMessage());
    		return resMap;
    	}
    }

    application.java

    package application;
    
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.context.annotation.ComponentScan;
    /**
     * 
     * @ClassName: application 
     * @Description: 企业级启动方式
     * @author 
     * @date 2018年1月26日 下午4:27:25 
     *
     */
    @ComponentScan(basePackages="com.spboot.*")
    @MapperScan(basePackages="com.spboot.*")
    @EnableAutoConfiguration
    public class Application {
    	public static void main(String[] args) {
    		SpringApplication.run(Application.class, args);
    	}
    }
    

    点击右键启动项目,控制台打印如下日志

     访问接口

    结果页面

     

     

     

     

     

     

     

     

     

    展开全文
  • 1.上篇讲解了如何在服务器搭建Nginx服务器,这里不做过多描述。 首先把压缩包拷贝到Linux的/usr/local目录下(Nginx:192.168.0.111) 2.安装keepalived(Nginx:192.168.0.111) 进入/usr/local目录下:...

    1.上一篇讲解了如何在服务器搭建Nginx服务器,这里不做过多描述。

    首先把压缩包拷贝到Linux的/usr/local目录下(主Nginx:192.168.0.111)

    2.安装keepalived(主Nginx:192.168.0.111)

    进入/usr/local目录下:

    tar -zxvf keepalived-1.2.18.tar.gz

    yum install -y openssl openssl-devel(需要安装一个软件包)

    cd keepalived-1.2.18/  && ./configure --prefix=/usr/local/keepalived

    make && make install

    常见错误1
    
    执行yum install 报错如下:
    
    File contains no section headers.
    
    解决方案:
    步骤1
    
    删除yum.repos.d目录下所有文件
    
    rm -f /etc/yum.repos.d/*  
    
    步骤2
    
    然后重新下载阿里的镜像
    
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  
    
    步骤3
    
    清理缓存
    
    yum clean all
    
    步骤4
    
    测试下载安装
    
    yum install gcc  
    
    常见错误2
    
    报错: eepalived执行./configure --prefix=/usr/local/keepalived时报错:configure: error: Popt libraries is required
    
    出现此错误的原因:
    
    未安装popt的开发包
    
    解决方法:
    
    yum install popt-devel
    
    安装好popt的开发包。重新./configure 即可。

    3.将keepalived安装成Linux系统服务,因为没有使用keepalived的默认安装路径(默认路径:/usr/local),安装完成之后,需要做一些修改工作:(主Nginx:192.168.0.111)

    ① 首先创建文件夹,将keepalived配置文件进行复制:

    mkdir /etc/keepalived

    cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

    ② 然后复制keepalived脚本文件:

    cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

    cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

    ln -s /usr/local/sbin/keepalived /usr/sbin/

    ln -s /usr/local/keepalived/sbin/keepalived /sbin/

    可以设置开机启动:chkconfig keepalived on,到此我们安装完毕!

    4.替换默认的keepalived.conf配置文件(本人已配置好,直接用SecureFX工具将下图本地两个文件上传,并替换)

      nginx_check.sh

    #!/bin/bash
    A=`ps -C nginx –no-header |wc -l`
    if [ $A -eq 0 ];then
        /usr/local/nginx/sbin/nginx
        sleep 2
        if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
            killall keepalived
        fi
    fi
    

    5.进入/etc/keepalived目录(主Nginx:192.168.0.111)

    查看一下当前linux虚拟机网卡,可以看出是eth0(注意:如果虚拟网卡为ens33,则设为ens33)

    打开keepalived配置文件,注意以下五处:

    master:192.168.0.111我们设置为主Nginx

    eth0:上图中ip a得出的网卡名

    192.168.0.111:虚拟机IP

    121:多个Nginx配keepalived时,这个值必须一致

    192.168.110.110:虚拟ip,可在windows浏览器下直接访问

    上述配置好后,wq保存退出。此时我们再次键入ip a,可以发现多了一个eth0,即我们配置的虚拟IP

    6.此时,启动keepalived:service keepalived start

    在Windows浏览器下访问我们配置的虚拟IP:192.168.110.110,会调到主Nginx首页(nginx/html/index.html)

    7.我们再配一个备机Nginx(备Nginx:192.168.0.108)

    重复上述安装步骤,ip a发现网卡为eth1

    打开keepalived配置文件

    此Nginx改为备机:BACKUP

    网卡改为:eth1

    虚拟路由ID号与主机保持一致,都为121

    IP地址改为备机IP

    虚拟IP也配为192.168.110.110

    wq退出

    启动备机192.168.0.108的keepalived:service keepalived start

    此时我们再次键入ip a,发现还是只有一个eth1,主Nginx(192.168.0.111)配完keepalived后有两个eth0

    原因:现在虚拟IP192.168.110.110在走主机,没走备机

    8.此时,我们把主Nignx的keepalived停掉

    在192.168.0.111服务器下执行命令:service keepalived stop

    再次在浏览器键入虚拟IP:192.168.110.110,可以发现进入备机Nginx

    并且,此时主Nginx变为一个eth0,备Nginx变为两个eth1:

     

    下面做个试验:

    ① 把两台服务器服务器的keepalived和nginx都停掉

    注意:都停掉(如果只停keepalived,访问192.169.0.111和192.168.0.108都可以访问得到Nginx首页)

        

    可以发现,现在虚拟IP:192.168.110.110访问不了了,因为这个IP地址是keepalived虚拟出来的,现在keekalived都停了

    访问192.169.0.111和192.168.0.108也访问不到Nginx首页了

    ② 此时把192.168.0.108的keepalived启动起来

    依旧访问不到192.168.110.110

    原因:没有权限

     

    解决方法:先把刚才启动的keepalived停掉,进入/etc/keepalived,给上述sh赋予权限

    此时启动192.168.0.108的keepalived,浏览器访问虚拟IP:192.168.110.110,会访问得到108Nginx首页

    并且此时,强制把nginx宕机掉,会秒起,只要keepalived不挂,会一直自动重启

    ③ 把 主Nginx(192.168.0.111)的/etc/keepalived下的nginx_check.sh赋予权限

    启动192.168.0.111的keepalived

    浏览器访问虚拟IP:192.168.110.110,会访问得到111Nginx首页

     

    总结1:

    ① 如果keepalived重启多次nginx失败,则可以配置,发送报警邮件给运维人员

    ② Nginx一主一备不同于Redis的哨兵机制,keepalived当主机挂了,再重启后,之前主机还是主机

    总结2:

    ① 如果你的项目在发布的时候,之前使用的session丢失了怎么办?

    方案:1.将session持久会到硬盘 、2.缓存到redis中;
    大的项目基本上都是使用token去替代sesion

    ② LVS 与Nginx实现负载均衡有那些区别?

    Lvs协调者可以管理我们nginx的集群,是四层负载均衡 基于tcp ip和端口号实现负载均衡

    Nginx 管理的是我们的服务器集群,是七层负载均衡器  能够对我们http协议实现负载均衡

    ③ keepAlived是对我们的lvs实现扩展功能,对我们应用程序监听、心跳检测、自动重启脚本;

    客户端请求先达到Lvs虚拟vip地址,在通过Lvs实现负载均衡转发到nginx服务器,Nginx服务器再转发到真实上游服务器。

    Lvs是Linux自带的功能,而keepalived需要安装

    总结3:

    ① DNS解析:买了域名后,(域名,IP地址)有一个库,每个运营商都会去读取该库

    ② 阿里云如何搭建局域网
    答案:只要阿里云同一个账号买服务器,基本上都是在同一个局域网中

     ps aux | grep 'nginx'  查看nginx进程

    ④ 跨域问题

    什么是网站跨域问题?
    答案:页面中请求的ajax地址如果与页面请求地址域名和端口、协议不同的话,浏览器采用安全策略,请求能够正常到达服务器端,但是无法获取响应结果

    什么场景会产生跨域?
    答案:前后端分离

    Java如何解决跨域问题? 注意:跨域是浏览器自带的一种安全机制

    1. 项目响应头设置允许跨域权限(或过滤器) response.setHeader("Access-Control-Allow-Origin", "*"); 适合于小公司
    2. 使用jsonp解决网站跨域问题 缺点:只能支持Get请求即使用post发送,也会转为get发给服务端 模拟脚本提交。很少用
    3. 使用Nginx解决:https://blog.csdn.net/l1028386804/article/details/79488328
    4. 使用微服务中的Zuul网关
    5. HttpClient实现转发 缺点:重复发送两次请求 )

             因为httpclient不存在跨域问题,相当于你在a项目写个接口,用httpclient或restTemplate调用b项目的接口,a项目的ajax调用a的接口即可,由此可以保证域名,端口相同

    阿里云默认不支持虚拟VIP技术,怎么解决?

    答案:可以找云服务器厂商,单独购买IP

    ⑥ 1M带宽每秒只能传输128kb: 128kb/s

        1024 / 8=128kb/s

    ⑦ 动静分离,CDN加速

    答案:动态资源(jsp,servlet,springmvc)与静态资源(js,html,img,css),不会部署到同一个服务器上。

    静态资源部署在Nginx上,动态资源部署在Tomcat。

    往往有时候,Nginx也不能满足我们的需求,则我们可以将img,mp4等静态文件存储到七牛云/阿里云OSS上

    可以单独购买CDN实现加速:采用CDN内容分发,能够将静态资源缓存到全国各地节点能够减少客户端与cdn带宽距离传输提高响应速度; 就近原则。

    如果图片过大的情况下,建议将一张大图拆分n多个小图加载;(ps拆分成多个小图) 【分段】

    搞多个图片,多个img,src引入...

    展开全文
  • 双出口nat配置(一主一备

    千次阅读 2015-08-20 18:04:59
    2、实现主备链路切换。 实验配置: 1)各接口IP的配置略,R5上有指向R2的默认路由,接下来主要看R2配置 R2(config)#do sh run interface Ethernet0/0  ip address 1.1.1.2 255.255.255.0  ip na
  • 根据网络情况,可能达到10秒左右的延时,即数据库添加,删除,更新的内容,一般在10秒内就可以同步到备用数据库上。 三分钟的视频操作演示在最下面,不要忘记看了。 1、配置分布发服务器 2、新建发布 3...
  • Oracle DataGuard 一主配置

    千次阅读 2017-09-14 09:01:47
    之前已经写过关于oracle 11g的一主一备的Data Guard的配置,这里就不再赘述,详细请参考: 这里我们将介绍oracle 一主2备的配置过程(红色部分尤其注意) Orcle 主库配置:pfile cebpm.__db_cache_size=47085256704...
  • 主备同步与主备倒换(

    万次阅读 2009-11-12 11:02:00
     转篇高端交换机主备倒换技术:1. 概述 高端交换机由于所处网络位置非常重要,不允许出现单点故障,设备一般都配备两块主控板,分别称为用主控板(Master)和备用主控板(Slave)。 其中,用主控板作为控制...
  • 主备 主从 主主模式

    千次阅读 2019-10-22 11:31:02
    :主机,机。 主机的意思当然是以它为了,读写都是主机上,而机呢就是备用,默默的在背后吸收主机的数据,时刻待命着等待主机挂了之后取而代之(没这么坏哈哈)。因此在主机还活着的情况下...
  • Mysql一主,读写分离

    千次阅读 2018-11-26 10:57:36
    1.主从复制的几种方式 异步复制 master只保证自己的操作完成就返回,至于slaves是否收到...master操作次,需要等待所有的slaves操作完成才可以返回,此方式一般不会采取,因为当前端用户插入条数据时需要很长的...
  • 本章中会讲述一些集群简单配置命令,法定人数概念,配置个VIP服务并且如何防止资源在节点恢复后移动。接着搭建继续来写在搭建完pacemaker之后如果不在里面配置任何服务其实这个东西是完全没有什么用的。那么我们从...
  • Oracle dataguard一主环境搭建

    千次阅读 2016-05-25 14:09:57
    库:Reahat 6.5 x64 + Oracle 11.2.0.3 x64 单机(IP:192.168.6.10 db) DB_UNIQUE_NAME=orcl 库1:Reahat 6.5 x64 + Oracle 11.2.0.3 x64 单机(IP:192.168.6.101 db1) DB_UNIQUE_NAME=dglocal 库2:...
  • postgres主备切换之文件触发方式

    千次阅读 2019-03-27 17:22:53
    本文测试参考PostgresSQL实战一书。 本文档测试环境: 主库IP:192.168.40.130 ...PostgreSQL9.0版本流复制主备切换只能通过创建触发文件方式进行,这一小节将介绍这种主备切换方式,测试环境为一主一备异步流复制...
  • 达梦数据库-实时主备的配置

    千次阅读 2019-09-23 10:56:23
    通常最少需要三台服务器或虚拟机,可部署一主一备集群,另外一台服务器或虚拟机作为确认监视器。本文采用三台虚拟机进行部署,由于机器处于内网环境,因此无公网IP,均采用内网IP。 一、数据准备 注:为了简化搭建...
  • 篇讲到的创建主备复制是假设主备库都为刚刚安装好的数据库,也就是说两台服务器上的数据相同,这不是典型的案例,大多数情况下有个已经运行了段时间的主库,然后用台新安装的库与之同步,本文讲述在这种...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 227,079
精华内容 90,831
关键字:

一主一备