-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dd64677
Showing
13 changed files
with
1,097 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea/ | ||
.code/ | ||
|
||
vagrant/.vagrant | ||
pkg/ | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
new: clean up | ||
|
||
|
||
############################################################### | ||
# node creation | ||
############################################################### | ||
meta: | ||
cd vagrant && vagrant up node0 | ||
cd ansible && ./init-yum.yml && ./init-control.yml | ||
# copy yum dir to accelerate next vm creation | ||
cache: | ||
rm -rf pkg/* && mkdir -p pkg && scp -r node0:/www/pigsty/* pkg/ | ||
|
||
############################################################### | ||
# vm management | ||
############################################################### | ||
status: | ||
cd vagrant && vagrant status | ||
up: | ||
cd vagrant && vagrant up | ||
bin/setup-ssh.sh | ||
suspend: | ||
cd vagrant && vagrant suspend | ||
halt: | ||
cd vagrant && vagrant halt | ||
resume: | ||
cd vagrant && vagrant resume | ||
clean: halt | ||
cd vagrant && vagrant destroy -f --parallel | ||
exit 0 | ||
# sync node clock via ntp | ||
sync-time: | ||
echo node0 node1 node2 node3 | xargs -n1 -P4 -I{} ssh {} sudo ntpdate -u time.pool.aliyun.com | ||
|
||
|
||
|
||
|
||
.PHONY: status meta up suspend halt resume clean |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[defaults] | ||
nocows = 1 | ||
inventory = hosts | ||
remote_user = vagrant | ||
host_key_checking = False | ||
deprecation_warnings=False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[cluster] | ||
node1 seq=1 role=primary | ||
node2 seq=2 role=standby offline=on backup=on candidate=on | ||
node3 seq=3 role=delayed | ||
|
||
[pigsty] | ||
node0 | ||
node1 | ||
node2 | ||
node3 | ||
|
||
[control] | ||
node0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env ansible-playbook | ||
--- | ||
#==============================================================# | ||
# File : init-control.yml | ||
# Mtime : 2020-05-30 | ||
# Desc : init control node | ||
# Path : ansible/init-control.yml | ||
# Author : Vonng([email protected]) | ||
# Note: This play assumes all pkgs already accessible via yum | ||
#==============================================================# | ||
|
||
|
||
- name: Init Yum | ||
hosts: control | ||
become: yes | ||
gather_facts: no | ||
vars: | ||
tasks: | ||
|
||
################################################################ | ||
# PHASE 1: [install] control node packages | ||
################################################################ | ||
- name: Install yum packages | ||
tags: [install] | ||
yum: | ||
name: | ||
- grafana,prometheus2,alertmanager,consul,etcd,nginx,haproxy,keepalived,dnsmasq | ||
- node_exporter,pg_exporter,nginx_exporter,consul_exporter | ||
- ansible,python,python-pip,python-ipython,python-psycopg2 | ||
- ntp,uuid,readline,lz4,nc,pv,jq,vim,bash,libxml2,libxslt,lsof,wget,unzip,git,bind-utils,net-tools,sysstat,tcpdump | ||
- gcc,gcc-c++,clang,make,coreutils,diffutils,patch,rpm-build,rpm-devel,rpmlint,rpmdevtools | ||
- postgresql12* | ||
- postgis30_12* | ||
- wal2json12,pg_repack12,pg_qualstats12,pg_stat_kcache12,pgrouting_12,pg_cron_12,timescaledb_12,pglogical_12,pgpool-II-12 | ||
- pgbouncer,pgadmin4,pg_top,pgbadger | ||
- perl-ExtUtils-Embed,zlib,zlib-devel,openssl,openssl-libs,openssl-devel,pam-devel,libxml2-devel,libxslt-devel,openldap-devel,systemd-devel,tcl-devel,python-devel | ||
- docker-ce,docker-ce-cli | ||
|
||
|
||
################################################################ | ||
# PHASE 2: [prometheus] | ||
################################################################ | ||
- name: Setup Prometheus and grafana | ||
tags: [prometheus] | ||
block: | ||
- name: Wipe out prometheus config | ||
file: path=/etc/prometheus state=absent | ||
- name: Wipe out prometheus data | ||
file: path=/var/lib/prometheus/data state=absent | ||
- name: Recreate prometheus data dir | ||
file: path=/var/lib/prometheus/data mode=0700 state=directory owner=prometheus group=prometheus | ||
- name: Copy prometheus configs | ||
copy: src=files/prometheus/ dest=/etc/prometheus mode=0755 | ||
- name: Launch prometheus service | ||
systemd: name=prometheus state=restarted enabled=yes daemon_reload=yes | ||
- name: Launch alertmanager service | ||
systemd: name=alertmanager state=restarted enabled=yes daemon_reload=yes | ||
|
||
################################################################ | ||
# PHASE 3: [grafana] | ||
################################################################ | ||
- name: Setup Grafana | ||
tags: [grafana] | ||
block: | ||
- name: Copy grafana configs | ||
copy: src=files/grafana/grafana.ini dest=/etc/grafana/grafana.ini owner=grafana group=grafana | ||
- name: Provision grafana datasource | ||
copy: src=files/grafana/datasources/ dest=/etc/grafana/provisioning/datasources/ owner=root group=grafana mode=0640 | ||
- name: Provision grafana dashboards | ||
copy: src=files/grafana/dashboards/ dest=/etc/grafana/provisioning/dashboards/ owner=root group=grafana mode=0640 | ||
- name: Launch grafana service | ||
systemd: name=grafana-server state=restarted enabled=yes daemon_reload=yes | ||
|
||
################################################################ | ||
# PHASE 4: [consul] | ||
################################################################ | ||
- name: Setup Consul | ||
tags: [consul] | ||
block: | ||
- name: Copy consul service unit | ||
copy: src=files/consul/consul.service dest=/usr/lib/systemd/system/consul.service | ||
- name: Copy consul main config | ||
copy: src=files/consul/consul.json dest=/etc/consul.d/consul.json mode=0700 owner=consul group=postgres | ||
- name: Copy consul services definition | ||
copy: src=files/consul/srv-{{ item }}.json dest=/etc/consul.d/srv-{{ item }}.json mode=0770 owner=consul group=postgres | ||
with_items: [grafana, prometheus, alertmanager, consul, nginx, dnsmasq, consul-dns] | ||
- name: Launch consul service | ||
systemd: name=consul state=restarted enabled=yes daemon_reload=yes | ||
|
||
|
||
################################################################ | ||
# PHASE 5: [dnsmasq] | ||
################################################################ | ||
- name: Setup dnsmasq | ||
tags: [dnsmasq] | ||
block: | ||
- name: Copy dnsmasq config | ||
copy: | ||
content: | | ||
port=53 | ||
listen-address=10.10.10.10 | ||
server=/consul/127.0.0.1#8600 | ||
dest: /etc/dnsmasq.d/config | ||
- name: Launch dnsmasq service | ||
systemd: name=dnsmasq state=restarted enabled=yes daemon_reload=yes | ||
|
||
|
||
# ################################################################ | ||
# # PHASE 6: [keepalived] | ||
# ################################################################ | ||
# - name: Setup keepalived | ||
# tags: [keepalived] | ||
# block: | ||
# - name: Copy keepalived config | ||
# copy: src=files/keepalived/keepalived.conf dest=/etc/keepalived/keepalived.conf mode=0750 | ||
# - name: Launch keepalived service | ||
# systemd: name=keepalived state=restarted enabled=yes daemon_reload=yes | ||
# | ||
# | ||
# ################################################################ | ||
# # PHASE 7: [haproxy] | ||
# ################################################################ | ||
# - name: Setup haproxy | ||
# tags: [haproxy] | ||
# block: | ||
# - name: Copy haproxy config | ||
# copy: src=files/haproxy/haproxy.cfg dest=/etc/haproxy/haproxy.cfg mode=0750 | ||
# - name: Launch haproxy service | ||
# systemd: name=haproxy state=restarted enabled=yes daemon_reload=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#!/usr/bin/env ansible-playbook | ||
--- | ||
#==============================================================# | ||
# File : init-yum.yml | ||
# Mtime : 2020-05-30 | ||
# Desc : init local yum repo on pigsty control node | ||
# Path : ansible/init-yum.yml | ||
# Author : Vonng([email protected]) | ||
# Note: This playbook may takes long time to download yum pkgs | ||
# Once downloaded, run `make cache` under pigsty home dir | ||
# to cache downloaded rpms on your host. And next control | ||
# node creation will be accelerated via cache | ||
# rpms in pigsty/pkg will be used, considering download | ||
# manually via proxy if blocked by the wall | ||
#==============================================================# | ||
|
||
- name: Init Yum | ||
hosts: control | ||
become: yes | ||
gather_facts: no | ||
vars: | ||
tasks: | ||
|
||
################################################################ | ||
# PHASE 1: [bootstrap] with minimal required packages | ||
################################################################ | ||
# check cache existence | ||
- name: Touch bootstrap dir | ||
tags: [bootstrap] | ||
file: path=/www/pigsty/boot state=directory mode=0755 | ||
|
||
# check local cache exists (when ok file exists) | ||
- name: Check bootstrap packges cache exists | ||
tags: [bootstrap] | ||
stat: path=/www/pigsty/boot/boot_complete | ||
register: boot_cache | ||
|
||
# if cache not found, download packages to cache dir and set ok flag | ||
- name: Download bootstrap packages if not exists | ||
tags: [bootstrap] | ||
when: not boot_cache.stat.exists | ||
block: | ||
- name: Install centos yum repos | ||
yum: name=epel-release,centos-release-scl,centos-release-scl-rh | ||
|
||
- name: Install 3rd-party yum repos | ||
copy: | ||
src: "files/yum.repos.d/{{ item }}.repo" | ||
dest: "/etc/yum.repos.d/{{ item }}.repo" | ||
mode: 0644 | ||
with_items: | ||
- nginx | ||
- docker | ||
- grafana | ||
- postgres | ||
- prometheus | ||
|
||
- name: Download bootstrap packages | ||
yum: | ||
download_only: yes | ||
download_dir: /www/pigsty/boot | ||
name: epel-release,createrepo,wget,yum-utils,nginx | ||
|
||
- name: Download bootstrap packages complete | ||
copy: content=ok dest=/www/pigsty/boot/boot_complete | ||
|
||
# install downloaded packages | ||
- name: Install bootstrap packages | ||
tags: [bootstrap] | ||
shell: cd /www/pigsty/boot && yum localinstall -q -y *.rpm | ||
|
||
|
||
################################################################ | ||
# PHASE 2: [nginx] config and launch | ||
################################################################ | ||
- name: Create nginx files | ||
tags: [nginx] | ||
block: | ||
- name: Copy nginx conf | ||
copy: src=files/nginx/nginx.conf dest=/etc/nginx/conf.d/nginx.conf | ||
- name: Copy nginx web files | ||
copy: src=files/nginx/{{ item }} dest=/www/{{ item }} | ||
with_items: | ||
- index.html | ||
- pigsty.repo | ||
|
||
- name: Launch nginx service | ||
tags: [nginx] | ||
systemd: | ||
name: nginx | ||
state: restarted | ||
enabled: yes | ||
daemon_reload: yes | ||
|
||
- name: Waits nginx online | ||
tags: [nginx] | ||
wait_for: | ||
host: localhost | ||
port: 80 | ||
state: started | ||
|
||
|
||
################################################################ | ||
# PHASE 3: [yum] repo init | ||
################################################################ | ||
# check local yum cache exists (when ok file exists) | ||
- name: Check nginx packges cache exists | ||
tags: [yum] | ||
stat: path=/www/pigsty/repo_complete | ||
register: repo_cache | ||
|
||
# download 3rd party rpms | ||
- name: Download local yum packages | ||
when: not repo_cache.stat.exists | ||
tags: [yum] | ||
block: | ||
- name: Download local yum packages | ||
yum: | ||
download_only: yes | ||
download_dir: /www/pigsty | ||
name: | ||
- postgresql13* | ||
- postgresql12* | ||
- postgis30_12* | ||
- wal2json12,pg_repack12,pg_qualstats12,pg_stat_kcache12,pgrouting_12,pg_cron_12,timescaledb_12,pglogical_12,pgpool-II-12 | ||
- pgbouncer,pgadmin4,pg_top,pgbadger,pgdg-redhat-repo | ||
- ansible,python,python-pip,python-ipython,python-psycopg2 | ||
- ntp,uuid,readline,lz4,nc,pv,jq,vim,bash,libxml2,libxslt,lsof,wget,unzip,git,bind-utils,net-tools,sysstat,tcpdump | ||
- gcc,gcc-c++,clang,make,coreutils,diffutils,patch,rpm-build,rpm-devel,rpmlint,rpmdevtools | ||
- perl-ExtUtils-Embed,zlib,zlib-devel,openssl,openssl-libs,openssl-devel,pam-devel,libxml2-devel,libxslt-devel,openldap-devel,systemd-devel,tcl-devel,python-devel | ||
- nginx,haproxy,keepalived,dnsmasq | ||
- grafana,prometheus2,pushgateway,alertmanager,node_exporter,postgres_exporter,nginx_exporter,consul_exporter,etcd | ||
- docker-ce,docker-ce-cli | ||
|
||
# download some rpm packages directly from github | ||
- name: Download pg_exporter RPM | ||
get_url: | ||
url: https://github.com/Vonng/pg_exporter/releases/download/v0.2.0/pg_exporter-0.2.0-1.el7.x86_64.rpm | ||
dest: /www/pigsty/pg_exporter-0.2.0-1.el7.x86_64.rpm | ||
- name: Download patroni RPM | ||
get_url: | ||
url: https://github.com/cybertec-postgresql/patroni-packaging/releases/download/1.6.5-1/patroni-1.6.5-1.rhel7.x86_64.rpm | ||
dest: /www/pigsty/patroni-1.6.5-1.rhel7.x86_64.rpm | ||
- name: Download consul RPM | ||
get_url: | ||
url: https://copr-be.cloud.fedoraproject.org/results/harbottle/main/epel-7-x86_64/01368466-consul/consul-1.7.3-1.el7.harbottle.x86_64.rpm | ||
dest: /www/pigsty/consul-1.7.3-1.el7.harbottle.x86_64.rpm | ||
- name: Download kubectl RPM | ||
get_url: | ||
url: https://copr-be.cloud.fedoraproject.org/results/harbottle/main/epel-7-x86_64/01399312-kubectl1.17/kubectl1.17-1.17.6-1.el7.harbottle.src.rpm | ||
dest: /www/pigsty/kubectl1.17-1.17.6-1.el7.harbottle.src.rpm | ||
- name: Download kubeadm RPM | ||
get_url: | ||
url: https://copr-be.cloud.fedoraproject.org/results/harbottle/main/epel-7-x86_64/01399314-kubeadm1.17/kubeadm1.17-1.17.6-1.el7.harbottle.src.rpm | ||
dest: /www/pigsty/kubeadm1.17-1.17.6-1.el7.harbottle.src.rpm | ||
- name: Download helm RPM | ||
get_url: | ||
url: https://copr-be.cloud.fedoraproject.org/results/harbottle/main/epel-7-x86_64/01372476-helm/helm-3.2.1-1.el7.harbottle.src.rpm | ||
dest: /www/pigsty/helm-3.2.1-1.el7.harbottle.src.rpm | ||
# create repo | ||
- name: Create repo index | ||
shell: createrepo /www/pigsty | ||
# set complete flag | ||
- name: Local yum repo online (Don't forget `make cache`) | ||
copy: content=ok dest=/www/pigsty/repo_complete | ||
|
||
- name: Install pigsty yum repo | ||
tags: [yum] | ||
get_url: | ||
url: http://yum.pigsty/pigsty.repo | ||
dest: /etc/yum.repos.d/pigsty.repo | ||
force: yes | ||
|
||
- name: Disable all default repos | ||
tags: [yum] | ||
shell: | | ||
yum-config-manager --disable * | ||
yum-config-manager --enable pigsty | ||
Oops, something went wrong.