共计 2144 个字符,预计需要花费 6 分钟才能阅读完成。
相干网址
- Ansible github: https://github.com/ansible/an…
- Ansible 官网文档: https://docs.ansible.com/
配置 ssh 免密登录
- 将公钥传送到 ssh 被控服务器
- 主控端配置(配好后用
ssh node01
测试)
vim ~/.ssh/config
# 将 ip 自身也作为别名之一 | |
Host node01 172.31.10.157 | |
HostName 172.31.10.157 | |
Port 22 | |
User ubuntu | |
IdentityFile ~/.ssh/id_rsa | |
Host node02 172.31.15.123 | |
HostName 172.31.15.123 | |
Port 22 | |
User ubuntu | |
IdentityFile ~/.ssh/id_rsa |
根本命令
- ping
# ping 所有资产清单上的主机 | |
ansible all -m ping | |
# ping node 组的所有主机 | |
ansible node -m ping |
- 执行 shell 命令
ansible node -a 'ls /home/ubuntu'
- 执行脚本
ansible-playbook 1_push.yml
Ansible 配置 Elasticsearch
环境
操作系统: Ubuntu 20.04 LTS | |
Python: 3.8.5 | |
Ansible: 2.10.4 |
资产清单(Inventory)
cat /etc/ansible/hosts
[node] | |
172.31.10.157 ansible_user=ubuntu es_node_name=node01 | |
172.31.15.123 ansible_user=ubuntu es_node_name=node02 | |
172.31.8.77 ansible_user=ubuntu es_node_name=node03 |
脚本(Inventory)
- 推送(
1_push.yml
)
- hosts: node | |
user: ubuntu | |
tasks: | |
- name: push file to node | |
copy: | |
src: /home/ubuntu/es_down | |
dest: /home/ubuntu | |
mode: 0660 |
- 装置(
2_install.yml
)
- hosts: node | |
user: ubuntu | |
tasks: | |
- name: Configure jvm.options | |
become: true | |
become_user: root | |
shell: dpkg -i /home/ubuntu/es_down/elasticsearch-7.10.1-amd64.deb |
- 配置 jvm(
3_config_jvm.yml
)
- hosts: node | |
user: ubuntu | |
tasks: | |
- name: Configure jvm.options | |
become: true | |
become_user: root | |
lineinfile: | |
dest: '/etc/elasticsearch/jvm.options' | |
regexp: "{{item.old}}" | |
line: "{{item.new}}" | |
with_items: | |
- {old: '^-Xms',new: '-Xms8g'} | |
- {old: '^-Xmx',new: '-Xmx8g'} |
- 配置 Elasticsearch(
4_config_es.yml
)
- hosts: node | |
user: ubuntu | |
tasks: | |
- name: Configure elasticsearch.yml | |
become: true | |
become_user: root | |
lineinfile: | |
dest: '/etc/elasticsearch/elasticsearch.yml' | |
backrefs: no | |
state: present | |
regexp: "{{item.old}}" | |
line: "{{item.new}}" | |
with_items: | |
- {old: '^cluster.name', new: 'cluster.name: esapi'} | |
- {old: '^node.roles', new: 'node.roles: [data]' } | |
- {old: '^node.name', new: 'node.name: {{ es_node_name}}' } | |
- {old: '^myhost', new: 'myhost: {{ inventory_hostname}}' } | |
- {old: '^path.data', new: 'path.data: /data/elasticsearch/data'} | |
- {old: '^path.log', new: 'path.log: /data/elasticsearch/log'} | |
- {old: '^network.host', new: 'network.host: 0.0.0.0'} | |
- {old: '^http.port', new: 'http.port: 9200'} | |
- {old: '^discovery.seed_hosts', new: 'discovery.seed_hosts: ["172.31.0.1","172.31.0.2","172.31.0.3"]' } | |
- {old: '^cluster.initial_master_nodes', new: 'cluster.initial_master_nodes: ["mnode01","mnode02","mnode03"]' } |
本文出自 qbit snap
正文完