页面“Sed skill”与“Filebeat nginx log”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
 
 
第1行: 第1行:
 +
[[category:ops]]
  
 +
=ins and config=
 +
==Download and install Filebeat==
 +
<pre>
  
==常用==
 
  sed  -i "s/netstat/\/usr\/bin\/netstat/g" check.sh  #还有一种不能转义的 是# ?
 
  
==!==
+
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.12.0-amd64.deb
 +
sudo dpkg -i filebeat-7.12.0-amd64.deb
 +
</pre>
 +
==Edit the configuration ==
 
<pre>
 
<pre>
[root@localhost ~]# cat  /var/spool/cron/root
+
Modify /etc/filebeat/filebeat.yml to set the connection information:
*/2  *  *  *  *    /root/check.sh
 
  
[root@localhost ~]# sed -i 's!*/2!#*!' /var/spool/cron/root
+
output.elasticsearch:
 +
  hosts: ["<es_url>"]
 +
  username: "elastic"
 +
  password: "<password>"
 +
setup.kibana:
 +
  host: "<kibana_url>"
  
[root@localhost ~]# cat  /var/spool/cron/root
+
Where <password> is the password of the elastic user, <es_url> is the URL of Elasticsearch, and <kibana_url> is the URL of Kibana.
#*  *  *  *  *    /root/check.sh
 
  
 
</pre>
 
</pre>
  
==sed 指定行后添加行==
+
==Enable and configure the nginx module ==
<pre>在29行之后添加
 
sed -i '29a user=mysql' /etc/my.cnf
 
sed -i '29a character-set-server=utf8' /etc/my.cnf
 
sed -i '29ainnodb_file_per_table=1' /etc/my.cnf</pre>
 
  
==sed删除指定行的注释==
+
<pre>
<pre>#ln36
+
sudo filebeat modules enable nginx
sed -i -e '36 s/^#//' file </pre>
 
  
==#ln1 to ln6==
+
Modify the settings in the /etc/filebeat/modules.d/nginx.yml file.
sed -i -e '1,6 s/^#//' file
 
  
 +
</pre>
  
==sed 替换并插入==
+
== Start Filebeat==
sed -i 's!old!new!' filename
 
  
==[[Sed删除或者替换有关键字的一行]]==
 
 
=追加不太像==
 
 
<pre>
 
<pre>
 +
The setup command loads the Kibana dashboards. If the dashboards are already set up, omit this command.
  
所有192.168.0.1 开头的行都被替换成它自己加localhost  192.168.0.1localhost                                                                                                 
+
sudo filebeat setup
sed  's/^192.168.0.1/&localhost/' filename                                                                                                                                 
+
sudo service filebeat start
                                                                                                                                                                           
 
                                                                                                                                                                           
 
evan@myxps:~/tmp$ cat e.txt                                                                                                                                               
 
i1111                                                                                                                                                                     
 
2222                                                                                                                                                                       
 
                                                                                                                                                                           
 
                                                                                                                                                                           
 
                                                                                                                                                                           
 
                                                                                                                                                                           
 
                                                                                                                                                                           
 
3333                                                                                                                                                                       
 
evan@myxps:~/tmp$ sed -i  -n 's/^i1/&love/p' e.txt                                                                                                                         
 
evan@myxps:~/tmp$ cat e.txt                                                                                                                                               
 
i1love111                                                                                                                                                                 
 
           
 
 
</pre>
 
</pre>
==sed 使用shell变量 ==
 
如果要使用shell变量,就需要使用双引号
 
  
=sed also=
+
== Module status==
 +
<pre>
 +
Module status  右边的 check data 按键  -- > Nginx logs dashboard
  
[https://blog.csdn.net/stpeace/article/details/46730991 sed基本用法简介]
+
</pre>
 +
systemctl daemon-reload
  
[http://kodango.com/sed-and-awk-notes-part-2 Sed and awk 笔记之 sed 篇:模式空间与地址匹配]
+
=see also=
  
[https://www.cnblogs.com/taosim/p/4000528.html sed awk插入,替换指定行的特定字符串,删除指定行首的]
+
https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-module-nginx.html
  
[https://baike.xsoftlab.net/view/595.html Linux使用sed删除和替换文件中某一行的方法]
 
  
[[category:ops]] [[category:shell]]
+
[https://www.cnblogs.com/kuku0223/p/8317965.html ELK--filebeat nginx模块]

2021年4月27日 (二) 09:25的版本


ins and config

Download and install Filebeat



curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.12.0-amd64.deb
sudo dpkg -i filebeat-7.12.0-amd64.deb

Edit the configuration

Modify /etc/filebeat/filebeat.yml to set the connection information:

output.elasticsearch:
  hosts: ["<es_url>"]
  username: "elastic"
  password: "<password>"
setup.kibana:
  host: "<kibana_url>"

Where <password> is the password of the elastic user, <es_url> is the URL of Elasticsearch, and <kibana_url> is the URL of Kibana.

Enable and configure the nginx module

sudo filebeat modules enable nginx

Modify the settings in the /etc/filebeat/modules.d/nginx.yml file.

Start Filebeat

The setup command loads the Kibana dashboards. If the dashboards are already set up, omit this command.

sudo filebeat setup
sudo service filebeat start

Module status

Module status  右边的 check data 按键  -- > Nginx logs dashboard

systemctl daemon-reload

see also

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-module-nginx.html


ELK--filebeat nginx模块