当前位置: 首页 > 工具软件 > aws-inventory > 使用案例 >

AWS-EC2用户数据

吕鸿朗
2023-12-01

curl http://169.254.169.254/latest/dynamic/instance-identity/document
----------------------不用密钥对登陆
#!/bin/bash
#Turn on password authentication for lab challenge
echo ‘abc@123’ | passwd --stdin root
sed -i ‘s|[#]*PasswordAuthentication no|PasswordAuthentication yes|g’ /etc/ssh/sshd_config
sed -i ‘s|PermitRootLogin forced-commands-only|PermitRootLogin yes|g’ /etc/ssh/sshd_config
service sshd restart
systemctl restart sshd
------------------------安装httpd和mysql
yum -y install httpd
service httpd restart
systemctl restart httpd
yum install mysql
yum install mysql-server
yum install mysql-devel
chgrp -R mysql /var/lib/mysql
chmod -R 770 /var/lib/mysql
service mysqld start
/usr/bin/mysqladmin -u root password ‘123’
------------------安装docker
yum update -y
yum install -y docker
service docker start
usermod -a -G docker ec2-user
yum install -y git
git clone https://github.com/awslabs/ecs-demo-php-simple-app
cd ecs-demo-php-simple-app
docker build -t yg-test .
docker run -p 80:81 yg-test

---------------------ec2远程连接RDS
#!/bin/bash
yum install -y httpd mysql*
amazon-linux-extras install -y php7.2
wget https://us-west-2-tcprod.s3.amazonaws.com/courses/ILT-TF-100-ARCHIT/v6.3.4/lab-2-webapp/scripts/inventory-app.zip
unzip inventory-app.zip -d /var/www/html/
wget https://github.com/aws/aws-sdk-php/releases/download/3.62.3/aws.zip
unzip aws -d /var/www/html
chkconfig httpd on
service httpd restart

--------------------显示实例ID
#!/bin/bash
#Turn on password authentication for lab challenge
echo ‘abc@123’ | passwd --stdin root
sed -i ‘s|[#]*PasswordAuthentication no|PasswordAuthentication yes|g’ /etc/ssh/sshd_config
sed -i ‘s|PermitRootLogin forced-commands-only|PermitRootLogin yes|g’ /etc/ssh/sshd_config
service sshd restart
systemctl restart sshd
yum -y install httpd
service httpd restart
systemctl restart httpd
echo “Hello World” >> /var/www/html/index.html
echo “” >> /var/www/html/index.html
echo “” >> /var/www/html/index.html
echo "Hello World from " >> /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/instance-id >> /var/www/html/index.html
echo “” >> /var/www/html/index.html
echo “” >> /var/www/html/index.html
echo “” >> /var/www/html/index.html
chmod 644 /var/www/html/index.html
chown root /var/www/html/index.html
chgrp wheel /var/www/html/index.html
echo “Starting httpd…”
service httpd start
chkconfig httpd on
echo “Updating Amazon ssm agent…”
yum update amazon-ssm-agent -y
echo “UserData Complete”

 类似资料: