-
Notifications
You must be signed in to change notification settings - Fork 35
/
sls-collect-logs-in-nginx-mode.yml
274 lines (274 loc) · 7.13 KB
/
sls-collect-logs-in-nginx-mode.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 采集Nginx日志至SLS,含ECS安全组配置、Nginx安装与日志 agent部署。
en: Collect Nginx logs to SLS, including ECS security group configuration, Nginx
installation, and log agent deployment.
Parameters:
InstanceId:
Type: String
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
Description:
en: Please select an ECS instance that can access the public network.
zh-cn: 请选择能访问公网的 ECS 实例。
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
Resources:
DS_Instances:
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
- Ref: InstanceId
SecurityGroupIngress_22:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 80/80
SecurityGroupIngress_3306:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 3306/3306
InstallNginx:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Ref: InstanceId
Type: RunShellScript
Sync: true
Timeout: 300
CommandContent:
Fn::Sub: |-
#!/bin/bash
yum install -y gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
rm -f nginx-1.17.10.tar.gz
wget http://nginx.org/download/nginx-1.17.10.tar.gz
tar -zxvf nginx-1.17.10.tar.gz
cd nginx-1.17.10 && ./configure && make && make install
cd /usr/local/nginx/
num=$(ps -ef|grep nginx |grep -vc grep)
if [ "$num" -ge "1" ]; then
echo "nginx is running!"
else
sbin/nginx
fi
Project:
Type: ALIYUN::SLS::Project
Properties:
Name:
Fn::Sub: trial-${ALIYUN::StackId}
Description: Created by trial center with one click
Logstore:
Type: ALIYUN::SLS::Logstore
Properties:
ProjectName:
Ref: Project
LogstoreName: test-logstore
EnableTracking: true
SlsIndex:
Type: ALIYUN::SLS::Index
Properties:
ProjectName:
Ref: Project
FullTextIndex:
Enable: true
LogstoreName:
Fn::GetAtt:
- Logstore
- LogstoreName
InstallLogAgent:
Type: ALIYUN::OOS::Execution
Properties:
TemplateName: ACS-ECS-BulkyInstallLogAgent
SafetyCheck: Skip
Parameters:
regionId:
Ref: ALIYUN::Region
OOSAssumeRole: ''
targets:
ResourceIds:
- Ref: InstanceId
RegionId:
Ref: ALIYUN::Region
Type: ResourceIds
rateControl:
Mode: Concurrency
MaxErrors: 100%
Concurrency: 1
action: install
DependsOn:
- InstallNginx
- SlsIndex
MachineGroup:
Type: ALIYUN::SLS::MachineGroup
Properties:
GroupName: test01
ProjectName:
Ref: Project
MachineIdentifyType: ip
MachineList:
- Fn::Jq:
- First
- .[0].PrivateIpAddress[0]
- Fn::GetAtt:
- DS_Instances
- Instances
DependsOn:
- InstallLogAgent
LogtailConfig:
Type: ALIYUN::SLS::LogtailConfig
Properties:
ProjectName:
Ref: Project
LogtailConfigName: test02
LogstoreName:
Fn::GetAtt:
- Logstore
- LogstoreName
RawConfigData:
configName: test-02
logSample: |-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$request_time $request_length '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
inputType: file
outputType: LogService
outputDetail:
logstoreName:
Fn::GetAtt:
- Logstore
- LogstoreName
inputDetail:
discardUnmatch: false
maxDepth: 10
advanced:
tail_size_kb: 1024
blacklist: {}
k8s:
ExternalEnvTag: {}
logPath: /usr/local/nginx/logs
filePattern: access.log
enableRawLog: false
topicFormat: none
fileEncoding: utf8
adjustTimezone: false
logTimezone: ''
preserve: true
preserveDepth: 1
dockerFile: false
dockerIncludeLabel: {}
dockerExcludeLabel: {}
dockerIncludeEnv: {}
dockerExcludeEnv: {}
logType: common_reg_log
regex: (\S*)\s*-\s*(\S*)\s*\[(\d+/\S+/\d+:\d+:\d+:\d+)\s+\S+\]\s*"(\S+)\s+(\S+)\s+\S+"\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*"([^"]*)"\s*"([^"]*)".*
key:
- remote_addr
- remote_user
- time_local
- request_method
- request_uri
- request_time
- request_length
- status
- body_bytes_sent
- http_referer
- http_user_agent
ApplyConfigToMachineGroup:
Type: ALIYUN::SLS::ApplyConfigToMachineGroup
Properties:
ProjectName:
Ref: Project
ConfigName:
Fn::GetAtt:
- LogtailConfig
- LogtailConfigName
GroupName:
Fn::GetAtt:
- MachineGroup
- GroupName
Outputs:
NginxUrl:
Description:
en: Nginx access URL.
zh-cn: Nginx访问Url。
Value:
Fn::Sub:
- http://${IP}
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress
end
- Fn::GetAtt:
- DS_Instances
- Instances
LogQueryAddress:
Description:
en: The of address nginx log.
zh-cn: Nginx日志查询地址。
Value:
Fn::Sub:
- https://sls.console.aliyun.com/lognext/project/${Project}/logsearch/${Logstore}
- Project:
Ref: Project
Logstore:
Fn::GetAtt:
- Logstore
- LogstoreName
ProjectName:
Description:
en: The name of SLS project.
zh-cn: 日志服务的项目名称。
Value:
Ref: Project
LogstoreName:
Description:
en: The name of SLS project.
zh-cn: 日志服务的日志库名称。
Value:
Fn::GetAtt:
- Logstore
- LogstoreName
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- InstanceId
TemplateTags:
- acs:document:试用教程:使用Nginx模式采集日志