Windows8.1クリーンインストールでWindowsUpdate失敗

Windows8.1クリーンインストールでWindowsUpdateに失敗する。

何度やっても同様。PCリカバリーを実行してWindowsUpdate行っても、1回のWindowsUpdate以外は「Windowsは最新です。」とか「更新するセキュリティはありません」というエラーになってしまう。

それも1時間以上Windowsupdateが終わらなかったり・・・・・(p>□<q*))

色々とやってみて解決方法がわかったので、忘れないうちに記載します。

①google検索で「KB3138615」で検索、Microsoftサイトから日本語のKB3138615パッチを事前にダウンロードする
②WindowsUpdateサービスを停止する
③KB3138615パッチ「自分が利用したファイル名はWindows8.1-KB3138615-x64.msu」を実行する
④OS再起動

以上の手順でWindowsupdateが正常になりました。

つまり、Windowsupdateソフトを最新にする必要があるという落ちなんですが・・・
半年前までは不要だったと思ったんだけどなぁ。

Windowsでsquid

squidは普通Linuxで利用するソフトだと思いますが、、自分はWindowsで利用しています。理由は察してください。

Windowsで利用している人は少ないようで、チューニングやちょっとした運用方法方法を忘れないように記載します。インストール方法は気が向いたら書きますが、そんなに難しくないのでチャレンジしてみてください。

まずは自分が使っているsquid for windows 設定ファイル

#
# Recommended minimum configuration:
## Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowedacl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
#http_port 3128
http_port 8080

# Uncomment the line below to enable disk caching – path format is /cygdrive/, i.e.
#cache_dir aufs /cygdrive/d/squid/cache 3000 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/cache/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

#hostsファイルの参照を有効化
hosts_file C:\Windows\System32\drivers\etc\hosts

dns_nameservers 9.9.9.9 208.67.222.123

max_filedescriptors 3200

#2018/12/21 追記
cache_mem 2500 MB
cache_dir aufs D:\Squid\var\cache\squid 60000 64 1024

自分は「パブリックDNS Quad9」と「Open DNS」を設定して、DNSレベルで悪性と判定されるサイトには接続できないようにしています。それでも、たまに「Windowsが壊れてます広告」サイトに接続出来てしまうけど。

あと、Windowsでも必ずcacheは設定してください。自分が管理している仮想サーバでは、設定しないときにはCPUパワーが50%くらい使っていましたが、設定すると5%に落ちました。

上記設定で問題ないかどうか、設定確認を行います。

#設定確認
D:\Squid>Squid.exe -k parse
2018/12/20 13:41:23| Startup: Initializing Authentication Schemes …
2018/12/20 13:41:23| Startup: Initialized Authentication Scheme ‘basic’
2018/12/20 13:41:23| Startup: Initialized Authentication Scheme ‘digest’
2018/12/20 13:41:23| Startup: Initialized Authentication Scheme ‘negotiate’
2018/12/20 13:41:23| Startup: Initialized Authentication Scheme ‘ntlm’
2018/12/20 13:41:23| Startup: Initialized Authentication.
2018/12/20 13:41:23| Processing Configuration File: /etc/squid/squid.conf (depth
0)
2018/12/20 13:41:23| Processing: acl localnet src 10.0.0.0/8 # RFC1918 possib
le internal network
2018/12/20 13:41:23| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possib
le internal network
2018/12/20 13:41:23| Processing: acl localnet src 192.168.0.0/16 # RFC191
8 possible internal network
2018/12/20 13:41:23| Processing: acl localnet src fc00::/7 # RFC 4193 loca
l private network range
2018/12/20 13:41:23| Processing: acl localnet src fe80::/10 # RFC 4291 link
-local (directly plugged) machines
2018/12/20 13:41:23| Processing: acl SSL_ports port 443
2018/12/20 13:41:23| Processing: acl Safe_ports port 80 # http
2018/12/20 13:41:23| Processing: acl Safe_ports port 21 # ftp
2018/12/20 13:41:23| Processing: acl Safe_ports port 443 # https
2018/12/20 13:41:23| Processing: acl Safe_ports port 70 # gopher
2018/12/20 13:41:23| Processing: acl Safe_ports port 210 # wais
2018/12/20 13:41:23| Processing: acl Safe_ports port 1025-65535 # unregistered p
orts
2018/12/20 13:41:23| Processing: acl Safe_ports port 280 # http-m
gmt
2018/12/20 13:41:23| Processing: acl Safe_ports port 488 # gss-ht
tp
2018/12/20 13:41:23| Processing: acl Safe_ports port 591 # filema
ker
2018/12/20 13:41:23| Processing: acl Safe_ports port 777 # multil
ing http
2018/12/20 13:41:23| Processing: acl CONNECT method CONNECT
2018/12/20 13:41:23| Processing: http_access allow localhost manager
2018/12/20 13:41:23| Processing: http_access deny manager
2018/12/20 13:41:23| Processing: http_access deny !Safe_ports
2018/12/20 13:41:23| Processing: http_access deny CONNECT !SSL_ports
2018/12/20 13:41:23| Processing: http_access allow localnet
2018/12/20 13:41:23| Processing: http_access allow localhost
2018/12/20 13:41:23| Processing: http_access deny all
2018/12/20 13:41:23| Processing: http_port 8080
2018/12/20 13:41:23| Processing: coredump_dir /var/cache/squid
2018/12/20 13:41:23| Processing: refresh_pattern ^ftp: 1440 20%100802018/12/20 13:41:23| Processing: refresh_pattern ^gopher: 1440 0%1440
2018/12/20 13:41:23| Processing: refresh_pattern -i (/cgi-bin/|\?) 0 0%0
2018/12/20 13:41:23| Processing: refresh_pattern . 0 20%4320
2018/12/20 13:41:23| Processing: hosts_file C:\Windows\System32\drivers\etc\host
s
2018/12/20 13:41:23| Processing: dns_nameservers 9.9.9.9 208.67.222.123
2018/12/20 13:41:23| Processing: max_filedescriptors 3200
2018/12/20 13:41:23| Processing: cache_mem 64 MB
2018/12/20 13:41:23| Processing: cache_dir aufs D:\Squid\var\cache\squid 400 64 1024
2018/12/20 13:41:23| Initializing https proxy context

D:\Squid>

 

問題ないのでキャッシュを作成します。作成前には必ずsquidを停止する必要があります。

キャッシュを作成する
D:\Squid>Squid.exe -z

 

キャッシュ作成はサービス停止中にコマンド実行されたら自動で行われます。自分はキャッシュ作成時は大体30秒程度待ってます。作成されたらコマンドプロンプトからサービスを起動しましょう。(サービス一覧からの起動でも問題ない)

#コマンドプロンプトから起動する場合
net start squidsrv#コマンドプロンプトから終了する場合
net stop squidsrv

 

起動したら情報を確認します。ポート番号を変更しているので「-pオプション」を使用します。

D:\Squid>bin\squidclient.exe -p 8080 mgr:info
HTTP/1.1 200 OK
Server: squid/3.5.19
Mime-Version: 1.0
Date: Thu, 20 Dec 2018 04:38:18 GMT
Content-Type: text/plain;charset=utf-8
Expires: Thu, 20 Dec 2018 04:38:18 GMT
Last-Modified: Thu, 20 Dec 2018 04:38:18 GMT
X-Cache: MISS from squid
Via: 1.1 squid (squid/3.5.19)
Connection: close

Squid Object Cache: Version 3.5.19
Build Info:
Service Name: squid
Start Time: Thu, 20 Dec 2018 04:36:16 GMT
Current Time: Thu, 20 Dec 2018 04:38:18 GMT
Connection information for squid:
Number of clients accessing cache: 87
Number of HTTP requests received: 1984
Number of ICP messages received: 0
Number of ICP messages sent: 0
Number of queued ICP replies: 0
Number of HTCP messages received: 0
Number of HTCP messages sent: 0
Request failure ratio: 0.00
Average HTTP requests per minute since start: 975.8
Average ICP messages per minute since start: 0.0
Select loop called: 6249 times, 19.522 ms avg
Cache information for squid:
Hits as % of all requests: 5min: 0.0%, 60min: 0.0%
Hits as % of bytes sent: 5min: 0.3%, 60min: 0.3%
Memory hits as % of hit requests: 5min: 0.0%, 60min: 0.0%
Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.0%
Storage Swap size: 3488 KB
Storage Swap capacity: 0.9% used, 99.1% free
Storage Mem size: 3700 KB
Storage Mem capacity: 5.6% used, 94.4% free
Mean Object Size: 14.84 KB
Requests given to unlinkd: 0
Median Service Times (seconds) 5 min 60 min:
HTTP Requests (All): 0.64968 0.64968
Cache Misses: 0.19742 0.19742
Cache Hits: 0.00000 0.00000
Near Hits: 0.00000 0.00000
Not-Modified Replies: 0.00000 0.00000
DNS Lookups: 0.19488 0.19488
ICP Queries: 0.00000 0.00000
Resource usage for squid:
UP Time: 121.990 seconds
CPU Time: 10.687 seconds
CPU Usage: 8.76%
CPU Usage, 5 minute avg: 8.89%
CPU Usage, 60 minute avg: 8.89%
Maximum Resident Size: 3918592 KB
Page faults with physical i/o: 15497
Memory accounted for:
Total accounted: 12331 KB
memPoolAlloc calls: 295752
memPoolFree calls: 304574
File descriptor usage for squid:
Maximum number of file descriptors: 3200
Largest file desc currently in use: 762
Number of file desc currently in use: 618
Files queued for open: 0
Available number of file descriptors: 2582
Reserved number of file descriptors: 100
Store Disk files open: 0
Internal Data Structures:
287 StoreEntries
287 StoreEntries with MemObjects
286 Hot Object Cache Items
235 on-disk objects

D:\Squid>

問題なければ、これで終わりです。

 

ちなみに・・・・自分が利用しているバージョンではプロキシサーバに「127.0.0.1」を投げるとサービスが応答しない状態になります。(他のバージョンでは検証してないのでわかりません)

D:\Squid>bin\squidclient.exe -p 8080 mgr:info
ERROR: Cannot connect to [::1]:8080

よって5分に1回サービス確認バッチをタスクスケジューラより実行して、停止したら再起動を行うようにしてます。

#サービスがこけた時に再起動するためのバッチ(squid_srv.bat)
@echo off
set LOGFILE=C:\bat\squid_srv.log

D:\Squid\bin\squidclient.exe -p 8080 mgr:info
if ERRORLEVEL 1 GOTO NG
if ERRORLEVEL 0 GOTO OK

:NG
echo; 1>> %LOGFILE%
echo ※squid restart※ 1>> %LOGFILE%
echo %date%-%time:~0,-3% FAILED 1>> %LOGFILE%
net stop squidsrv
D:\Squid\bin\Squid.exe -z
timeout 10
net start squidsrv
echo ※END※ 1>> %LOGFILE%
exit /b 1

:OK
REM echo %date%-%time:~0,-3% SUCCESS 1>> %LOGFILE%
REM echo ※END※ 1>> %LOGFILE%
exit /b 0

 

上記バッチはある方が良いけど、やっぱり暫定対処だと考えてます。なので127.0.0.1パケットを発信しているPCを見かけたら
「localhost/127.0.0.1」を例外に設定し、squidの停止原因にならないように変更を行ってます。

あと、ログローテーションは下記バッチを実行することで対応できます。引数を入れたらPAUSEが利かないようになってます。タスクスケジューラから実行するときは引数をなにか設定(例えば1など)してポーズが聞かないようにしてください。

#1日1回実行してsquidログローテーションする(squid_log.bat)
d:
cd D:\Squid\bin
squid -n squidsrv -k rotate

IF “%1” EQU “” (
PAUSE
)

 

サービスを1日1回再起動するなら下記バッチを実行すればよいです。(原因が判明してからは利用してない)

#1日1回再起動バッチ(squid_reboot.bat)
net stop squidsrv
D:\Squid\bin\Squid.exe -z
timeout 60
net start squidsrv

IF “%1” EQU “” (
PAUSE
)

これで安定してくれればうれしいなぁ。。。。