Kings of DEVOPS
10 subscribers
1 file
1 link
🐍 Pythonda songi va tarqalmagan kodlar kanali: @KingsOfPy

⚙️ JavaScriptda so'ngi va tarqalmagan kodlar kanali: @Kings_of_Js

🗄️DevOps uchun eng kerakli va foydali kanal @kingsofdevops

Admin : @Mistrdev
Download Telegram
Channel created
DevOps Haqida malumotlar tashlanadigan kanal
🔥1
sudo apt install ncdu -y
sudo ncdu /



serverning to'liq xotirasini ko'rsatadigan funksiya juda foydali ekan sizlarga ham ulashyapman )
Postgresql ni Ubuntu serverga o'rnatish va sozlash.

1️⃣ Serverni yangilash
sudo apt update && sudo apt upgrade -y

2️⃣ PostgreSQL o‘rnatish
sudo apt install postgresql postgresql-contrib -y

3️⃣ Xizmatni tekshirish
sudo systemctl status postgresql

4️⃣ Postgres foydalanuvchisi orqali kirish
sudo -i -u postgres
psql

5️⃣ Parol qo‘yish
\password postgres

6️⃣ Yangi baza yaratish
CREATE DATABASE mydb;
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;

7️⃣ Chiqish
\q
exit

8️⃣ Ulanishni sozlash (masofadan kirish kerak bo‘lsa)
Config fayllar odatda shu yerda bo‘ladi:

/etc/postgresql/16/main/postgresql.conf
/etc/postgresql/16/main/pg_hba.conf

Masalan, postgresql.conf ichida:
listen_addresses = '*'

qilib qo‘yiladi.

pg_hba.conf faylida:
host    all             all             0.0.0.0/0               md5

Keyin serverni qayta ishga tushiramiz:
sudo systemctl restart postgresql
server {
server_name miniapp-dev.suvgo.uz;
client_max_body_size 100M;
charset utf-8;

location /_next/static/ {
alias /var/www/suvgo-miniapp/dev/.next/static/;
expires 1y;
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
}

location / {
proxy_pass http://localhost:6006;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}



NEXT JS NGINX CONFIGURATION
server {
listen 80;
server_name domain;
client_max_body_size 100M;
charset utf-8;

root /var/www/obkeber-adminka/prod/dist;
index index.html;

location / {
try_files $uri $uri/ /index.html?$args;
}
}




REACT NGINX CONF
git clone --single-branch --branch <branch-nomi> <repo-url>



Aynan bitta branchdan clone olish uchun
name: Node.js DEV CD (Frontend)

on:
push:
branches: [dev]
pull_request:
branches: [dev]

jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: Deploy and Build Frontend
id: deploy
env:
SSHPASS: ${{ secrets.PASSWORD }}
run: |
set -o pipefail
{
sshpass -e ssh \
-o StrictHostKeyChecking=no \
-o PubkeyAuthentication=no \
-o PreferredAuthentications=password \
-o NumberOfPasswordPrompts=1 \
${{ secrets.USERNAME }}@${{ secrets.HOST }} "
cd /var/www/korzinka-admin/dev &&
git pull origin dev &&
pnpm i &&
pnpm run build
"
} 2>&1 | tee deploy.log

# ✅ SUCCESS notification
- name: Send success message to Telegram topic
if: success()
run: |
COMMIT_MSG="${{ github.event.head_commit.message }}"
AUTHOR="${{ github.actor }}"
BRANCH="${{ github.ref_name }}"
TIME=$(date '+%Y-%m-%d %H:%M:%S')

curl -s -X POST https://api.telegram.org/bot${{ secrets.BOT_TOKEN }}/sendMessage \
-d chat_id="-1003256642968" \
-d parse_mode=Markdown \
-d text="✅ *KORZINKA ADMIN DEV (FRONTEND)* muvaffaqiyatli ishga tushdi! 🚀%0A%0A🕓 *${TIME}*%0A👤 *${AUTHOR}*%0A🌿 Branch: *${BRANCH}*%0A📝 Commit: _${COMMIT_MSG}_"

# ❌ FAILURE notification (with error log)
- name: Send failure message to Telegram topic
if: failure()
run: |
COMMIT_MSG="${{ github.event.head_commit.message }}"
AUTHOR="${{ github.actor }}"
BRANCH="${{ github.ref_name }}"
TIME=$(date '+%Y-%m-%d %H:%M:%S')
ERROR_LOG=$(tail -n 15 deploy.log | sed 's/"/\\"/g' | sed 's/$/%0A/' | tr -d '\n')

curl -s -X POST https://api.telegram.org/botTOKEN/sendMessage \
-d chat_id="-1003256642968" \
-d parse_mode=Markdown \
-d text="❌ *KORZINKA ADMIN DEV (FRONTEND)* ishga tushirilmadi!%0A%0A🕓 *${TIME}*%0A👤 *${AUTHOR}*%0A🌿 Branch: *${BRANCH}*%0A📝 Commit: _${COMMIT_MSG}_%0A%0A⚠️ *Xato log (oxirgi 15 qator):*%0A\`\`\`${ERROR_LOG}\`\`\`"
server {
server_name DOMEN.uz;
client_max_body_size 100M;
charset utf-8;

location /_next/static/ {
alias /var/www/telegram-mini-app/dev/.next/static/;
expires 1y;
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
}

location / {
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
proxy_pass http://localhost:2002;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}



NEXT JS - NGINX CONFIGURATION
servedagi barcha userlarni korish:

awk -F: '$3 >= 1000 {print $1}' /etc/passwd


Online (hozir aktiv) userlarni ko‘rish:
who


Login qilgan hamma sessiyalar:
w


Serverga qachon kim kirgan tarixini ko‘rish:
last
Serverga faqat ssh key orqali kirishni sozlash:

1. Windowsda ssh keyni yaratish:
ssh-keygen -t ed25519 -C "your_email@example.com"


2. Yaratilgan ssh keyni ko'rish:

CMD da:
type %USERPROFILE%\.ssh\id_ed25519.pub

Powershellda:
Get-Content ~/.ssh/id_ed25519.pub


3. Serverda .ssh papkasini yaratish (agar bo'lmasa)
mkdir -p ~/.ssh
chmod 700 ~/.ssh


4. Public keyni authorized_keys ichiga yozish:
echo "BU_YERGA_PUBLIC_KEY_PASTA" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Yoki qo'lda yozib qo'ysangiz ham bo'ladi:
nano ~/.ssh/authorized_keys


5. SSH serverni faqat key bilan ishlashga sozlash

SSH konfiguratsiyasini ochamiz:
sudo nano /etc/ssh/sshd_config

Quyidagilar ON bo‘lishi shart:
PubkeyAuthentication yes
PasswordAuthentication no


6. SSH servisini qayta ishga tushirish:
sudo systemctl restart ssh



7. Windows’dan ssh orqali key bilan ulanish:

ssh -i ~/.ssh/id_ed25519 topcargo@SERVER_IP


Agar default .ssh kalitlar bo‘lsa, -i shart emas:

ssh topcargo@SERVER_IP
git clone --single-branch --branch <branch-nomi> <repo-url>


o'ziz xohlagan branchdan clone qilib olish komandasi
module.exports = {
apps: [
{
name: "dev-backend",
script: "dist/main.js",

exec_mode: "fork",
instances: 1,

cwd: "/root/CargoSoft/backend/dev",

autorestart: true,
watch: false,
max_memory_restart: "500M",

out_file: "/var/log/pm2/dev-backend-out.log",
error_file: "/var/log/pm2/dev-backend-error.log",
log_date_format: "YYYY-MM-DD HH:mm:ss",

env: {
NODE_ENV: "development",
PORT: 4009
}
},

{
name: "prod-backend",
script: "dist/main.js",
exec_mode: "cluster",
instances: "max",

cwd: "/root/CargoSoft/backend/prod",

autorestart: true,
watch: false,
max_memory_restart: "700M",

out_file: "/var/log/pm2/prod-backend-out.log",
error_file: "/var/log/pm2/prod-backend-error.log",
log_date_format: "YYYY-MM-DD HH:mm:ss",

env: {
NODE_ENV: "production",
PORT: 4000
}
}
]
};

pm2 uchun nestjs ga ecosystem fayli example
apt install -y docker.io
systemctl enable docker
systemctl start docker


docker run -d --restart=always -p 3031:3001 \
-v uptime-kuma:/app/data \
--name uptime-kuma \
louislam/uptime-kuma:1



Server uchun eng kerakli monitoring xizmati Telegramdan notification yuboradi