teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

軽度の変更

2019/06/12 04:49

投稿

zazabi
zazabi

スコア24

title CHANGED
File without changes
body CHANGED
@@ -94,7 +94,7 @@
94
94
  $conf > $conf_path[1]
95
95
 
96
96
  エンコード
97
- # -Encoding default
97
+ -Encoding default
98
98
  $conf | Out-file $conf_path[1] -Encoding default
99
99
 
100
100
  #####ZabbixAgentサービス開始
@@ -113,11 +113,11 @@
113
113
  Set-Service -Name 'Zabbix Agent' -StartupType Automatic
114
114
 
115
115
  zipファイル削除
116
- #Remove-Item $zip[1] -Recurse
116
+ Remove-Item $zip[1] -Recurse
117
117
  binファイル削除
118
- #Remove-Item $folder[1] -Recurse
118
+ Remove-Item $folder[1] -Recurse
119
119
  confファイル削除
120
- #Remove-Item $folder[2] -Recurse
120
+ Remove-Item $folder[2] -Recurse
121
121
 
122
122
  起動確認
123
123
  Get-service "Zabbix Agent" | select-object displayname,status,starttype,PathName

1

コマンドを全文掲載しました。

2019/06/12 04:49

投稿

zazabi
zazabi

スコア24

title CHANGED
File without changes
body CHANGED
@@ -10,39 +10,122 @@
10
10
 
11
11
  #■コマンド
12
12
  ###引数
13
+ #####ユーザーが設定する
14
+ $IP = "**.**.**.**"
15
+ $log_path = "c:\zabbix\zabbix_agentd.log"
16
+ $Metadata = "windows2008"
17
+
18
+ #####以下本文
19
+ フォルダパス
20
+ $folder = @("C:\zabbix\","C:\zabbix\bin","C:\zabbix\conf")
21
+ フォルダ作成
22
+ New-Item $folder[0] -ItemType Directory
23
+
13
24
  位置パス定義
25
+ 現在のスクリプトパス
14
26
  $file_path = (Convert-Path .)
27
+ 標準出力に表示
28
+ Write-Host $file_path
29
+
30
+ スクリプト出力ログ
31
+ Start-Transcript -Path ($file_path+"\zabbixAgentインストール.log")
32
+
33
+ ファイルパス
34
+ zipファイル
35
+ $zip = @(($file_path+"\Desktop\zabbix_agents.zip"),"C:\zabbix\zabbix_agents.zip")
36
+ exe:移動前/移動後
37
+ $exe_path = @("C:\zabbix\bin\zabbix_agentd.exe","C:\zabbix\zabbix_agentd.exe")
38
+ conf:移動前/移動後
39
+ $conf_path = @("C:\zabbix\conf\zabbix_agentd.conf","C:\zabbix\zabbix_agentd.conf")
40
+
15
- confファイル用
41
+ #####confファイル用
42
+ log
16
43
  $LogFile = @("LogFile=c:\zabbix_agentd.log",("LogFile="+$log_path))
44
+
17
45
  zabbixIPアドレス
18
46
  $Server = @("Server=127.0.0.1",("Server="+$IP))
19
- アクティブZabbixサーバIP
20
47
  $ServerActive =@("ServerActive=127.0.0.1",("ServerActive="+$IP))
48
+
21
49
  hostname
22
50
  $Hostname = "Hostname=Windows host"
51
+
23
52
  メタデータ
24
53
  $HostMetadata = @("# HostMetadata=",("# HostMetadata=`r`n`r`nHostMetadata="+$Metadata))
25
54
 
55
+ #####処理開始
56
+ zipファイル移動
57
+ Move-Item $zip[0] $zip[1]
58
+
59
+ 解凍
60
+ $file = $zip[1]
61
+ $shell = New-Object -ComObject shell.application
62
+ $zip_file = $shell.NameSpace($file)
63
+ $dest = $shell.NameSpace((Split-Path $file -Parent))
64
+ $dest.CopyHere($zip_file.Items())
65
+
66
+ exeファイル配置
67
+ Move-Item $exe_path[0] $exe_path[1]
68
+ confフォルダ配置
69
+ Move-Item $conf_path[0] $conf_path[1]
70
+
26
- ###confファイル
71
+ confファイル書き
72
+ -Encoding UTF8
27
73
  $conf= Get-Content $conf_path[1] -Encoding UTF8
74
+
28
75
  zabbixサーバ設定
29
76
  $conf = $(Get-Content $conf_path[1]) -replace $Server[0],$Server[1]
30
77
  $conf > $conf_path[1]
78
+
31
79
  Zabbixアクティブサーバ設定
32
80
  $conf = $(Get-Content $conf_path[1]) -replace $ServerActive[0],$ServerActive[1]
33
81
  $conf > $conf_path[1]
82
+
34
83
  Logファイル設定
35
84
  $conf = $(Get-Content $conf_path[1]) -replace $LogFile[0],$LogFile[1]
36
85
  $conf > $conf_path[1]
86
+
37
87
  ホスト名
38
88
  $result = hostname
39
89
  $conf = $(Get-Content $conf_path[1]) -replace $Hostname,("Hostname="+$result)
40
90
  $conf > $conf_path[1]
91
+
41
92
  Zabbixサーバ自動登録をするためのメタデータ
42
93
  $conf = $(Get-Content $conf_path[1]) -replace $HostMetadata[0], $HostMetadata[1]
43
94
  $conf > $conf_path[1]
95
+
44
96
  エンコード
45
- -Encoding default
97
+ # -Encoding default
46
98
  $conf | Out-file $conf_path[1] -Encoding default
47
99
 
100
+ #####ZabbixAgentサービス開始
101
+ exe実行
102
+ cd $folder[0]
103
+ .\zabbix_agentd.exe -i -c $conf_path[1]
104
+
105
+ スタートアップの種類:手動
106
+ Get-Service -DisplayName 'Zabbix Agent' | Set-Service -StartupType Manual
107
+
108
+ サービス開始
109
+ cd $folder[0]
110
+ .\zabbix_agentd.exe -s -c $conf_path[1]
111
+
112
+ スタートアップの種類:自動
113
+ Set-Service -Name 'Zabbix Agent' -StartupType Automatic
114
+
115
+ zipファイル削除
116
+ #Remove-Item $zip[1] -Recurse
117
+ binファイル削除
118
+ #Remove-Item $folder[1] -Recurse
119
+ confファイル削除
120
+ #Remove-Item $folder[2] -Recurse
121
+
122
+ 起動確認
123
+ Get-service "Zabbix Agent" | select-object displayname,status,starttype,PathName
124
+
125
+ ポーズ
126
+ Read-Host "続けるには Enter キーを押してください..."
127
+
128
+ 結果を出力する
129
+ Stop-Transcript
130
+
48
131
  不明瞭なことがあれば追加で記述しますので、よろしくお願いいたします。