add aws scripts
This commit is contained in:
parent
8fbe671229
commit
564c3ed8ea
40
sk1/aws config/deploy-instance.sh
Normal file
40
sk1/aws config/deploy-instance.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ========== Configuration ==========
|
||||
AMI_ID="ami-01c7096235204c7be"
|
||||
INSTANCE_TYPE="t3.xlarge"
|
||||
KEY_NAME="mykey"
|
||||
SECURITY_GROUP="sg-0e08dfcd575ebfe2e"
|
||||
EIP_ALLOC_ID="eipalloc-0ab8a278c183034a3"
|
||||
SUBNET_ID="subnet-015876fa51f73f1ad"
|
||||
|
||||
# ========== Launch EC2 instance ==========
|
||||
echo "Launching EC2 instance..."
|
||||
INSTANCE_ID=$(aws ec2 run-instances \
|
||||
--image-id $AMI_ID \
|
||||
--instance-type $INSTANCE_TYPE \
|
||||
--key-name $KEY_NAME \
|
||||
--security-group-ids $SECURITY_GROUP \
|
||||
--subnet-id $SUBNET_ID \
|
||||
--associate-public-ip-address \
|
||||
--block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"VolumeSize\":400,\"VolumeType\":\"gp3\"}}]" \
|
||||
--query "Instances[0].InstanceId" \
|
||||
--output text)
|
||||
|
||||
echo "Waiting for instance $INSTANCE_ID to start..."
|
||||
aws ec2 wait instance-running --instance-ids $INSTANCE_ID
|
||||
echo "Instance $INSTANCE_ID is now running."
|
||||
|
||||
# ========== Associate Elastic IP ==========
|
||||
echo "Associating Elastic IP..."
|
||||
aws ec2 associate-address \
|
||||
--instance-id $INSTANCE_ID \
|
||||
--allocation-id $EIP_ALLOC_ID
|
||||
|
||||
# ========== Get Elastic IP ==========
|
||||
PUBLIC_IP=$(aws ec2 describe-addresses \
|
||||
--allocation-ids $EIP_ALLOC_ID \
|
||||
--query "Addresses[0].PublicIp" \
|
||||
--output text)
|
||||
|
||||
echo "Elastic IP $PUBLIC_IP has been successfully associated with instance $INSTANCE_ID."
|
24
sk1/aws config/setup-docker.sh
Normal file
24
sk1/aws config/setup-docker.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Updating packages..."
|
||||
sudo apt-get update
|
||||
|
||||
echo "Installing Docker..."
|
||||
sudo apt-get install -y docker.io
|
||||
|
||||
echo "Installing Docker Compose..."
|
||||
sudo apt-get install -y docker-compose
|
||||
|
||||
echo "Allowing Docker to run without sudo..."
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
|
||||
echo "Enabling Docker to start on boot..."
|
||||
sudo systemctl enable docker
|
||||
sudo systemctl start docker
|
||||
|
||||
echo "Installing Git..."
|
||||
sudo apt-get install -y git
|
||||
|
||||
echo "Done! You can now run:"
|
||||
echo "docker-compose up --build"
|
80
sk1/aws config/setup-nginx-certs.sh
Normal file
80
sk1/aws config/setup-nginx-certs.sh
Normal file
@ -0,0 +1,80 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCAL_PEM_PATH="/c/Users/olezk/Desktop/mykey.pem"
|
||||
USERNAME="ubuntu"
|
||||
DOMAIN="healthai-tuke.com"
|
||||
CERT_ARCHIVE_PATH="/c/Users/olezk/Desktop/healthai-certs.tar.gz"
|
||||
SERVER_IP="52.51.10.99" # Elastic IP
|
||||
|
||||
|
||||
echo "Removing old known_hosts entry..."
|
||||
ssh-keygen -R "$SERVER_IP" 2>/dev/null
|
||||
|
||||
|
||||
if [ ! -f "$CERT_ARCHIVE_PATH" ]; then
|
||||
echo "Certificate archive not found: $CERT_ARCHIVE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
echo "Copying certificate archive to server $SERVER_IP..."
|
||||
scp -i "$LOCAL_PEM_PATH" "$CERT_ARCHIVE_PATH" "$USERNAME@$SERVER_IP:~/"
|
||||
|
||||
|
||||
echo "Configuring Nginx and SSL..."
|
||||
|
||||
ssh -i "$LOCAL_PEM_PATH" -o StrictHostKeyChecking=no "$USERNAME@$SERVER_IP" <<EOF
|
||||
set -e
|
||||
|
||||
sudo apt update
|
||||
sudo apt install -y nginx
|
||||
|
||||
# Unpack certificates
|
||||
sudo tar xzvf ~/healthai-certs.tar.gz -C /
|
||||
|
||||
# Remove old config if exists
|
||||
sudo rm -f /etc/nginx/sites-available/$DOMAIN
|
||||
sudo rm -f /etc/nginx/sites-enabled/$DOMAIN
|
||||
|
||||
# Create new HTTPS config
|
||||
# Create new HTTPS config
|
||||
sudo tee /etc/nginx/sites-available/$DOMAIN > /dev/null <<'NGINX'
|
||||
server {
|
||||
listen 80;
|
||||
server_name healthai-tuke.com www.healthai-tuke.com;
|
||||
return 301 https://\$host\$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name healthai-tuke.com www.healthai-tuke.com;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/healthai-tuke.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/healthai-tuke.com/privkey.pem;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://localhost:5000;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://localhost:5173;
|
||||
proxy_set_header Host \$host;
|
||||
proxy_set_header X-Real-IP \$remote_addr;
|
||||
try_files \$uri \$uri/ /index.html;
|
||||
}
|
||||
}
|
||||
NGINX
|
||||
|
||||
|
||||
|
||||
sudo ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/
|
||||
sudo nginx -t && sudo systemctl restart nginx
|
||||
EOF
|
||||
|
||||
|
||||
echo "Checking if https://$DOMAIN is available..."
|
||||
curl -I --connect-timeout 5 https://$DOMAIN
|
||||
|
||||
echo "Server is ready with HTTPS at https://$DOMAIN"
|
@ -6,14 +6,14 @@ INSTANCE_ID=$(aws ec2 describe-instances \
|
||||
--output text)
|
||||
|
||||
if [ "$INSTANCE_ID" == "None" ] || [ -z "$INSTANCE_ID" ]; then
|
||||
echo "❌ Нет остановленных инстансов для запуска."
|
||||
echo "No stopped EC2 instances found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🚀 Запускаем инстанс $INSTANCE_ID..."
|
||||
echo "Starting EC2 instance: $INSTANCE_ID..."
|
||||
aws ec2 start-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "⏳ Ждём запуска..."
|
||||
echo "Waiting for the instance to enter running state..."
|
||||
aws ec2 wait instance-running --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "✅ Инстанс $INSTANCE_ID работает."
|
||||
echo "EC2 instance $INSTANCE_ID is now running."
|
@ -6,14 +6,14 @@ INSTANCE_ID=$(aws ec2 describe-instances \
|
||||
--output text)
|
||||
|
||||
if [ "$INSTANCE_ID" == "None" ] || [ -z "$INSTANCE_ID" ]; then
|
||||
echo "❌ Нет работающих инстансов для остановки."
|
||||
echo "No running EC2 instances found to stop."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🛑 Останавливаем инстанс $INSTANCE_ID..."
|
||||
echo "Stopping EC2 instance: $INSTANCE_ID..."
|
||||
aws ec2 stop-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "⏳ Ждём остановки..."
|
||||
echo "Waiting for the instance to stop..."
|
||||
aws ec2 wait instance-stopped --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "✅ Инстанс $INSTANCE_ID остановлен."
|
||||
echo "EC2 instance $INSTANCE_ID has been stopped."
|
25
sk1/aws config/terminate.sh
Normal file
25
sk1/aws config/terminate.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
INSTANCE_ID=$(aws ec2 describe-instances \
|
||||
--filters "Name=instance-state-name,Values=running" \
|
||||
--query "Reservations[-1].Instances[-1].InstanceId" \
|
||||
--output text)
|
||||
|
||||
if [ "$INSTANCE_ID" == "None" ] || [ -z "$INSTANCE_ID" ]; then
|
||||
echo "No running EC2 instances found to stop and terminate."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Stopping EC2 instance: $INSTANCE_ID..."
|
||||
aws ec2 stop-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "Waiting for the instance to stop..."
|
||||
aws ec2 wait instance-stopped --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "Terminating EC2 instance: $INSTANCE_ID..."
|
||||
aws ec2 terminate-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "Waiting for termination..."
|
||||
aws ec2 wait instance-terminated --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "Instance $INSTANCE_ID has been successfully stopped and terminated."
|
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ========== Конфигурация ==========
|
||||
AMI_ID="ami-01c7096235204c7be"
|
||||
INSTANCE_TYPE="t3.xlarge"
|
||||
KEY_NAME="mykey"
|
||||
SECURITY_GROUP="sg-0e08dfcd575ebfe2e"
|
||||
EIP_ALLOC_ID="eipalloc-0ab8a278c183034a3"
|
||||
SUBNET_ID="subnet-015876fa51f73f1ad"
|
||||
LOCAL_PEM_PATH="/c/Users/olezk/Desktop/mykey.pem"
|
||||
USERNAME="ubuntu"
|
||||
SSH_OUTPUT_FILE="ssh-key.txt"
|
||||
|
||||
# ========== Запуск EC2-инстанса ==========
|
||||
echo "🚀 Запускаем EC2 инстанс..."
|
||||
INSTANCE_ID=$(aws ec2 run-instances \
|
||||
--image-id $AMI_ID \
|
||||
--instance-type $INSTANCE_TYPE \
|
||||
--key-name $KEY_NAME \
|
||||
--security-group-ids $SECURITY_GROUP \
|
||||
--subnet-id $SUBNET_ID \
|
||||
--associate-public-ip-address \
|
||||
--query "Instances[0].InstanceId" \
|
||||
--output text)
|
||||
|
||||
echo "🟡 Инстанс создаётся: $INSTANCE_ID"
|
||||
aws ec2 wait instance-running --instance-ids $INSTANCE_ID
|
||||
echo "✅ Инстанс $INSTANCE_ID работает."
|
||||
|
||||
# ========== Получение публичного IP ==========
|
||||
PUBLIC_IP=$(aws ec2 describe-instances \
|
||||
--instance-ids "$INSTANCE_ID" \
|
||||
--query "Reservations[0].Instances[0].PublicIpAddress" \
|
||||
--output text)
|
||||
|
||||
# ========== Привязка Elastic IP ==========
|
||||
echo "🔗 Привязываем Elastic IP..."
|
||||
aws ec2 associate-address \
|
||||
--instance-id $INSTANCE_ID \
|
||||
--allocation-id $EIP_ALLOC_ID
|
||||
|
||||
echo "✅ Готово!"
|
||||
echo "🔗 IP для подключения: $PUBLIC_IP"
|
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔧 Обновляем пакеты..."
|
||||
sudo apt-get update
|
||||
|
||||
echo "🐳 Устанавливаем Docker..."
|
||||
sudo apt-get install -y docker.io
|
||||
|
||||
echo "📦 Устанавливаем Docker Compose..."
|
||||
sudo apt-get install -y docker-compose
|
||||
|
||||
echo "🔁 Разрешаем запуск Docker без sudo..."
|
||||
sudo usermod -aG docker $USER
|
||||
newgrp docker
|
||||
|
||||
echo "🔧 Включаем автозапуск Docker..."
|
||||
sudo systemctl enable docker
|
||||
sudo systemctl start docker
|
||||
|
||||
echo "🧬 Устанавливаем Git..."
|
||||
sudo apt-get install -y git
|
||||
|
||||
echo "✅ Готово! Система готова к запуску:"
|
||||
echo "👉 docker-compose up --build"
|
@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Найдём только running-инстансы
|
||||
INSTANCE_ID=$(aws ec2 describe-instances \
|
||||
--filters "Name=instance-state-name,Values=running" \
|
||||
--query "Reservations[-1].Instances[-1].InstanceId" \
|
||||
--output text)
|
||||
|
||||
if [ "$INSTANCE_ID" == "None" ] || [ -z "$INSTANCE_ID" ]; then
|
||||
echo "❌ Нет работающих (running) EC2-инстансов для остановки и удаления."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🟡 Останавливаем EC2-инстанс: $INSTANCE_ID..."
|
||||
aws ec2 stop-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "⏳ Ждём полной остановки..."
|
||||
aws ec2 wait instance-stopped --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "🔴 Удаляем остановленный инстанс: $INSTANCE_ID..."
|
||||
aws ec2 terminate-instances --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "⏳ Ждём удаления..."
|
||||
aws ec2 wait instance-terminated --instance-ids "$INSTANCE_ID"
|
||||
|
||||
echo "✅ Успешно остановлен и удалён инстанс: $INSTANCE_ID"
|
Loading…
Reference in New Issue
Block a user