Skip to content

Commit cbfaa27

Browse files
committed
something from devops and dba
1 parent 9fa44a3 commit cbfaa27

File tree

16 files changed

+261
-13
lines changed

16 files changed

+261
-13
lines changed

HAPostgres/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
POSTGRES_DB=iot_db
2+
POSTGRES_USERNAME=postgres
3+
POSTGRES_PASSWORD=postgres
4+
PG_DATA=/var/lib/postgresql/data

HAPostgres/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM postgres:latest
2+
RUN mkdir /backup
3+
COPY scripts /scripts
4+
RUN chmod +x -R /scripts/

HAPostgres/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3'
2+
services:
3+
postgres:
4+
image: custom_postgres:1.4
5+
container_name: pg_master
6+
ports:
7+
- 5432:5432
8+
env_file:
9+
- .env
10+
volumes:
11+
- ./data/backup:/backup
12+
- ./init.sql:/docker-entrypoint-initdb.d/init.sql

HAPostgres/init.sql

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
CREATE TABLE IF NOT EXISTS Locations (
2+
location_id SERIAL PRIMARY KEY,
3+
country VARCHAR(255),
4+
city VARCHAR(255),
5+
home_number varchar(255)
6+
);
7+
8+
CREATE TABLE IF NOT EXISTS Devices (
9+
device_id SERIAL PRIMARY KEY,
10+
device_name VARCHAR(255),
11+
device_type VARCHAR(50),
12+
location_id INT REFERENCES Locations(location_id),
13+
status VARCHAR(10) CHECK (status IN ('active', 'inactive')),
14+
last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP
15+
);
16+
17+
CREATE TABLE IF NOT EXISTS Sensors (
18+
sensor_id SERIAL PRIMARY KEY,
19+
device_id INT REFERENCES Devices(device_id),
20+
sensor_type VARCHAR(50),
21+
value FLOAT,
22+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
23+
);
24+
25+
CREATE TABLE IF NOT EXISTS SecuritySystems (
26+
security_id SERIAL PRIMARY KEY,
27+
device_id INT REFERENCES Devices(device_id),
28+
security_type VARCHAR(50),
29+
status VARCHAR(10) CHECK (status IN ('active', 'inactive')),
30+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
31+
);
32+
33+
CREATE TABLE IF NOT EXISTS TrafficControl (
34+
traffic_id SERIAL PRIMARY KEY,
35+
device_id INT REFERENCES Devices(device_id),
36+
traffic_light_status VARCHAR(10) CHECK (traffic_light_status IN ('red', 'yellow', 'green')),
37+
traffic_flow FLOAT,
38+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
39+
);
40+
41+
CREATE TABLE IF NOT EXISTS PowerNetworks (
42+
power_id SERIAL PRIMARY KEY,
43+
device_id INT REFERENCES Devices(device_id),
44+
power_consumption FLOAT,
45+
renewable_energy VARCHAR(3) CHECK (renewable_energy IN ('yes', 'no')),
46+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
47+
);
48+
49+
CREATE TABLE IF NOT EXISTS DataCollection (
50+
data_id SERIAL PRIMARY KEY,
51+
device_id INT REFERENCES Devices(device_id),
52+
data_type VARCHAR(50),
53+
data_content TEXT,
54+
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
55+
);
56+
-- добавить табличку с маппингом местоположения в формате таблицы : страна, город, улица, дом
57+
-- описать баш скрипт для создания бэкапа в формате backup-дата.sql
58+
-- добавить скрипт в образ постгрес
59+
-- добавить в образ скрипт для загрузки последнего бэкапа из папки backup, чтобы при запуске автоматом создавались все таблички. Возможно нужно задать переменную среды в которой определять надо ли создавать таблички из бэкап папки
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3'
2+
services:
3+
postgres_master:
4+
container_name: postgres_master
5+
image: custom_postgres:1.4
6+
restart: unless-stopped
7+
volumes:
8+
- ./data:/var/lib/postgresql/data
9+
- ./init-script/init.sql:/docker-entrypoint-initdb.d/init.sql
10+
- ./data-slave:/var/lib/postgresql/data-slave
11+
- ./init-script:/etc/postgresql/init-script
12+
- ./init-script/config/pg_hba.conf:/etc/postgresql/pg_hba.conf
13+
- ./init-script/config/postgres.conf:/etc/postgresql/postgresql.conf
14+
ports:
15+
- "5432:5432"
16+
env_file:
17+
- ../.env
18+
19+
postgres_slave:
20+
container_name: postgres_slave
21+
image: custom_postgres:1.4
22+
restart: always
23+
volumes:
24+
- ./data-slave:/var/lib/postgresql/data
25+
- ./init-script/config/pg_hba.conf:/etc/postgresql/pg_hba.conf
26+
- ./init-script/config/postgres.conf:/etc/postgresql/postgresql.conf
27+
ports:
28+
- "5434:5432"
29+
env_file:
30+
- ../.env
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Memory Configuration
2+
shared_buffers = 512MB
3+
effective_cache_size = 2GB
4+
work_mem = 51MB
5+
maintenance_work_mem = 102MB
6+
7+
# Checkpoint Related Configuration
8+
min_wal_size = 2GB
9+
max_wal_size = 3GB
10+
checkpoint_completion_target = 0.9
11+
wal_buffers = -1
12+
13+
# Network Related Configuration
14+
listen_addresses = '*'
15+
max_connections = 10
16+
17+
# Storage Configuration
18+
random_page_cost = 1.1
19+
effective_io_concurrency = 200
20+
21+
# Worker Processes Configuration
22+
max_worker_processes = 8
23+
max_parallel_workers_per_gather = 2
24+
max_parallel_workers = 2
25+
26+
# Logging configuration for pgbadger
27+
logging_collector = on
28+
log_checkpoints = on
29+
log_connections = on
30+
log_disconnections = on
31+
log_lock_waits = on
32+
log_temp_files = 0
33+
lc_messages = 'C'
34+
35+
# Adjust the minimum time to collect the data
36+
log_min_duration_statement = '10s'
37+
log_autovacuum_min_duration = 0
38+
39+
# Replication
40+
wal_level = logical
41+
hot_standby = on
42+
max_wal_senders = 2
43+
max_replication_slots = 2
44+
hot_standby_feedback = on
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
primary_conninfo = 'host=postgres_master port=5432 user=postgres password=postgres
2+
primary_slot_name = 'replication_slot_slave1'

HAPostgres/scripts/backup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
current_date=$(date +"%Y%m%d")
3+
echo "db name"
4+
read dbname
5+
backup_file="/backup/backup-$dbname-$current_date.sql"
6+
pg_dump -U $POSTGRES_USERNAME -d $dbname > $backup_file
7+
echo "Dumped file with name $backup_file for db $dbname"

HAPostgres/scripts/createdb.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
echo "enter db name"
3+
read dbname
4+
createdb -U $POSTGRES_USERNAME $dbname
5+
echo "enter filename"
6+
read filename
7+
psql -d $dbname -U $POSTGRES_USERNAME -f /backup/$filename

VPN/nginx.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
events {
2+
worker_connections 1000;
3+
}
4+
5+
http {
6+
server {
7+
listen 80;
8+
9+
location / {
10+
proxy_pass http://app:8080;
11+
}
12+
}
13+
server {
14+
listen 8080;
15+
server_name example.com;
16+
17+
location / {
18+
allow 185.242.85.29;
19+
deny all;
20+
proxy_pass http://grafana:3000;
21+
}
22+
}
23+
}

entropt_devops/playbook.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
- hosts: all
2+
become: true
3+
tasks:
4+
- name: Install aptitude
5+
apt:
6+
name: aptitude
7+
state: latest
8+
update_cache: true
9+
10+
- name: Install required system packages
11+
apt:
12+
pkg:
13+
- apt-transport-https
14+
- ca-certificates
15+
- curl
16+
- software-properties-common
17+
- python3-pip
18+
- virtualenv
19+
- python3-setuptools
20+
state: latest
21+
update_cache: true
22+
23+
- name: Add Docker GPG apt Key
24+
apt_key:
25+
url: https://download.docker.com/linux/ubuntu/gpg
26+
state: present
27+
28+
- name: Add Docker Repository
29+
apt_repository:
30+
repo: deb https://download.docker.com/linux/ubuntu focal stable
31+
state: present
32+
33+
- name: Update apt and install docker-ce
34+
apt:
35+
name: docker-ce
36+
state: latest
37+
update_cache: true
38+
39+
- name: Install Docker Module for Python
40+
pip:
41+
name: docker

linuxADM/Vagrantfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
nodes = [
22
{ :hostname => 'ubuntu1-master', :ip => '10.245.1.100', :memory => 2048, :cpu => 1, :boxname => 'spox/ubuntu-arm' },
3-
# { :hostname => 'ubuntu2-worker', :ip => '10.245.1.334', :memory => 2048, :cpu => 1, :boxname => 'spox/ubuntu-arm' },
3+
# { :hostname => 'ubuntu2-worker', :ip => '10.245.1.101', :memory => 2048, :cpu => 1, :boxname => 'spox/ubuntu-arm' },
44
]
55

66
Vagrant.configure("2") do |config|
@@ -20,8 +20,5 @@ Vagrant.configure("2") do |config|
2020
vmware.linked_clone = false
2121
end
2222
end
23-
config.vm.provision "ansible" do |ansible|
24-
ansible.playbook = "lab4/taskPlaybook.yml"
25-
end
2623
end
2724
end

linuxADM/lab4/taskPlaybook.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,4 @@
4040
- name: change project dir permissions
4141
shell: |
4242
chmod -R ug+rw /home/vagrant/shared/project
43-
chmod -R o-rx /home/vagrant/shared/project
44-
45-
46-
43+
chmod -R o-rx /home/vagrant/shared/project

nginx/load_balancing/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.9-slim
2+
3+
WORKDIR /app
4+
5+
COPY . .
6+
RUN pip install -r requirments.txt
7+
CMD gunicorn --bind 0.0.0.0:5000 wsgi:app
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3'
2+
services:
3+
app:
4+
image: pyapp:1.1
5+
ports:
6+
- "5000"
7+
nginx:
8+
image: nginx
9+
depends_on:
10+
- app
11+
ports:
12+
- "8080:80"
13+
volumes:
14+
- ./nginx.conf:/etc/nginx/nginx.conf:ro

start.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ cqlsh -e "
66
CREATE KEYSPACE student_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
77
CREATE TABLE student_keyspace.students (
88
id uuid PRIMARY KEY,
9-
age int,
10-
email text,
11-
name text
9+
birthday int,
10+
group text,
11+
name text,
12+
surname text
1213
) WITH additional_write_policy = '99p'
1314
AND bloom_filter_fp_chance = 0.01
1415
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
@@ -30,5 +31,4 @@ CREATE MATERIALIZED VIEW student_keyspace.students_by_age AS
3031
SELECT id, age, email, name
3132
FROM student_keyspace.students
3233
WHERE id IS NOT NULL AND age IS NOT NULL
33-
PRIMARY KEY (age, id);
34-
"
34+
PRIMARY KEY (age, id);"

0 commit comments

Comments
 (0)