Loki单实例部署
-
服务部署规划
IP 部署服务 10.130.41.121 loki、grafana 10.130.41.10 promtail -
下载部署安装包
#在10.130.41.121部署
[loki@cdesk_node_1 ~]$ wget https://zhao138969.com/upload/Loki_to_promtail.tar.gz
[root@cdesk_node_1 ~]$ wget https://zhao138969.com/upload/grafana-enterprise-11.2.2-1.x86_64.rpm
- 安装grafana
#安装grafana
[root@cdesk_node_1 loki]# rpm -ivh grafana-enterprise-11.2.2-1.x86_64.rpm
warning: grafana-enterprise-11.2.2-1.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 10458545: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:grafana-enterprise-11.2.2-1 ################################# [100%]
[root@cdesk_node_1 loki]# vim /etc/grafana/grafana.ini
#设置为中文
default_language = zh-Hans
#nginx代理相关配置
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
allowed_origins = *
allow_embedding = true
[root@cdesk_node_1 loki]# systemctl start grafana-server.service
[root@cdesk_node_1 loki]# systemctl enable grafana-server.service
- nginx代理grafana
location /grafana {
rewrite ^/grafana/(.*) /$1 break;
proxy_pass http://192.168.27.47:3000;
proxy_set_header Host $host;
}
- 部署安装Loki服务端
[loki@cdesk_node_1 ~]$ tar xf Loki_to_promtail.tar.gz
[loki@cdesk_node_1 ~]$ cd Loki_to_promtail
# 修改配置Loki配置参数,根据实际ip和目录就行修改即可。
[loki@cdesk_node_1 Loki_to_promtail]$ vim cfg/loki-config.yaml
#指定 Loki 实例的地址
instance_addr: 10.130.41.121
#数据存储目录
path_prefix: ../loki_data
storage:
filesystem:
chunks_directory: ../loki_data/chunks
rules_directory: ../loki_data/rules
[loki@cdesk_node_1 Loki_to_promtail]$ ./start.sh -d list
[loki@cdesk_node_1 Loki_to_promtail]$ ./start.sh list
loki-server (pid 16026) [running]
promtail-cli [stopped]
[loki@cdesk_node_1 Loki_to_promtail]$ netstat -auntlp|grep 3100
tcp6 0 0 :::3100 :::* LISTEN 16026/./loki-server
tcp6 0 0 ::1:3100 ::1:52708 ESTABLISHED 16026/./loki-server
tcp6 0 0 ::1:52708 ::1:3100 ESTABLISHED 16026/./loki-server
#如启动失败,则手动执行看下,是否有其他报错信息
loki-server --config.file=../cfg/loki-config.yaml
- 部署安装Loki服务端
#涉及需要采集日志的服务器都需要对应部署,一台部署一个promtail即可。
#涉及普通用户采集日志权限,root执行,普通用户能访问到其他普通用户家目录。
[root@cdesk_node_1 loki]# setfacl -m u:loki:rwx /home/ccodqnsoft/
[loki@cdesk_node_1 ~]$ tar xf Loki_to_promtail.tar.gz
[loki@cdesk_node_1 ~]$ cd Loki_to_promtail
# 修改配置Loki配置参数,根据实际ip和目录就行修改即可。
[loki@cdesk_node_1 Loki_to_promtail]$ vim cfg/promtail-config.yaml
clients:
##指定 Loki 服务端的地址
- url: http://10.130.41.121:3100/loki/api/v1/push
scrape_configs:
- job_name: cms
static_configs:
- targets:
- localhost
labels:
#可以自行添加对应需要的标签,app和app-2
ip: 192.168.27.30
job: app
__path__: /home/ccodrunner/Platform/log/cms/cms2.log
stream: stdout
- targets:
- localhost
labels:
ip: 192.168.27.30
job: app-2
__path__: /home/app/tomcat/log/app.log
stream: stdout
- targets:
- localhost
labels:
ip: 192.168.27.30
job: varLog
#支持正则
__path__: /var/log/*log
stream: stdout
[loki@cdesk_node_1 Loki_to_promtail]$ ./start.sh -d promtail
[loki@cdesk_node_1 Loki_to_promtail]$ ./start.sh list
loki-server (pid 16026) [running]
promtail-cli (pid 15460) [running]
Garfana页面添加数据源
-
访问http://nginx_ip/grafana 默认用户和密码都是
admin
-
添加Loki数据源: 选择
open Menu
—> 选择Connections
—> 选择Data Sources
—> 选择Add New data source
—> 然后再选择Loki
对应填写Loki
服务端地址信息- 然后再选择
Save & test
- 然后再选择
Garfana页面查看日志
- 查看日志操作: 先查询选择对应标签,然后再查询相关具体日志信息。
- 选择
open Menu
—> 在选择Explore
评论区