質問編集履歴
2
軽度の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -190,7 +190,7 @@
|
|
190
190
|
|
191
191
|
エンコード
|
192
192
|
|
193
|
-
|
193
|
+
-Encoding default
|
194
194
|
|
195
195
|
$conf | Out-file $conf_path[1] -Encoding default
|
196
196
|
|
@@ -228,15 +228,15 @@
|
|
228
228
|
|
229
229
|
zipファイル削除
|
230
230
|
|
231
|
-
|
231
|
+
Remove-Item $zip[1] -Recurse
|
232
232
|
|
233
233
|
binファイル削除
|
234
234
|
|
235
|
-
|
235
|
+
Remove-Item $folder[1] -Recurse
|
236
236
|
|
237
237
|
confファイル削除
|
238
238
|
|
239
|
-
|
239
|
+
Remove-Item $folder[2] -Recurse
|
240
240
|
|
241
241
|
|
242
242
|
|
1
コマンドを全文掲載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,54 +22,154 @@
|
|
22
22
|
|
23
23
|
###引数
|
24
24
|
|
25
|
+
#####ユーザーが設定する
|
26
|
+
|
27
|
+
$IP = "**.**.**.**"
|
28
|
+
|
29
|
+
$log_path = "c:\zabbix\zabbix_agentd.log"
|
30
|
+
|
31
|
+
$Metadata = "windows2008"
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
#####以下本文
|
36
|
+
|
37
|
+
フォルダパス
|
38
|
+
|
39
|
+
$folder = @("C:\zabbix\","C:\zabbix\bin","C:\zabbix\conf")
|
40
|
+
|
41
|
+
フォルダ作成
|
42
|
+
|
43
|
+
New-Item $folder[0] -ItemType Directory
|
44
|
+
|
45
|
+
|
46
|
+
|
25
47
|
位置パス定義
|
26
48
|
|
49
|
+
現在のスクリプトパス
|
50
|
+
|
27
51
|
$file_path = (Convert-Path .)
|
28
52
|
|
53
|
+
標準出力に表示
|
54
|
+
|
55
|
+
Write-Host $file_path
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
スクリプト出力ログ
|
60
|
+
|
61
|
+
Start-Transcript -Path ($file_path+"\zabbixAgentインストール.log")
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
ファイルパス
|
66
|
+
|
67
|
+
zipファイル
|
68
|
+
|
69
|
+
$zip = @(($file_path+"\Desktop\zabbix_agents.zip"),"C:\zabbix\zabbix_agents.zip")
|
70
|
+
|
71
|
+
exe:移動前/移動後
|
72
|
+
|
73
|
+
$exe_path = @("C:\zabbix\bin\zabbix_agentd.exe","C:\zabbix\zabbix_agentd.exe")
|
74
|
+
|
75
|
+
conf:移動前/移動後
|
76
|
+
|
77
|
+
$conf_path = @("C:\zabbix\conf\zabbix_agentd.conf","C:\zabbix\zabbix_agentd.conf")
|
78
|
+
|
79
|
+
|
80
|
+
|
29
|
-
confファイル用
|
81
|
+
#####confファイル用
|
82
|
+
|
83
|
+
log
|
30
84
|
|
31
85
|
$LogFile = @("LogFile=c:\zabbix_agentd.log",("LogFile="+$log_path))
|
32
86
|
|
87
|
+
|
88
|
+
|
33
89
|
zabbixIPアドレス
|
34
90
|
|
35
91
|
$Server = @("Server=127.0.0.1",("Server="+$IP))
|
36
92
|
|
37
|
-
アクティブZabbixサーバIP
|
38
|
-
|
39
93
|
$ServerActive =@("ServerActive=127.0.0.1",("ServerActive="+$IP))
|
40
94
|
|
95
|
+
|
96
|
+
|
41
97
|
hostname
|
42
98
|
|
43
99
|
$Hostname = "Hostname=Windows host"
|
44
100
|
|
101
|
+
|
102
|
+
|
45
103
|
メタデータ
|
46
104
|
|
47
105
|
$HostMetadata = @("# HostMetadata=",("# HostMetadata=`r`n`r`nHostMetadata="+$Metadata))
|
48
106
|
|
49
107
|
|
50
108
|
|
109
|
+
#####処理開始
|
110
|
+
|
111
|
+
zipファイル移動
|
112
|
+
|
113
|
+
Move-Item $zip[0] $zip[1]
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
解凍
|
118
|
+
|
119
|
+
$file = $zip[1]
|
120
|
+
|
121
|
+
$shell = New-Object -ComObject shell.application
|
122
|
+
|
123
|
+
$zip_file = $shell.NameSpace($file)
|
124
|
+
|
125
|
+
$dest = $shell.NameSpace((Split-Path $file -Parent))
|
126
|
+
|
127
|
+
$dest.CopyHere($zip_file.Items())
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
exeファイル配置
|
132
|
+
|
133
|
+
Move-Item $exe_path[0] $exe_path[1]
|
134
|
+
|
135
|
+
confフォルダ配置
|
136
|
+
|
137
|
+
Move-Item $conf_path[0] $conf_path[1]
|
138
|
+
|
139
|
+
|
140
|
+
|
51
|
-
|
141
|
+
confファイル書き換え
|
142
|
+
|
143
|
+
-Encoding UTF8
|
52
144
|
|
53
145
|
$conf= Get-Content $conf_path[1] -Encoding UTF8
|
54
146
|
|
147
|
+
|
148
|
+
|
55
149
|
zabbixサーバ設定
|
56
150
|
|
57
151
|
$conf = $(Get-Content $conf_path[1]) -replace $Server[0],$Server[1]
|
58
152
|
|
59
153
|
$conf > $conf_path[1]
|
60
154
|
|
155
|
+
|
156
|
+
|
61
157
|
Zabbixアクティブサーバ設定
|
62
158
|
|
63
159
|
$conf = $(Get-Content $conf_path[1]) -replace $ServerActive[0],$ServerActive[1]
|
64
160
|
|
65
161
|
$conf > $conf_path[1]
|
66
162
|
|
163
|
+
|
164
|
+
|
67
165
|
Logファイル設定
|
68
166
|
|
69
167
|
$conf = $(Get-Content $conf_path[1]) -replace $LogFile[0],$LogFile[1]
|
70
168
|
|
71
169
|
$conf > $conf_path[1]
|
72
170
|
|
171
|
+
|
172
|
+
|
73
173
|
ホスト名
|
74
174
|
|
75
175
|
$result = hostname
|
@@ -78,18 +178,84 @@
|
|
78
178
|
|
79
179
|
$conf > $conf_path[1]
|
80
180
|
|
181
|
+
|
182
|
+
|
81
183
|
Zabbixサーバ自動登録をするためのメタデータ
|
82
184
|
|
83
185
|
$conf = $(Get-Content $conf_path[1]) -replace $HostMetadata[0], $HostMetadata[1]
|
84
186
|
|
85
187
|
$conf > $conf_path[1]
|
86
188
|
|
189
|
+
|
190
|
+
|
87
191
|
エンコード
|
88
192
|
|
89
|
-
-Encoding default
|
193
|
+
# -Encoding default
|
90
194
|
|
91
195
|
$conf | Out-file $conf_path[1] -Encoding default
|
92
196
|
|
93
197
|
|
94
198
|
|
199
|
+
#####ZabbixAgentサービス開始
|
200
|
+
|
201
|
+
exe実行
|
202
|
+
|
203
|
+
cd $folder[0]
|
204
|
+
|
205
|
+
.\zabbix_agentd.exe -i -c $conf_path[1]
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
スタートアップの種類:手動
|
210
|
+
|
211
|
+
Get-Service -DisplayName 'Zabbix Agent' | Set-Service -StartupType Manual
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
サービス開始
|
216
|
+
|
217
|
+
cd $folder[0]
|
218
|
+
|
219
|
+
.\zabbix_agentd.exe -s -c $conf_path[1]
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
スタートアップの種類:自動
|
224
|
+
|
225
|
+
Set-Service -Name 'Zabbix Agent' -StartupType Automatic
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
zipファイル削除
|
230
|
+
|
231
|
+
#Remove-Item $zip[1] -Recurse
|
232
|
+
|
233
|
+
binファイル削除
|
234
|
+
|
235
|
+
#Remove-Item $folder[1] -Recurse
|
236
|
+
|
237
|
+
confファイル削除
|
238
|
+
|
239
|
+
#Remove-Item $folder[2] -Recurse
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
起動確認
|
244
|
+
|
245
|
+
Get-service "Zabbix Agent" | select-object displayname,status,starttype,PathName
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
ポーズ
|
250
|
+
|
251
|
+
Read-Host "続けるには Enter キーを押してください..."
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
結果を出力する
|
256
|
+
|
257
|
+
Stop-Transcript
|
258
|
+
|
259
|
+
|
260
|
+
|
95
261
|
不明瞭なことがあれば追加で記述しますので、よろしくお願いいたします。
|