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
2️⃣ PostgreSQL o‘rnatish
3️⃣ Xizmatni tekshirish
4️⃣ Postgres foydalanuvchisi orqali kirish
5️⃣ Parol qo‘yish
6️⃣ Yangi baza yaratish
7️⃣ Chiqish
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:
qilib qo‘yiladi.
pg_hba.conf faylida:
Keyin serverni qayta ishga tushiramiz:
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
Steps to deploy a Node.js app to Ubuntu Server using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt
https://gist.github.com/FirdavsCoder/fa17d1ce8e84f5ad1856a1752321d35c
https://gist.github.com/FirdavsCoder/fa17d1ce8e84f5ad1856a1752321d35c
Gist
Node.js Deployment
Node.js Deployment. GitHub Gist: instantly share code, notes, and snippets.
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:
Online (hozir aktiv) userlarni ko‘rish:
Login qilgan hamma sessiyalar:
Serverga qachon kim kirgan tarixini ko‘rish:
awk -F: '$3 >= 1000 {print $1}' /etc/passwdOnline (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:
2. Yaratilgan ssh keyni ko'rish:
CMD da:
Powershellda:
3. Serverda .ssh papkasini yaratish (agar bo'lmasa)
4. Public keyni authorized_keys ichiga yozish:
Yoki qo'lda yozib qo'ysangiz ham bo'ladi:
5. SSH serverni faqat key bilan ishlashga sozlash
SSH konfiguratsiyasini ochamiz:
Quyidagilar ON bo‘lishi shart:
6. SSH servisini qayta ishga tushirish:
7. Windows’dan ssh orqali key bilan ulanish:
Agar default .ssh kalitlar bo‘lsa, -i shart emas:
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