Created
January 30, 2021 22:21
-
-
Save alsantos123/0e1c0864e9685572628354b75795ddc5 to your computer and use it in GitHub Desktop.
git, git-flow, awscli, jq, nginx, docker, portainer, nvm, code-server, cloudwatch agent e swap file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| chmod 644 /var/log/syslog | |
| apt-get update && apt-get upgrade -y | |
| # TOOLS | |
| apt -y install git git-flow | |
| apt -y install zip | |
| apt -y install awscli | |
| apt -y install jq | |
| apt -y install mosh | |
| # NGINX | |
| apt-get update --fix-missing && \ | |
| apt-get install -y software-properties-common && \ | |
| rm -rf /var/lib/apt/lists/* | |
| add-apt-repository -y ppa:ondrej/nginx | |
| apt-get -y install nginx | |
| systemctl enable nginx | |
| chmod 644 /var/log/nginx/error.log | |
| # Docker | |
| sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common | |
| curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
| sudo apt-key fingerprint 0EBFCD88 | |
| sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu \ | |
| $(lsb_release -cs) \ | |
| stable" | |
| sudo apt-get update | |
| sudo apt-get install -y docker-ce docker-ce-cli containerd.io | |
| # Docker group | |
| sudo groupadd docker | |
| udo usermod -aG docker ubuntu | |
| # Portainer | |
| sudo docker volume create portainer_data | |
| docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce | |
| # # JHipster Registry | |
| # docker run -d -p 8080:8761 --name=registry jhipster/jhipster-registry | |
| # NVM Node + code-server | |
| cat > /tmp/subscript.sh << EOF | |
| #!/bin/bash | |
| echo "instalando nvm" | |
| wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash | |
| echo 'export NVM_DIR="/home/ubuntu/.nvm"' >> /home/ubuntu/.bashrc | |
| echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> /home/ubuntu/.bashrc | |
| # Dot source the files to ensure that variables are available within the current shell | |
| . /home/ubuntu/.nvm/nvm.sh | |
| . /home/ubuntu/.profile | |
| . /home/ubuntu/.bashrc | |
| nvm install --lts | |
| nvm ls | |
| echo "instalando code-server" | |
| npm install pm2 -g | |
| curl -fsSL https://code-server.dev/install.sh | sh | |
| pm2 start "PASSWORD=123456 code-server --bind-addr 0.0.0.0:3000" --name code-server | |
| pm2 save | |
| EOF | |
| chown ubuntu:ubuntu /tmp/subscript.sh && chmod a+x /tmp/subscript.sh | |
| sleep 1; su - ubuntu -c "/tmp/subscript.sh" | |
| # .bashrs | |
| cat >> /home/ubuntu/.bashrc << EOF | |
| export EDITOR=vim | |
| alias watchn1="watch -n 1" | |
| alias l="ls -lh" | |
| alias la="ls -lha" | |
| alias cc=clear | |
| alias ds='docker ps -a --format "table {{.ID}} | {{.Names}}\t=> {{.Command}}\t {{.Image}}\t {{.Status}}"' | |
| alias ddc=docker-compose | |
| echo "---------" | |
| echo "IP Publico: " `curl -s http://checkip.amazonaws.com` | |
| echo "IP Privado: " `/sbin/ip route|awk '/default/ { print $3 }'` | |
| echo "EC2: " `curl -s http://169.254.169.254/latest/meta-data/instance-type` | |
| echo "UPTIME: " `uptime` | |
| echo "---------" | |
| EOF | |
| # Cloudwatch agent (amd64) | |
| wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb | |
| sudo dpkg -i -E ./amazon-cloudwatch-agent.deb | |
| echo '{ | |
| "agent": { | |
| "run_as_user": "cwagent", | |
| "metrics_collection_interval": 300 | |
| }, | |
| "metrics": { | |
| "metrics_collected": { | |
| "mem": { | |
| "measurement": ["mem_used_percent"] | |
| }, | |
| "swap": { | |
| "measurement": ["used_percent"] | |
| }, | |
| "disk": { | |
| "measurement": ["used_percent"], | |
| "resources": ["/"] | |
| }, | |
| "processes": { | |
| "measurement": ["total", "wait", "zombies"] | |
| } | |
| }, | |
| "append_dimensions": { | |
| "ImageId": "${aws:ImageId}", | |
| "InstanceId": "${aws:InstanceId}", | |
| "InstanceType": "${aws:InstanceType}", | |
| "AutoScalingGroupName": "${aws:AutoScalingGroupName}" | |
| } | |
| } | |
| }' > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json | |
| /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json | |
| # swap file | |
| fallocate -l 2G /swapfile | |
| sudo chmod 600 /swapfile | |
| sudo mkswap /swapfile | |
| sudo swapon /swapfile | |
| echo "/swapfile swap swap defaults 0 0" >> /etc/fstab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment