Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

PMM-8306 migrate ami ova to docker #343

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packer/ansible/files/pmm2.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=PMM2 Docker container
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker exec %n stop
ExecStartPre=-/usr/bin/docker rm %n
ExecStart=/usr/bin/docker run --rm --name %n \
--net host \
percona/pmm-server:2.26.0
nikita-b marked this conversation as resolved.
Show resolved Hide resolved

[Install]
WantedBy=default.target
143 changes: 143 additions & 0 deletions packer/ansible/pmm2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
- name: Create PMM2 image
hosts: default
become: true
tasks:
# - name: Enable epel repo
# command: amazon-linux-extras install -y epel
- name: Install packages
package:
name:
- docker
- python3-pip
- python3

- name: Install docker Python API
pip:
name: docker

- name: Enable Docker service
systemd:
name: docker.service
state: started
enabled: yes

- name: Turn off swap
sysctl:
name: vm.swappiness
value: 0
state: present

- name: Increase dirty ratio
sysctl:
name: vm.dirty_ratio
value: 80
state: present

- name: Decrease dirty_background_ratio
sysctl:
name: vm.dirty_background_ratio
value: 5

- name: Increase dirty_expire_centisecs
sysctl:
name: vm.dirty_expire_centisecs
value: 12000 #120 sec

- name: Increase net.core.somaxconn
sysctl:
name: net.core.somaxconn
value: 1024

- name: Increase net.core.netdev_max_backlog
sysctl:
name: net.core.netdev_max_backlog
value: 5000

- name: Increase net.core.rmem_max
sysctl:
name: net.core.rmem_max
value: 16777216

- name: Increase net.core.wmem_max
sysctl:
name: net.core.wmem_max
value: 16777216

- name: Increase net.ipv4.tcp_wmem
sysctl:
name: net.ipv4.tcp_wmem
value: 4096 12582912 16777216

- name: Increase net.ipv4.tcp_rmem
sysctl:
name: net.ipv4.tcp_rmem
value: 4096 12582912 16777216

- name: Increase net.ipv4.tcp_max_syn_backlog
sysctl:
name: net.ipv4.tcp_max_syn_backlog
value: 8192

- name: Disable net.ipv4.tcp_slow_start_after_idle
sysctl:
name: net.ipv4.tcp_slow_start_after_idle
value: 0

- name: Enable net.ipv4.tcp_tw_reuse
sysctl:
name: net.ipv4.tcp_tw_reuse
value: 1

- name: Change net.ipv4.ip_local_port_range
sysctl:
name: net.ipv4.ip_local_port_range
value: 10240 65535

- name: Change TCP Congestion Control Algorithm (net.ipv4.tcp_congestion_control)
sysctl:
name: net.ipv4.tcp_congestion_control
value: bbr

- name: Change net.ipv4.tcp_syn_retries
sysctl:
name: net.ipv4.tcp_syn_retries
value: 2

- name: Change BBR algoritm
sysctl:
name: net.core.default_qdisc
value: fq

- name: Increase kernel.perf_event_max_stack
sysctl:
name: kernel.perf_event_max_stack
value: 1023

- name: Increase fs.xfs.xfssyncd_centisecs
sysctl:
name: fs.xfs.xfssyncd_centisecs
value: 9000

- name: Increase fs.inotify.max_user_watches
sysctl:
name: fs.inotify.max_user_watches
value: 1048576

- name: pull the PMM image
docker_image:
name: percona/pmm-server:2.26.0
source: pull

- name: Copy systemd service file to image
copy:
src: pmm2.service
dest: /etc/systemd/system
owner: root
group: root

- name: Enable PMM2 container
systemd:
name: pmm2
state: started
enabled: yes
63 changes: 63 additions & 0 deletions packer/pmm2.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
packer {
required_plugins {
amazon = {
version = "=1.0.8"
source = "github.com/hashicorp/amazon"
}
}
}

source "amazon-ebs" "pmm2" {
ami_name = "PMM2 Server [${formatdate("YYYY-MM-DD hhmm", timestamp())}]"
instance_type = "c4.xlarge"
ena_support = "true"
region = "us-east-1"
subnet_id = "subnet-ee06e8e1"
security_group_id = "sg-688c2b1c"
ssh_username = "ec2-user"

launch_block_device_mappings {
delete_on_termination = true
device_name = "/dev/xvda"
volume_size = 8
volume_type = "gp3"
}

launch_block_device_mappings {
delete_on_termination = false
device_name = "/dev/xvdb"
volume_size = 100
volume_type = "gp3"
}

source_ami_filter {
filters = {
name = "*amzn2-ami-hvm-*"
root-device-type = "ebs"
virtualization-type = "hvm"
architecture = "x86_64"
}
most_recent = true
owners = ["amazon"]
}
tags = {
iit-billing-tag = "pmm-worker"
}
run_tags = {
iit-billing-tag = "pmm-ami"
}
run_volume_tags = {
iit-billing-tag = "pmm-ami"
}
}


build {
name = "pmm2"
sources = [
"source.amazon-ebs.pmm2"
]
provisioner "ansible" {
playbook_file = "./packer/ansible/pmm2.yml"
}
}