MSSQL 사용자계정 전송

 USE master
 GO
 IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
   DROP PROCEDURE sp_hexadecimal
 GO
 CREATE PROCEDURE sp_hexadecimal
     @binvalue varbinary(256),
     @hexvalue varchar (514) OUTPUT
 AS
 DECLARE @charvalue varchar (514)
 DECLARE @i int
 DECLARE @length int
 DECLARE @hexstring char(16)
 SELECT @charvalue = '0x'
 SELECT @i = 1
 SELECT @length = DATALENGTH (@binvalue)
 SELECT @hexstring = '0123456789ABCDEF'
 WHILE (@i <= @length)
 BEGIN
   DECLARE @tempint int
   DECLARE @firstint int
   DECLARE @secondint int
   SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
   SELECT @firstint = FLOOR(@tempint/16)
   SELECT @secondint = @tempint - (@firstint*16)
   SELECT @charvalue = @charvalue +
     SUBSTRING(@hexstring, @firstint+1, 1) +
     SUBSTRING(@hexstring, @secondint+1, 1)
   SELECT @i = @i + 1
 END
  
 SELECT @hexvalue = @charvalue
 GO
  
 IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
   DROP PROCEDURE sp_help_revlogin
 GO
 CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
 DECLARE @name sysname
 DECLARE @type varchar (1)
 DECLARE @hasaccess int
 DECLARE @denylogin int
 DECLARE @is_disabled int
 DECLARE @PWD_varbinary  varbinary (256)
 DECLARE @PWD_string  varchar (514)
 DECLARE @SID_varbinary varbinary (85)
 DECLARE @SID_string varchar (514)
 DECLARE @tmpstr  varchar (1024)
 DECLARE @is_policy_checked varchar (3)
 DECLARE @is_expiration_checked varchar (3)
  
 DECLARE @defaultdb sysname
  
 IF (@login_name IS NULL)
   DECLARE login_curs CURSOR FOR
  
       SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
 sys.server_principals p LEFT JOIN sys.syslogins l
       ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
 ELSE
   DECLARE login_curs CURSOR FOR
  
  
       SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
 sys.server_principals p LEFT JOIN sys.syslogins l
       ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
 OPEN login_curs
  
 FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
 IF (@@fetch_status = -1)
 BEGIN
   PRINT 'No login(s) found.'
   CLOSE login_curs
   DEALLOCATE login_curs
   RETURN -1
 END
 SET @tmpstr = '/* sp_help_revlogin script '
 PRINT @tmpstr
 SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
 PRINT @tmpstr
 PRINT ''
 WHILE (@@fetch_status <> -1)
 BEGIN
   IF (@@fetch_status <> -2)
   BEGIN
     PRINT ''
     SET @tmpstr = '-- Login: ' + @name
     PRINT @tmpstr
     IF (@type IN ( 'G', 'U'))
     BEGIN -- NT authenticated account/group
  
       SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
     END
     ELSE BEGIN -- SQL Server authentication
         -- obtain password and sid
             SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
         EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
         EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
  
         -- obtain password policy state
         SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
         SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
  
             SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
  
         IF ( @is_policy_checked IS NOT NULL )
         BEGIN
           SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
         END
         IF ( @is_expiration_checked IS NOT NULL )
         BEGIN
           SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
         END
     END
     IF (@denylogin = 1)
     BEGIN -- login is denied access
       SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
     END
     ELSE IF (@hasaccess = 0)
     BEGIN -- login exists but does not have access
       SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
     END
     IF (@is_disabled = 1)
     BEGIN -- login is disabled
       SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
     END
     PRINT @tmpstr
   END
  
   FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
    END
 CLOSE login_curs
 DEALLOCATE login_curs
 RETURN 0
 GO
  
 --------------------------------------------------------------------------------
  
 EXEC sp_help_revlogin 

AlwaysON 복제본 읽기 전용 연결

 

USE master
GO

-- 보조 복제본 읽기 전용 연결 허용 (UI로 변경 가능)
ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR1' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL));
 
-- 읽기 전용 라우팅 URL 지정 
ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR1' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://WS16-AOSVR1:1433'));
 ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR2' WITH (SECONDARY_ROLE (ALLOW_CONNECTIONS = ALL));
 ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR2' WITH
(SECONDARY_ROLE (READ_ONLY_ROUTING_URL = N'TCP://WS16-AOSVR2:1433'));
 
-- 라우팅 우선 순위
ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR1' WITH
(PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('WS16-AOSVR2','WS16-AOSVR1')));
 ALTER AVAILABILITY GROUP [ALG]
MODIFY REPLICA ON N'WS16-AOSVR2' WITH
(PRIMARY_ROLE (READ_ONLY_ROUTING_LIST=('WS16-AOSVR1','WS16-AOSVR2')));
 
-- 설정확인
SELECT ag.name as "Availability Group", ar.replica_server_name as "When Primary Replica Is",
rl.routing_priority as "Routing Priority", ar2.replica_server_name as "RO Routed To",
ar.secondary_role_allow_connections_desc, ar2.read_only_routing_url
FROM sys.availability_read_only_routing_lists rl
inner join sys.availability_replicas ar on rl.replica_id = ar.replica_id
inner join sys.availability_replicas ar2 on rl.read_only_replica_id = ar2.replica_id
inner join sys.availability_groups ag on ar.group_id = ag.group_id
ORDER BY ag.name, ar.replica_server_name, rl.routing_priority

Windows 시간동기화 명령어

AD Join된 서버 및 클라이언트의 시간 동기화 옵션

1. AD서버와 AD Join된 PC또는 서버간의 시간차이 확인

w32tm /monitor /computers:서버 IP

2. AD 서버와 동기화 진행

w32tm /resync /nowait
net stop w32time && net start w32time

3. AD서버와 AD Join된 PC또는 서버간의 시간차이 확인

w32tm /monitor /computers: 서버 IP

• NTP서버(IP:192.168.0.3) 서버를 시스템 시간으로 설정한다.
C:\>w32tm /config /syncfromflags:manual /manualpeerlist:192.168.0.3/update
명령이 성공적으로 완료되었습니다.

• Windows Time 서비스를 재기동한다.
C:\>net stop w32time
Windows Time 서비스를 멈춥니다..
Windows Time 서비스를 잘 멈추었습니다.

C:\>net start w32time
Windows Time 서비스를 시작합니다..
Windows Time 서비스가 잘 시작되었습니다.

• NTP서버(IP:192.168.0.3)로 지정한 서버와 동기화를 요청한다.
C:\>w32tm /resync
로컬 컴퓨터에 다시 동기화 명령을 보내는 중
명령이 성공적으로 완료되었습니다.

• NTP서버(IP:192.168.0.3)와 실행 중인 서버와의 시간차이를 확인한다.
C:\>w32tm /stripchart /dataonly /computer:192.168.0.3
192.168.0.3[192.168.0.3:123] 추적 중
현재 시간은 2012-04-19 오후 22:47:25입니다.
22:47:25, +23.2364090s
22:47:27, +22.7004942s -> 조금씩이지만 차이가 줄어드는 것을 볼 수 있다.(갑자기 크게 바뀌면 유닉스 같은 경우 클러스터가 떨어지는 장애가 발생됨)
22:47:30, +22.1639462s
22:47:32, +21.6430236s
^C -> 중지하기 위해서는 “Ctrl + c”를 누르면 된다.

Setup a napp-it ZFS Storage Server

Step1: Setup your OS ex
see http://omnios.omniti.com/wiki.php/Installation

Step 2: configure you network
enable DHCP or set a fixed ip

Step 3: setup the appliance
run the online installer

wget -O - www.napp-it.org/nappit | perl
 


Please set a password for root and napp-it now (only on permission error messages in 151028)!
passwd root and optionally passwd napp-it

You can now manage the storage server via: http://ip_of_your_server:81

After setup I suggest to clone the bootdisk to an external disk or an SMB/NFS share (can be your desktop) with clonezilla (from USB stick) or with the help of an 3,5″ hardware Sata raid 1 enclosure.  If you care about uptime, do a ZFS boot mirror on two disks.  If you use a hardware raid-1 enclosure, I would use it with its hotplug capability to clone the bootdisk – not for regular raid-use as they are not as good as ZFS mirrors.

Recovery:
In case of problems, try a former BE, use the bootable backup disk or restore from image with clonezilla.