16.2 添加节点和数据库

16.2  添加节点和数据库

16.2.1 添加节点

以上操作,脚本为:


--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.

:Connect SQLSVR3

USE [master]

GO

CREATE LOGIN [LOCALDOMAIN\SQLHAUser] FROM WINDOWS

GO

:Connect SQLSVR1

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [LOCALDOMAIN\SQLHAUser]

GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [LOCALDOMAIN\administrator]

GO

:Connect SQLSVR2

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [LOCALDOMAIN\SQLHAUser]

GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [LOCALDOMAIN\Administrator]

GO

:Connect SQLSVR3

USE [master]

GO

CREATE ENDPOINT [Hadr_endpoint]

AS TCP (LISTENER_PORT = 5022)

FOR DATA_MIRRORING (ROLE = ALL, ENCRYPTION = REQUIRED ALGORITHM AES)

GO

IF (SELECT state FROM sys.endpoints WHERE name = N‘Hadr_endpoint‘) <> 0

BEGIN

ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED

END

GO

use [master]

GO

GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [LOCALDOMAIN\SQLHAUser]

GO

:Connect SQLSVR3

IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name=‘AlwaysOn_health‘)

BEGIN

ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);

END

IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name=‘AlwaysOn_health‘)

BEGIN

ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;

END

GO

:Connect SQLSVR1

USE [master]

GO

ALTER AVAILABILITY GROUP [HAGroup01]

ADD REPLICA ON N‘SQLSVR3‘ WITH (ENDPOINT_URL = N‘TCP://SQLSVR3.LocalDomain.Local:5022‘, FAILOVER_MODE = MANUAL, AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT, BACKUP_PRIORITY = 50, SECONDARY_ROLE(ALLOW_CONNECTIONS = NO));

GO

:Connect SQLSVR3

ALTER AVAILABILITY GROUP [HAGroup01] JOIN;

GO

:Connect SQLSVR1

BACKUP DATABASE [SQLDB01] TO  DISK = N‘\\SQLSVR1\HAGroup\SQLDB01.bak‘ WITH  COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 5

GO

:Connect SQLSVR3

RESTORE DATABASE [SQLDB01] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB01.bak‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR1

BACKUP LOG [SQLDB01] TO  DISK = N‘\\SQLSVR1\HAGroup\SQLDB01_20150613040532.trn‘ WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 5

GO

:Connect SQLSVR3

RESTORE LOG [SQLDB01] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB01_20150613040532.trn‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR3

-- Wait for the replica to start communicating

begin try

declare @conn bit

declare @count int

declare @replica_id uniqueidentifier

declare @group_id uniqueidentifier

set @conn = 0

set @count = 30 -- wait for 5 minutes

if (serverproperty(‘IsHadrEnabled‘) = 1)

and (isnull((select member_state from master.sys.dm_hadr_cluster_members where upper(member_name COLLATE Latin1_General_CI_AS) = upper(cast(serverproperty(‘ComputerNamePhysicalNetBIOS‘) as nvarchar(256)) COLLATE Latin1_General_CI_AS)), 0) <> 0)

and (isnull((select state from master.sys.database_mirroring_endpoints), 1) = 0)

begin

select @group_id = ags.group_id from master.sys.availability_groups as ags where name = N‘HAGroup01‘

select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id

while @conn <> 1 and @count > 0

begin

set @conn = isnull((select connected_state from master.sys.dm_hadr_availability_replica_states as states where states.replica_id = @replica_id), 1)

if @conn = 1

begin

-- exit loop when the replica is connected, or if the query cannot find the replica status

break

end

waitfor delay ‘00:00:10‘

set @count = @count - 1

end

end

end try

begin catch

-- If the wait loop fails, do not stop execution of the alter database statement

end catch

ALTER DATABASE [SQLDB01] SET HADR AVAILABILITY GROUP = [HAGroup01];

GO

GO

16.2.2 添加数据库

以上操作,脚本为:


--- YOU MUST EXECUTE THE FOLLOWING SCRIPT IN SQLCMD MODE.

:Connect SQLSVR1

USE [master]

GO

ALTER AVAILABILITY GROUP [HAGroup01]

ADD DATABASE [SQLDB02];

GO

:Connect SQLSVR1

BACKUP DATABASE [SQLDB02] TO  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02.bak‘ WITH  COPY_ONLY, FORMAT, INIT, SKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 5

GO

:Connect SQLSVR2

RESTORE DATABASE [SQLDB02] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02.bak‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR3

RESTORE DATABASE [SQLDB02] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02.bak‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR1

BACKUP LOG [SQLDB02] TO  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02_20150613041128.trn‘ WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, COMPRESSION,  STATS = 5

GO

:Connect SQLSVR2

RESTORE LOG [SQLDB02] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02_20150613041128.trn‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR2

-- Wait for the replica to start communicating

begin try

declare @conn bit

declare @count int

declare @replica_id uniqueidentifier

declare @group_id uniqueidentifier

set @conn = 0

set @count = 30 -- wait for 5 minutes

if (serverproperty(‘IsHadrEnabled‘) = 1)

and (isnull((select member_state from master.sys.dm_hadr_cluster_members where upper(member_name COLLATE Latin1_General_CI_AS) = upper(cast(serverproperty(‘ComputerNamePhysicalNetBIOS‘) as nvarchar(256)) COLLATE Latin1_General_CI_AS)), 0) <> 0)

and (isnull((select state from master.sys.database_mirroring_endpoints), 1) = 0)

begin

select @group_id = ags.group_id from master.sys.availability_groups as ags where name = N‘HAGroup01‘

select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id

while @conn <> 1 and @count > 0

begin

set @conn = isnull((select connected_state from master.sys.dm_hadr_availability_replica_states as states where states.replica_id = @replica_id), 1)

if @conn = 1

begin

-- exit loop when the replica is connected, or if the query cannot find the replica status

break

end

waitfor delay ‘00:00:10‘

set @count = @count - 1

end

end

end try

begin catch

-- If the wait loop fails, do not stop execution of the alter database statement

end catch

ALTER DATABASE [SQLDB02] SET HADR AVAILABILITY GROUP = [HAGroup01];

GO

:Connect SQLSVR3

RESTORE LOG [SQLDB02] FROM  DISK = N‘\\SQLSVR1\HAGroup\SQLDB02_20150613041128.trn‘ WITH  NORECOVERY,  NOUNLOAD,  STATS = 5

GO

:Connect SQLSVR3

-- Wait for the replica to start communicating

begin try

declare @conn bit

declare @count int

declare @replica_id uniqueidentifier

declare @group_id uniqueidentifier

set @conn = 0

set @count = 30 -- wait for 5 minutes

if (serverproperty(‘IsHadrEnabled‘) = 1)

and (isnull((select member_state from master.sys.dm_hadr_cluster_members where upper(member_name COLLATE Latin1_General_CI_AS) = upper(cast(serverproperty(‘ComputerNamePhysicalNetBIOS‘) as nvarchar(256)) COLLATE Latin1_General_CI_AS)), 0) <> 0)

and (isnull((select state from master.sys.database_mirroring_endpoints), 1) = 0)

begin

select @group_id = ags.group_id from master.sys.availability_groups as ags where name = N‘HAGroup01‘

select @replica_id = replicas.replica_id from master.sys.availability_replicas as replicas where upper(replicas.replica_server_name COLLATE Latin1_General_CI_AS) = upper(@@SERVERNAME COLLATE Latin1_General_CI_AS) and group_id = @group_id

while @conn <> 1 and @count > 0

begin

set @conn = isnull((select connected_state from master.sys.dm_hadr_availability_replica_states as states where states.replica_id = @replica_id), 1)

if @conn = 1

begin

-- exit loop when the replica is connected, or if the query cannot find the replica status

break

end

waitfor delay ‘00:00:10‘

set @count = @count - 1

end

end

end try

begin catch

-- If the wait loop fails, do not stop execution of the alter database statement

end catch

ALTER DATABASE [SQLDB02] SET HADR AVAILABILITY GROUP = [HAGroup01];

GO

GO

时间: 2024-10-18 09:36:03

16.2 添加节点和数据库的相关文章

delphi TreeView 从数据库添加节点的四种方法

方法一:delphi中递归算法构建treeView 过程:通过读取数据库中table1的数据,来构建一颗树.table1有两个字段:ID,preID,即当前结点标志和父结点标志.所以整个树的表示为父母表示法.本递归算法不难写,但是要注意:程序内部的变量都应使用局部变量!比如当Query是外部变量(函数外定义或者直接通过控件拖拽得来)时就会得到错误的结果.代码如下: unit Unit1; interface uses  Windows, Messages, SysUtils, Variants,

Oracle 11gR2 RAC 添加节点

1. 概述 生产,测试数据库添加节点. 2. 安装前准备 1.首先,物理链路的准备.这过程包括对db3进行存储映射.心跳互联等物理环境的准备: 2.根据db1.db2的操作系统配置,安装.配置db3的操作系统:注意此处需要配置的操作系统内容较多.大致包括确认RAC需要的系统安装包.系统核心参数配置.ASMLIB的配置./etc/hosts配置等等.详细可参考官方的安装指导手册. 3.根据db1.db2的操作系统组.用户的信息,在db3上创建相应的组.用户:创建对于的目录信息:注意:创建的组.用户

rac 10g 添加节点详解

目标: 当前我环境中是有两个节点RAC1 和RAC2 节点,现在增加一个RAC3节点.   概要:为现有的Oracle10g RAC 添加节点大致包括以下步骤: 1. 配置新的服务器节点上的硬件及操作系统环境 2. 向 Cluster 集群中加入该节点 3. 在新节点上安装 Oracle Database software 4. 为新的节点配置监听器 LISTENER 5. 通过 DBCA 为新的节点添加实例   注意:在新的服务器节点上配置操作系统环境 1. 这包括配置该节点今后使用的 pub

orcle 11g rac crs状态正常,节点2数据库未启动

orcle 11g rac crs状态正常,节点2数据库未启动 安装完oracle11g R2 rac后,在节点1上查看数据库状态: [[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed May 17 18:56:34 2017 Copyright (c) 1982, 2013, Oracle.  All rights reserved. Connected to: Or

Redis 集群环境添加节点失败问题

最近在给公司网管系统Redis集群环境添加节点时候遇到一个问题,提示新增的Node不为空: [[email protected] src]# ./redis-trib.rb add-node --slave --master-id4f6424e47a2275d2b7696bfbf8588e8c4c3a5b95 172.168.63.202:7001172.168.63.202:7000 ...... [OK] All nodes agree about slotsconfiguration. >

实验:Oracle单节点RAC添加节点

环境:RHEL 6.5 + Oracle 11.2.0.4 单节点RAC 需求:单节点RAC添加新节点 1.添加节点前的准备工作 2.正式添加节点 3.其他配置工作 1.添加节点前的准备工作 参考Oracle官方文档: Oracle? Clusterware Administration and Deployment Guide 11g Release 2 (11.2) -> Adding and Deleting Cluster Nodes 1.1 确保硬件连接正常 1.1 Make phys

js实现在末尾添加节点

在末尾添加节点: 1.获取ul标签 2.创建li标签 document.createElement("标签名称")方法 3.创建文本 document.createTextNode("文本内容"); 4.把文本添加到li下面 使用 appendChild方法 5.把添加到ul的末尾 使用 appendChild方法 <html> <head> <title>HTML示例</title> <style type=&

JS添加节点方法与JQuery添加节点方法的比较及总结

原生JS添加节点方法与JQuery添加节点方法的比较及总结 一.首先构建一个简单布局,来供下边讲解使用 1.HTML部分代码: <div id="div1">div1</div> <div id="div2">div2 <span id="span1">span1</span> <span id="span2">span2</span> <

16.3 添加侦听器

16.3  添加侦听器 16.3.1 添加侦听器 在 SSMS 中,右键单击"可用性组侦听器",然后在右键菜单中选择"添加侦听器". "在新的可用性组侦听器"窗口,为侦听器指定 DNS 名称.端口(实例当前使用的端口).IP 地址. 添加完成后,在"可用性组侦听器"中将列出已有的侦听器. 上述操作,脚本为: USE [master] GO ALTER AVAILABILITY GROUP [HAGroup01] ADD LIS