IT Soldier Sakuri !!

Oracle使い。いつのまにかIT戦士になってしまったさくりの可哀想な奮闘記。

WSUS(WindowsServerUpdateService)が接続エラーとなってKBが表示できない!

だいぶ遅くなってしまいましたが、あけましておめでとうございます。
本年もどうぞよろしくお願いします。

新年早々…というか実は年末からなんですけど、
WSUS(WindowsServerUpdateService)の調子が悪い(;´д`)

うちはこんな感じで更新プログラムを配信してるんだけど、
・更新プログラムが公表されたら、システム部全員に配信する。
・2週間ほどシステム部全員が問題なければ、全ユーザに配信する。

[すべての更新プログラム]で[承認済み]を[すべて]表示させようとすると、
f:id:itsoldiersakuri:20160111155325p:plain
こんな感じで[エラー:接続エラー]となってしまって表示できない。
f:id:itsoldiersakuri:20160124195806p:plain
何度やってもダメ。

どうやら更新プログラムが多すぎて表示させるのにタイムアウトになってるっぽい。
35,000件くらいでそれってどうなんだろう。


だが、いきなり全ユーザに更新プログラムは配信したくない。
(正直更新プログラムにバグが多すぎて信じられないのです。)

な、なんとかしなくては…
だって、実は12月の更新プログラム当ててないんだもの。

対応策としては順番的にこんな感じです。

①もう使用しない累積更新を削除
下記サイトの「A. 過去の「IE の累積的なセキュリティ更新プログラム」を WSUS 上で拒否済みに設定」を実施。
「IE の累積的なセキュリティ更新プログラム」が承認されていると、更新プログラムの検出処理時に WSUS クライアントの CPU 使用率が高くなる - Japan WSUS Support Team Blog - Site Home - TechNet Blogs
だってもうIE6とかIE7とかの更新はいらないもんね。
もう少ししたら、IE8とかWindowsXPとかの更新も拒否できる!!!

②クリーンアップウィザードの実行
 正直これは毎月実施した方がいいと思う。
 たまれば溜まる程、時間がかかるし、タイムアウトで何もできなくなる可能性がある。

1.サーバーマネージャーより[役割]-[WindowsServerUpdateServices]-[UpdateServices]-[オプション]を選択し、[サーバークリーンアップウィザード]をクリックする。
f:id:itsoldiersakuri:20160124185350p:plain

2.全✔のまま[次へ]
 ※当ててない更新とかがあっても大丈夫!消えたりしないよ!
f:id:itsoldiersakuri:20160124185423p:plain


③インデックスの更新
詳細はコチラ。
WSUS DB インデックスの再構成の手順について - Japan WSUS Support Team Blog - Site Home - TechNet Blogs


1.UAC(ユーザー アカウント制御)をOFFにしないと絶対エラーになるので注意!
UACをOFFにするには、コンパネで「UAC」と検索して、OFFに。
f:id:itsoldiersakuri:20160124185950p:plain

2.「SQL Server Management Studio Express」をインストール。
Download Microsoft SQL Server Management Studio Express from Official Microsoft Download Center

3.SQL Server Management Studio Expressをクリック。
f:id:itsoldiersakuri:20160124190925p:plain

4.サーバー名は下記をコピペして、認証:[Windows 認証]を選択し、[接続]ボタンをクリックする。
\\.\pipe\mssql$microsoft##ssee\sql\query
f:id:itsoldiersakuri:20160124190947p:plain

5.[データベース]-[SUSDB]を右クリックし、[新しいクエリ]を選択する。
f:id:itsoldiersakuri:20160124191031p:plain

6.右の欄に下記のテキストを貼りつけて、[実行]ボタンをクリックする。
※実行時間は2分くらい?

f:id:itsoldiersakuri:20160124191050p:plain

/****************************************************************************** 
This sample T-SQL script performs basic maintenance tasks on SUSDB 
1. Identifies indexes that are fragmented and defragments them. For certain 
   tables, a fill-factor is set in order to improve insert performance. 
   Based on MSDN sample at http://msdn2.microsoft.com/en-us/library/ms188917.aspx 
   and tailored for SUSDB requirements 
2. Updates potentially out-of-date table statistics. 
******************************************************************************/ 
 
USE SUSDB; 
GO 
SET NOCOUNT ON; 
 
-- Rebuild or reorganize indexes based on their fragmentation levels 
DECLARE @work_to_do TABLE ( 
    objectid int 
    , indexid int 
    , pagedensity float 
    , fragmentation float 
    , numrows int 
) 
 
DECLARE @objectid int; 
DECLARE @indexid int; 
DECLARE @schemaname nvarchar(130);  
DECLARE @objectname nvarchar(130);  
DECLARE @indexname nvarchar(130);  
DECLARE @numrows int 
DECLARE @density float; 
DECLARE @fragmentation float; 
DECLARE @command nvarchar(4000);  
DECLARE @fillfactorset bit 
DECLARE @numpages int 
 
-- Select indexes that need to be defragmented based on the following 
-- * Page density is low 
-- * External fragmentation is high in relation to index size 
PRINT 'Estimating fragmentation: Begin. ' + convert(nvarchar, getdate(), 121)  
INSERT @work_to_do 
SELECT 
    f.object_id 
    , index_id 
    , avg_page_space_used_in_percent 
    , avg_fragmentation_in_percent 
    , record_count 
FROM  
    sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'SAMPLED') AS f 
WHERE 
    (f.avg_page_space_used_in_percent < 85.0 and f.avg_page_space_used_in_percent/100.0 * page_count < page_count - 1) 
    or (f.page_count > 50 and f.avg_fragmentation_in_percent > 15.0) 
    or (f.page_count > 10 and f.avg_fragmentation_in_percent > 80.0) 
 
PRINT 'Number of indexes to rebuild: ' + cast(@@ROWCOUNT as nvarchar(20)) 
 
PRINT 'Estimating fragmentation: End. ' + convert(nvarchar, getdate(), 121) 
 
SELECT @numpages = sum(ps.used_page_count) 
FROM 
    @work_to_do AS fi 
    INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id 
    INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id 
 
-- Declare the cursor for the list of indexes to be processed. 
DECLARE curIndexes CURSOR FOR SELECT * FROM @work_to_do 
 
-- Open the cursor. 
OPEN curIndexes 
 
-- Loop through the indexes 
WHILE (1=1) 
BEGIN 
    FETCH NEXT FROM curIndexes 
    INTO @objectid, @indexid, @density, @fragmentation, @numrows; 
    IF @@FETCH_STATUS < 0 BREAK; 
 
    SELECT  
        @objectname = QUOTENAME(o.name) 
        , @schemaname = QUOTENAME(s.name) 
    FROM  
        sys.objects AS o 
        INNER JOIN sys.schemas as s ON s.schema_id = o.schema_id 
    WHERE  
        o.object_id = @objectid; 
 
    SELECT  
        @indexname = QUOTENAME(name) 
        , @fillfactorset = CASE fill_factor WHEN 0 THEN 0 ELSE 1 END 
    FROM  
        sys.indexes 
    WHERE 
        object_id = @objectid AND index_id = @indexid; 
 
    IF ((@density BETWEEN 75.0 AND 85.0) AND @fillfactorset = 1) OR (@fragmentation < 30.0) 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REORGANIZE'; 
    ELSE IF @numrows >= 5000 AND @fillfactorset = 0 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD WITH (FILLFACTOR = 90)'; 
    ELSE 
        SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname + N'.' + @objectname + N' REBUILD'; 
    PRINT convert(nvarchar, getdate(), 121) + N' Executing: ' + @command; 
    EXEC (@command); 
    PRINT convert(nvarchar, getdate(), 121) + N' Done.'; 
END 
 
-- Close and deallocate the cursor. 
CLOSE curIndexes; 
DEALLOCATE curIndexes; 
 
 
IF EXISTS (SELECT * FROM @work_to_do) 
BEGIN 
    PRINT 'Estimated number of pages in fragmented indexes: ' + cast(@numpages as nvarchar(20)) 
    SELECT @numpages = @numpages - sum(ps.used_page_count) 
    FROM 
        @work_to_do AS fi 
        INNER JOIN sys.indexes AS i ON fi.objectid = i.object_id and fi.indexid = i.index_id 
        INNER JOIN sys.dm_db_partition_stats AS ps on i.object_id = ps.object_id and i.index_id = ps.index_id 
 
    PRINT 'Estimated number of pages freed: ' + cast(@numpages as nvarchar(20)) 
END 
GO 
 
 
--Update all statistics 
PRINT 'Updating all statistics.' + convert(nvarchar, getdate(), 121)  
EXEC sp_updatestats 
PRINT 'Done updating statistics.' + convert(nvarchar, getdate(), 121)  
GO 


7.下記メッセージが出たらOK。画面を全て閉じる。
f:id:itsoldiersakuri:20160124191659p:plain

とりあえず、これでなんとか解決。
WSUSって意外にチャチいし、お守りがめんどくさいのよね。。。