Skip to content

Instantly share code, notes, and snippets.

@brickpop
Last active August 29, 2015 14:07
Show Gist options
  • Save brickpop/3e8adb5f0adcdbd58c78 to your computer and use it in GitHub Desktop.
Save brickpop/3e8adb5f0adcdbd58c78 to your computer and use it in GitHub Desktop.
Amazon Linux Install Script
# SWAP
sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=1048576
sudo chown root:root /swapfile1
sudo chmod 0600 /swapfile1
sudo mkswap /swapfile1
sudo swapon /swapfile1
sudo echo "/swapfile1 swap swap defaults 0 0" > /etc/fstab
# MAIN SYSTEM UPDATE
sudo yum update -y
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/bashrc > ~/.bashrc
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/profile > ~/.profile
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/vimrc > ~/.vimrc
# NODE
sudo yum install -y gcc-c++ make openssl-devel git
wget http://nodejs.org/dist/v0.12.1/node-v0.12.1.tar.gz
tar xvfz node*
cd node*
./configure
make
sudo make install
cd
rm -Rf node*
# global node components
sudo sed -i '/secure_path = / s/$/:\/usr\/local\/bin/' /etc/sudoers
sudo npm install -g forever gulp
# MONGO DB
sudo cat <<EOF > /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
EOF
sudo yum install -y mongodb-org
sudo chkconfig mongod on
sudo service mongod start
# NGINX
sudo yum install nginx
sudo cat <<EOF > /etc/nginx/conf.d/express-app-1.conf
server {
listen 80;
server_name hostname1.net; # PORT 8080
location / {
error_page 502 = /502.html;
error_page 505 = /505.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080;
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
EOF
sudo cat <<EOF > /etc/nginx/conf.d/express-app-2.conf
server {
listen 80;
server_name hostname2.net; # PORT 8090
location / {
error_page 502 = /502.html;
error_page 505 = /505.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8090;
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
EOF
sudo mkdir -p /var/www
sudo cat <<EOF > /var/www/502.html
<html>
<head>
<style>
body {
font-family: "Helvetica Neue", "Helvetica", sans-serif;
text-align: center;
}
</style>
</head>
<body>
<h1>Service off line</h1>
<p>The service you are trying to access is not available</p>
</body>
</html>
EOF
sudo cat <<EOF > /var/www/505.html
<html>
<head>
<style>
body {
font-family: "Helvetica Neue", "Helvetica", sans-serif;
text-align: center;
}
</style>
</head>
<body>
<h1>Internal Error</h1>
<p>The server has encountered an internal error</p>
</body>
</html>
EOF
sudo chkconfig nginx on
sudo service nginx start
echo "Installation completed!"
description "appname.server.com"
env APP_PATH="/home/apps/sites/appname"
start on startup
stop on shutdown
script
cd $APP_PATH
exec forever start server.js
end script
SHORT_NAME=MASTERASP
FQDN=masterasp.uniclau.com
cd
# MAIN SYSTEM UPDATE
sudo yum update -y
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/bashrc > ~/.bashrc
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/profile > ~/.profile
curl https://raw.githubusercontent.com/jmoraleda/linux-bp/master/vimrc > ~/.vimrc
# --------------------------------------------------
# SOFTWARE
# --------------------------------------------------
yum update
yum install httpd mod_ssl mysql-server php php-mysql php-xml php-mcrypt php-mbstring php-cli
service httpd start
# --------------------------------------------------
# MySQL
service mysqld start
chkconfig mysqld on
/usr/bin/mysql_secure_installation
# --------------------------------------------------
# phpMyAdmin
cd /var/www/html
wget "http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.0-rc4/phpMyAdmin-4.0.0-rc4-all-languages.zip"
unzip phpMyAdmin*zip
mv phpMyAdmin-4.0.0-rc4-all-languages db
rm -f phpMyAdmin*zip
cp db/config.sample.inc.php db/config.inc.php
chown -R apache:apache /var/www/html
cd
# --------------------------------------------------
# MongoDB
#
# TUTORIAL on http://docs.mongodb.org/ecosystem/tutorial/install-mongodb-on-amazon-ec2/
echo "[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0" | tee -a /etc/yum.repos.d/10gen.repo
yum -y install mongo-10gen-server
yum -y install sysstat
chkconfig mongod on
/etc/init.d/mongod start
yum -y install gcc
yum -y install make
yum -y install httpd mod_ssl
yum -y install php
yum -y install php-devel php-pear
yum -y install pcre-devel
pecl channel-update pecl.php.net
pecl install mongo
echo "extension=mongo.so" > /etc/php.d/mongo.ini
# --------------------------------------------------
# DONE
server {
listen 80;
server_name *.mysite.com;
rewrite ^ https://$host$request_uri? permanent;
}
server {
listen 443 ssl;
ssl on;
location / {
proxy_pass http://localhost:8080;
}
}
ssl_certificate ssl/mysite.com.crt;
ssl_certificate_key ssl/mysite.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP;
ssl_prefer_server_ciphers on;
server {
listen 80;
server_name *.mysite.com;
rewrite ^ https://$host$request_uri? permanent;
}
server {
listen 443 ssl;
server_name one.mysite.com;
ssl on;
location / {
proxy_pass http://localhost:8080;
}
}
server {
listen 443 ssl;
server_name two.mysite.com;
ssl on;
location / {
proxy_pass http://localhost:8090;
}
}
server {
listen 80;
server_name hostname1.net; # PORT 8080
location / {
error_page 502 = /502.html;
error_page 505 = /502.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
server {
listen 80;
server_name hostname2.net; # PORT 8090
location / {
error_page 502 = /502.html;
error_page 505 = /502.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8090;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
server {
listen 80;
server_name hostname1.net; # PORT 8080
location / {
error_page 502 = /502.html;
error_page 505 = /502.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080;
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
server {
listen 80;
server_name hostname2.net; # PORT 8090
location / {
error_page 502 = /502.html;
error_page 505 = /502.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8090;
}
location /502.html {
root /var/www;
}
location /505.html {
root /var/www;
}
}
upstream hostname.net {
server 127.0.0.1:8080;}
server {
listen 0.0.0.0:80;
server_name hostname.net;
access_log /var/log/nginx/hostname.access.log;
error_log /var/log/nginx/hostname.error.log debug;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://hostname.net;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment