Skip to content

Commit

Permalink
add nano_install
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaifeng committed Jan 18, 2021
1 parent d341b5e commit 21e6c70
Show file tree
Hide file tree
Showing 23 changed files with 502 additions and 15 deletions.
32 changes: 32 additions & 0 deletions nano_install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 作用
这个role的作用是部署nano集群。

nano 分为 core, cell, frontend 三个组件。

* core 是主控端。
* cell 是被控端。
* frontend 是前端进程。

这里可以为host指定 `nano_role` 的变量来决定其部署为哪种角色。(还没有实现)
目前主要是部署cell.

## examples

```yaml
# group_vars/nano_cell.yml

## nano core 的实际ip地址
nano_core_ph_ip: 10.111.32.182
## nano core 的vxlan ip
nano_core_vxlan_ip: 172.16.5.182
## nano 通信时的组播地址
nano_multicast_address: 224.0.0.226
nano_packet: /data/apps/soft/ansible/nano/nano-cell-1.3.0.tgz
nano_confs:
- domain.cfg

- hosts: nano_cell
roles:
- {role: nano_install}

```
26 changes: 26 additions & 0 deletions nano_install/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
nano_packet:
nano_run_user: nano
app_base_dir: /data/apps/opt
nano_install_dir: '{{app_base_dir}}'
nano_app_name: 'nano-cell'
nano_base_dir: "{{nano_install_dir}}/{{nano_app_name}}"
nano_data_dir: /data/apps/data/{{nano_app_name}}
nano_conf_dir: /data/apps/config/{{nano_app_name}}
nano_log_dir: /data/apps/log/{{nano_app_name}}
nano_var_dir: /data/apps/var/{{nano_app_name}}
nano_install_method: local
nano_confs:
- domain.cfg
nano_env_file: nano.sh
nano_boot_file: '{{nano_app_name}}.{{ansible_service_mgr |default("systmed", true)}}'
nano_dependence_packets:
- libvirt
- policycoreutils-python
- genisoimage
- qemu-system-x86
- seabios
- seabios-bin
# 下面这两个包,如果系统是 latest 的话,是需要安装的
# - centos-release-qemu-ev
# - qemu-kvm-ev

10 changes: 10 additions & 0 deletions nano_install/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: restart_nano_for_systemd
systemd:
name: '{{nano_app_name}}'
state: restarted
daemon_reload: yes

- name: systemctl_daemon_reload
systemd:
daemon_reload: yes

27 changes: 27 additions & 0 deletions nano_install/tasks/copy_nano_conf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: set cell vxlan ip
set_fact:
nano_cell_vxlan_ip: '{{(iansible_default_ipv4.address.split(".")[-2:] | join(".") |float) * 1000 % 254 }}'

- name: copy nano vxlan script
template:
src: nano_vxlan.sh
dest: '{{ nano_var_dir }}'
owner: '{{nano_run_user}}'
group: '{{nano_run_user}}'
mode: "0644"
backup: yes

- name: copy nano conf file
template:
src: '{{ nano_conf }}'
dest: '{{ nano_conf_dir }}'
owner: '{{nano_run_user}}'
group: '{{nano_run_user }}'
mode: "0644"
backup: yes
#loop: '{{nano_conf}}'
tags:
- copy_nano_conf
notify:
- reload_nano_for_{{ansible_service_mgr}}

47 changes: 47 additions & 0 deletions nano_install/tasks/create_nano_dir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# editor: haifengsss@163.com
# create date: 2021/01/15
#

- name: create nano user
user:
name: '{{ nano_run_user }}'
state: present
local: yes
system: yes

- name: set nano sudo privilege
lineinfile:
line: '{{nano_run_user}} ALL=(root) NOPASSWD: /bin/bash'
state: present
path: /etc/sudoers
backup: 'yes'
validate: '/usr/sbin/visudo -cf %s'


- name: link /data to /data1 dir
file:
src: /data1
dest: /data
owner: root
group: root
mode: "0777"
state: link
when:
- '"/data1" in ansible_mounts | json_query("[*].mount")'
tags:
- create_data_soft_link

- name: create nano dir
file:
path: '{{ item.path }}'
owner: '{{ item.owner | default("root", true) }}'
group: '{{ item.group | default("root", true) }}'
mode: "0755"
state: 'directory'
loop:
- path: "{{app_base_dir}}"
- path: "{{nano_install_dir}}"
owner: '{{nano_run_user}}'
- path: "{{nano_var_dir}}"
owner: '{{nano_run_user}}'

33 changes: 33 additions & 0 deletions nano_install/tasks/install_nano.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


- name: get nano packet dir name
local_action:
module: shell
cmd: tar tf {{nano_packet}} |head -n 1 |awk -F'/' '{print $1}'
warn: false
register: nano_dir_name
run_once: true

- name: cp and unarchive nano to remote host
unarchive:
src: '{{ nano_packet }}'
dest: '{{ nano_install_dir }}'
owner: '{{ nano_run_user }}'
group: '{{ nano_run_user }}'
creates: '{{ nano_install_dir }}/{{nano_dir_name.stdout }}'
mode: "0755"

- name: create nano link dir
file:
src: '{{ nano_install_dir }}/{{nano_dir_name.stdout }}'
dest: '{{nano_base_dir}}'
state: link
when: nano_dir_name.stdout != nano_app_name

#- name: create nano conf link dir
# file:
# src: '{{ nano_conf_dir }}'
# dest: '/etc/{{nano_app_name}}'
# state: link
# ignore_errors: true

4 changes: 4 additions & 0 deletions nano_install/tasks/install_nano_dependence_packet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: install nano dependence packet
yum:
name: '{{nano_dependence_packets}}'
state: present
29 changes: 29 additions & 0 deletions nano_install/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# editor: haifengsss@163.com
# update date: 2021/01/18

- import_tasks: create_nano_dir.yml
tags:
- nano_create_dir

- import_tasks: install_nano.yml
tags:
- nano_install

- import_tasks: copy_nano_conf.yml
tags:
- nano_copy_conf

- import_tasks: install_nano_dependence_packet.yml
tags:
- nano_install_dependence_packet

- import_tasks: nano_boot.yml
tags:
- nano_boot


#- include: install_dependence_packet.yml
# when: nano_install_method == "net"


#- include: core_argument.yml
4 changes: 4 additions & 0 deletions nano_install/tasks/nano_boot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

- include_tasks: nano_{{ansible_service_mgr}}_service.yml
name: nano_service_boot
when: ansible_os_family == "RedHat"
16 changes: 16 additions & 0 deletions nano_install/tasks/nano_systemd_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: copy nano systemd boot file
template:
src: '{{nano_boot_file}}'
dest: '/usr/lib/systemd/system/{{nano_app_name}}.service'
owner: root
group: root
mode: "0644"
backup: yes
notify:
- systemctl_daemon_reload

- name: set nano boot and starting up
systemd:
name: '{{nano_app_name}}'
enabled: yes
state: started
5 changes: 5 additions & 0 deletions nano_install/templates/domain.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"domain": "nano",
"group_address": "{{nano_multicast_address}}",
"group_port": 5599
}
17 changes: 17 additions & 0 deletions nano_install/templates/nano-cell.systemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=nano-cell

[Service]
Type=forking
PIDFile={{nano_base_dir}}/cell.pid
WorkingDirectory={{nano_log_dir}}
ExecStartPre=-/bin/sudo -u root /bin/bash {{nano_var_dir}}/nano_vxlan.sh
User={{nano_run_user}}
ExecStart={{nano_base_dir}}/cell start
ExecStop={{nano_base_dir}}/cell stop
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

17 changes: 17 additions & 0 deletions nano_install/templates/nano-vxlan.systemd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=nano-cell

[Service]
Type=forking
PIDFile={{nano_base_dir}}/cell.pid
WorkingDirectory={{nano_log_dir}}
#ExecStartPre=-/bin/bash {{nano_var_dir}}/nano_vxlan.sh
User={{nano_run_user}}
ExecStart={{nano_base_dir}}/cell start
ExecStop={{nano_base_dir}}/cell stop
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

14 changes: 14 additions & 0 deletions nano_install/templates/nano.systemd.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network-online.target

[Service]
Type=forking
PIDFile={{keepalived_var_dir}}/keepalived.pid
KillMode=process
EnvironmentFile=-{{keepalived_conf_dir}}/keepalived.env
ExecStart={{keepalived_bin_dir}}/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit 21e6c70

Please sign in to comment.