一.准备环境:
1.centos7 环境
2.安装ansible环境
3.kibana安装文件下载路径:
https://artifacts.elastic.co/downloads/kibana/kibana-8.6.2-linux-x86_64.tar.gz
4.kibana安装主机,作者用192.168.126.128作为elasticsearch安装环境
二.规划:
1.变量规划:
安装路径:kibana_dir: "/kingdee/yzj_monitor"
运行用户:kibana_user: "elasticsearch"
监听端口: kibana_port: 9201
安装包版本:kibana_tgz: "kibana-8.6.1-linux-x86_64.tar.gz"
es用户名称:esusername: "logadmin"
es用户密码:espassword: "Mytest@@@@@1203"
2.mongodb目录规划:
安装目录:/kingdee/yzj_monitor
三.编写ansible-playbook:
1.创建ansible-playbook剧本目录
mkdir -p roles/kibana/{files,tasks,templates,vars}
2.模板文件配置
cd roles/kibana/templates
#kibana配置文件
vim kibana.nginx.conf.j2
server.port: 9201
server.host: {{ansible_ssh_host}}
elasticsearch.hosts: ["http://{{elasticsearch_host.split(',')[0]}}","http://{{elasticsearch_host.split(',')[1]}}","http://{{elasticsearch_host.split(',')[2]}}"]
elasticsearch.username: "{{esusername}}"
elasticsearch.password: "{{espassword}}"
i18n.locale: zh-CN
server.publicBaseUrl: "http://{{ansible_ssh_host}}:9201"
server.rewriteBasePath: false
#######如果需要走nginx代理,则放开如下配置########################
#server.basePath: "/kibana"
#server.publicBaseUrl: "http://{{ansible_ssh_host}}:9201/kibana"
#################################################################
#nginx代理的转发配置【根据环境是否需要经过nginx转发编写】
vim kibana.nginx.conf.j2
location /kibana/ {
proxy_pass http://{{ansible_ssh_host}}:9201/;
rewrite ^/kibabna/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}
2.tasks任务文件
cd roles/kibana/tasks
vim install_kibana.yml
---
- name: "mkdir {{kibana_dir}}"
file:
path: "{{kibana_dir}}"
owner: "{{kibana_user}}"
group: "{{kibana_user}}"
state: directory
mode: 0755
become: yes
ignore_errors: yes
- name: "copy .tar to kibana server"
copy:
src: "{{kibana_tgz}}"
dest: "{{kibana_dir}}"
become: yes
- name: "unzip {{kibana_tgz}}"
shell: |
tar -xf {{kibana_dir}}/{{kibana_tgz}} -C {{kibana_dir}}
mv {{kibana_dir}}/{{kibana_tgz.split('-linux-')[0]}} {{kibana_dir}}/kibana
become: yes
- name: "copy config"
template:
src: kibana.yml.j2
dest: "{{kibana_dir}}/kibana/config/kibana.yml"
become: yes
- name: "chown -R {{kibana_user}}:{{kibana_user}} {{kibana_dir}}/kibana"
shell: |
chown -R {{kibana_user}}:{{kibana_user}} {{kibana_dir}}/kibana
become: yes
- name: "remove tgz"
file:
path: "{{kibana_dir}}/{{kibana_tgz}}"
state: absent
become: yes
## 如果使用nginx代理则开启如下:/usr/local/openresty/nginx/conf/conf.d为nginx配置文件路径
#- name: "copy kibana nginx config"
# template:
# src: kibana.conf.j2
# dest: /usr/local/openresty/nginx/conf/conf.d/kibana.conf
#- name: "restart nginx"
# shell: /usr/local/openresty/nginx/sbin/nginx -s reload
- name: "start kibana sever"
shell: |
su - {{kibana_user}} -c "nohup {{kibana_dir}}/kibana/bin/kibana > {{kibana_dir}}/kibana/logs/kibana.log 2>&1 &"
sleep 10
become: yes
- name: "print kibana proce"
debug:
msg: "url:https://{{ansible_ssh_host}}:9201/kibana username:{{esusername}} password:{{espassword}}"
#主任务文件
vim mani.yml
---
- include_tasks: install_kibana.yml
3.拿取kibana安装包
cd roles/kibana/files
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.6.2-linux-x86_64.tar.gz -O kibana-8.6.2-linux-x86_64.tar.gz
整体目录文件如下:
四.编写hosts文件,与roles文件在同级目录:
vim hosts
[kibana]
kibane ansible_ssh_host=192.168.126.128
五.编写运行yml文件,与roles文件在同级目录:
vim startinstall_kibana.yml
---
- hosts: kibana
remote_user: yzj
vars:
- kibana_dir: "/kingdee/yzj_monitor"
- kibana_user: "elasticsearch"
- kibana_tgz: "kibana-8.6.1-linux-x86_64.tar.gz"
- esusername: "logadmin"
- espassword: "Test@@@@@1203"
- elasticsearch_host: "192.168.126.128:9200,192.168.126.129:9200,192.168.126.130:9200"
roles:
- role: kibana
六.运行kibana安装脚本:
ansible-playbook -i hosts startinstall_kibana.yml
运行效果如图:
七.测试登录
访问:http://192.168.126.128:9201 用户名/密码: logadmin/Mytest@@@@@1203
至此,ansible-playbook安装kibana已经完成,后续会讲到ansible-playbook安装部署redis[单机部署、集群部署],如果对你有帮助,请点个赞吧!