首页 > 其他分享 >ansible-playbook之安装elasticsearch单机版

ansible-playbook之安装elasticsearch单机版

时间:2023-04-07 18:02:20浏览次数:56  
标签:单机版 name ansible elasticsearch user yes dir

一.准备环境:

1.centos7 环境

2.安装ansible环境

3.elasticsearch安装文件下载路径:

   https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.2-linux-x86_64.tar.gz

4.elasticsearch安装主机,作者用192.168.126.129作为elasticsearch安装环境


二.规划:

1.变量规划:

安装路径:elasticsearch_dir: "/kingdee/elasticsearch"

运行用户:es_start_user: elasticsearch

用户名称:esusername: logadmin

用户密码:espassword: Mytest@@@@@1203

监听端口:elasticsearch_port: 9200

最大内存(GB): memory_max: 1

最小内存(GB): memory_small: 1


2.mongodb目录规划:

安装目录:/kingdee/elasticsearch


三.编写ansible-playbook:

1.创建ansible-playbook剧本目录

mkdir -p roles/elasticsearch_single/{files,tasks,templates,vars}


2.模板文件配置

cd roles/elasticsearch_single/templates

vim elasticsearch.yml.j2

#cluster.name: my_test_elasticsearch
node.name: {{ansible_ssh_host}}
path.data: {{elasticsearch_dir}}/data
path.logs: {{elasticsearch_dir}}/logs
action.auto_create_index: false
bootstrap.memory_lock: false
network.host: {{ansible_ssh_host}}
http.port: {{elasticsearch_port}}
#discovery.seed_hosts: ["{{ ansible_ssh_host }}"]
cluster.initial_master_nodes:  ["{{ansible_ssh_host}}"]
readiness.port: 19200
action.destructive_requires_name: false

xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

xpack.security.transport.ssl:
  enabled: yes
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12

http.host: {{ ansible_ssh_host }}
transport.host: {{ ansible_ssh_host }}


vim jvm.options.j2

-Xms{{memory_small}}g
-Xmx{{memory_max}}g
-XX:+UseG1GC
-Djava.io.tmpdir=${ES_TMPDIR}
-XX:+HeapDumpOnOutOfMemoryError
-XX:+ExitOnOutOfMemoryError
-XX:HeapDumpPath=data
-XX:ErrorFile=logs/hs_err_pid%p.log
-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m


2.tasks任务文件

cd roles/elasticsearch_single/tasks

#安装单机版elasticsearch文件

vim install_elasticsearch.yml

---
- name: "user is elasticsearch exist"
  shell: |
    getent passwd {{es_start_user}}|wc -l
  register: user_exist
  become: yes

- name: "user is elasticsearch exist"
  shell: |
    cat /etc/shadow|grep {{es_start_user}}|wc -l
  register: group_exist
  become: yes

- name: "add elasticsearch group"
  group:
    name: "{{es_start_user}}"
    gid: 1112
  become: yes
  when: group_exist.stdout != "1"

- name: "add elasticsearch user"
  user:
    name: "{{es_start_user}}"
    uid: 1112
    group: "{{es_start_user}}"
  become: yes
  when: user_exist.stdout != "1"

- name: "mkdir elasticsearch directory"
  file:
    path: "/{{elasticsearch_dir.split('/')[1]}}"
    state: directory
    mode: 0755
    owner: "{{es_start_user}}"
    group: "{{es_start_user}}"
  become: yes

- name: "copy elasticsearch packge"
  copy:
    src: elasticsearch-8.6.2-linux-x86_64.tar.gz
    dest: "/tmp/elasticsearch-8.6.2-linux-x86_64.tar.gz"

- name: "tar -zxvf elasticsearch-8.6.2-linux-x86_64.tar.gz"
  shell: |
    tar -xf /tmp/elasticsearch-8.6.2-linux-x86_64.tar.gz -C  /{{elasticsearch_dir.split('/')[1]}}
    mv  /{{elasticsearch_dir.split('/')[1]}}/elasticsearch-8.6.2 {{elasticsearch_dir}}
  become: yes

- name: "chown -R {{es_start_user}}:{{es_start_user}} {{elasticsearch_dir}}"
  file:
    path: "{{elasticsearch_dir}}"
    owner: "{{es_start_user}}"
    group: "{{es_start_user}}"
    mode: 0755
    recurse: yes
  become: yes

- name: "start elasticsearch"
  shell: |
    su - elasticsearch -c "cd {{elasticsearch_dir}}/bin && sh elasticsearch -d"
    sleep 50
  become: yes

- name: "copy elasticsearch conf"
  template:
    src:  "{{item}}"
    dest: "{{elasticsearch_dir}}/config/{{item.split('.j2')[0]}}"
    mode: 0755
  become: yes
  with_items:
    - elasticsearch.yml.j2
    - jvm.options.j2

- name: "remove elasticsearch-8.6.2-linux-x86_64.tar.gz"
  file:
    path: "/tmp/elasticsearch-8.6.2-linux-x86_64.tar.gz"
    state: absent

- name: "stop elasticsearch"
  shell: |
    ps -ef|grep elasticsearch|grep -v grep|awk '{print "kill -s 9 "$2}'|sh
  become: yes

- name: "start elasticsearch"
  shell: su - elasticsearch -c "cd {{elasticsearch_dir}}/bin && sh elasticsearch -d"
  become: yes

- name: "add elasticsearch user {{ esusername }} and superuser to {{ esusername }}"
  shell: |
    {{elasticsearch_dir}}/bin/elasticsearch-users useradd {{esusername}} -r superuser,kibana_system<<EOF
    {{espassword}}
    {{espassword}}
     >>EOF
  become: yes
  ignore_errors: yes

- name: "create test index in elasticsearch"
  shell: |
    curl -XPUT http://{{ansible_ssh_host}}:9200/{{item}}  -u {{esusername}}:'{{espassword}}'
  with_items:
    - applog

- name: "chage elastic password"
  shell: |
    echo 'y'|{{elasticsearch_dir}}/bin/elasticsearch-reset-password -u elastic|grep "New value"|cut -d ':' -f2
  register: elastic_passwd

- name: "check chech_server"
  debug:
    msg: "url:http://{{ ansible_ssh_host }}:9200/_cat/nodes?v  username:{{ esusername }},password:{{espassword}}"


#环境配置

vim init.yml

---
- name: "set security config"
  shell: |
    echo "* soft nproc 65535" >> /etc/security/limits.conf
    echo "* hard nproc 65535" >> /etc/security/limits.conf
    echo "root soft nproc unlimited" >> /etc/security/limits.conf
    echo "root hard nproc unlimited" >> /etc/security/limits.conf
  become: yes

- name: "add sysctl config"
  shell: |
    echo "vm.max_map_count=655360" >> /etc/sysctl.conf
    sysctl -p
  become: yes


#主任务文件

vim mian.yml

---
- include_tasks: init.yml
- include_tasks: install_elasticsearch.yml


3.拿取elsticsearch安装包

cd roles/elasticsearch_single/files

wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.2-linux-x86_64.tar.gz -O elasticsearch-8.6.2-linux-x86_64.tar.gz

整个roles目录如下:

ansible-playbook之安装elasticsearch单机版_vim



四.编写hosts文件,与roles文件在同级目录:

vim hosts

[elasticsearch]
ansible-master ansible_ssh_host=192.168.126.128

 

五.编写运行yml文件:

vim startinstall_single_elasticsearch.yml

---
- hosts: elasticsearch_single
  remote_user: yzj
  gather_facts: no
  vars:
    - es_start_user: elasticsearch
    - esusername: logadmin
    - espassword: Kingdee@1203
    - elasticsearch_dir: "/kingdee/elasticsearch"
    - memory_small: 1
    - memory_max: 1
    - elasticsearch_port: 9200

  roles:
   - role: elasticsearch_single


六.运行elasticsearch安装脚本:

ansible-playbook -i hosts  startinstall_single_elasticsearch.yml

ansible-playbook之安装elasticsearch单机版_linux_02


七:访问elasticsearch查看状态:

curl http://192.168.126.129:9200/_cat/nodes?v  --user logadmin:'Mytest@@@@@1203'

ansible-playbook之安装elasticsearch单机版_vim_03

curl http://192.168.126.129:9200/_cat/health?v  --user logadmin:'Mytest@@@@@1203'

ansible-playbook之安装elasticsearch单机版_vim_04


至此,ansible-playbook部署elasticsearch单机部署已完成,下面会讲到elasticsearch[集群]使用ansible-playbook进行部署,如果对您有用,帮忙点个赞呗!



标签:单机版,name,ansible,elasticsearch,user,yes,dir
From: https://blog.51cto.com/u_15623120/6176462

相关文章

  • Ansible2.9安装与配置
    一、先决条件Centos7,Python2(2.7版)或Python3(3.5及更高版本), 关闭SELinux,关闭防火墙。二、安装Ansible1、yuminstallepel-release-y2、yuminstallansible-y三、配置SSH免密登录1、ssh-keygen2、[email protected]、ssh-keyscan192.168.1.2>>~/.ss......
  • ansible-galaxy命令快速创建角色框架
    在Ansible中创建角色,可以考虑使用ansible-galaxy命令快速创建角色框架。ansiblevsansible-galaxyAnsible是科幻小说银河系漫游指南中的一种超光速通讯工具,而Ansible社区的Galaxy就是类似类似dockerhub一样的存在,很多可以复用的角色(role),都在一个被称为AnsibleGalaxy的网站进......
  • 运维Ansible自动化工具概述
    运维的工作内容安装系统:pxe、kickstart、cobbler、imagetemplate安装应用、配置应用、启动应用(服务):puppet、saltstack、chef发布程序:puppet、saltstack、chef监控(服务器、系统、应用、程序):zabbix程序发布灰度发布金丝雀发布ansible解决的问题:批量安装应用、配置应用、启动应用批量......
  • es查询三种方式,Elasticsearch查询速度为什么这么快
    Elasticsearch查询速度为什么这么快?es查询三种方式 ......
  • 分布式搜索引擎Elasticsearch的架构分析
    一、写在前面 ES(Elasticsearch下文统一称为ES)越来越多的企业在业务场景是使用ES存储自己的非结构化数据,例如电商业务实现商品站内搜索,数据指标分析,日志分析等,ES作为传统关系型数据库的补充,提供了关系型数据库不具备的一些能力。ES最先进入大众视野的是其能够实现全文搜索的能力,也......
  • ElasticSearch常用api文档
    搜索引擎实现实现步骤搜集例如google、baidu都是根据爬虫爬取网页数据分析根据爬取的数据分词解析,建立临时索引等索引通过分析阶段产生的临时索引构建倒排索引,用于查询查询响应用户请求,根据倒排索引获取相关网页信息,计算权重等倒排索引正排索引:文档中包含了哪......
  • ElasticSearch 7.x (一 ~ 二)
    ElasticSearch7.x一、ElasticSearch概述1.1ElasticSearch是什么Elasticsearch是一个分布式、RESTful风格的  搜索和数据分析引擎,能够解决不断涌现出的各种用例。作为ElasticStack的核心,Elasticsearch会集中存储您的数据,让您飞快完成搜索,微调相关性,进行强大的分析......
  • ES005-Elasticsearch核心概念
    1、cluster***1.1代表一个集群,集群中有多个节点,其中有一个为主节点,这个主节点是可以通过选举产生的,主从节点是对于集群内部来说的。es的一个概念就是去中心化,字面上理解就是无中心节点,这是对于集群外部来说的,因为从外部来看es集群,在逻辑上是个整体,你与任何一个节点的通信和与整个......
  • ES002-Elasticsearch环境安装
    1、Elasticsearch安装java版本要求:最低1.7下载地址:   https://www.elastic.co/downloads/past-releases/1-4-4启动   cd/usr/local/elasticsearch-1.4.4   ./bin/elasticsearch   bin/elasticsearch-d(后台运行)2、ES安装......
  • ansible 部署mysql 5.7
    准备工作创建roles目录#mkdir-pv/data/apps/ansible/roles/mysql-5.7/{files,tasks,handlers,templates,vars}hosts[ubuntu]172.16.18.31ansible_ssh_port=22ansible_ssh_user=ubuntuhostname=app-01测试连通性#ansibleubuntu-mping172.16.18.247|SUCCESS=......