Last active
September 29, 2016 21:00
-
-
Save andypotanin/6128333 to your computer and use it in GitHub Desktop.
Google Compute - Setup CentOS Apache2/Varnish/Node.js Stack
This file contains 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
# Set variables in .bash_profile for convenience: | |
# GOOGLE_COMPUTE_PROJECT_NAME - e.g. "my-project" | |
# GOOGLE_COMPUTE_USER - e.g. "bob" | |
# GOOGLE_COMPUTE_INSTANCE_NAME - e.g. "us-east-instance" | |
# GOOGLE_COMPUTE_HOSTNAME - e.g. "mywebsite.com" | |
# | |
# Services | |
# /etc/init.d/httpd | |
# /etc/init.d/mysql | |
# /etc/init.d/varnish | |
# | |
# service mysqld status | |
# service httpd status | |
# service varnish status | |
# Cache project name | |
gcutil getproject --project=$GOOGLE_COMPUTE_PROJECT_NAME --cache_flag_values | |
# Add firewall rules | |
gcutil addfirewall port-80 --description="Open up port 80." --allowed="tcp:80" | |
gcutil addfirewall port-443 --description="Open up port 443." --allowed="tcp:443" | |
# gcutil addfirewall port-3000 --description="Open up port 3000." --allowed="tcp:3000" | |
# gcutil addfirewall port-8000 --description="Open up port 8000. (Temporary)" --allowed="tcp:8000" | |
# gcutil addfirewall port-10000 --description="Open up port 10000. (Temporary)" --allowed="tcp:10000" | |
# gcutil addfirewall port-11000 --description="Open up port 11000. (Temporary)" --allowed="tcp:11000" | |
# Without this could not connect via Coda or whatever using SSH | |
sudo ssh-add ~/.ssh/google_compute_engine | |
# SSH Into Project | |
gcutil ssh $GOOGLE_COMPUTE_INSTANCE_NAME | |
# Work as root | |
sudo su | |
# Update Yum and install common CentosOS stuf | |
yum -y update | |
yum -y install links | |
# Install LAMP stack (source http://www.rickymills.com/tutorials/install-apache2-php5-mysql5-with-yum-on-centos/) | |
yum -y install httpd php mysql mysql-server php-mysql | |
yum --enablerepo=remi,remi-test install -y php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo | |
# Configure Apache as Service | |
chkconfig httpd on | |
# Install PHPMyAdmin | |
rpm -ivh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm && yum -y update | |
yum -y install phpMyAdmin | |
# Start MySQL Services | |
/sbin/chkconfig mysqld on | |
/sbin/service mysqld start | |
chkconfig --levels 235 mysqld on | |
# Set MySQL Password (replace with unique password) | |
/usr/bin/mysqladmin -u root password 'some-random-password' | |
# Forward port 80 to 8080 and port 443 to 8443, respectively | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443 | |
# Save IP Table updates | |
iptables -F | |
service iptables save | |
# Install things we need for Node.js | |
yum -y groupinstall "Development Tools" | |
yum -y install gcc | |
yum -y install gcc-c++ | |
yum -y install screen | |
# Add "git svn" capability to git | |
yum -y install git | |
yum -y install git-svn | |
yum -y install svn | |
# Install Node.js 0.10.15 | |
cd /usr/src | |
wget http://nodejs.org/dist/latest/node-v0.10.21.tar.gz && tar zxf node-v0.10.21.tar.gz && cd node-v0.10.21 | |
bash ./configure | |
make | |
make install | |
# Add non-privileged user (will need to set a password after second command) | |
useradd -d /home/www -m www | |
passwrd www | |
# Add yourself to www group | |
usermod -G $GOOGLE_COMPUTE_USER,www www | |
# Configure Apache | |
mkdir -p /var/www/public_html | |
chown -R www:wwwwww /var/www/public_html | |
chmod 755 /var/www/public_html | |
# Manual Step: Configure vhosts in /etc/httpd/conf/httpd.conf | |
# Restart Apache | |
apachectl -k stop | |
/etc/init.d/httpd restart | |
# Install Varnish (Source http://www.tecmint.com/install-varnish-cache-web-accelerator/) | |
cd ~ && wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm | |
rpm --nosignature -i varnish-release-3.0-1.noarch.rpm | |
unlink varnish-release-3.0-1.noarch.rpm | |
yum -y install varnish | |
# Manual Step: Configure Varnish VCL in /etc/varnish/default.vcl | |
# Install Webmin (/usr/libexec/webmin/) | |
touch /etc/yum.repos.d/webmin.repo | |
curl https://gist.github.com/andypotanin/6129080/raw >> webmin.repo | |
wget http://www.webmin.com/jcameron-key.asc | |
rpm --import jcameron-key.asc | |
mkdir /etc/webmin | |
touch /etc/webmin/miniserv.conf # This should be added automatically? | |
# Install VirtualMin (Source: http://www.smarchsoft.com/virtualmin_on_centos6.html ) | |
cd ~ | |
wget http://software.virtualmin.com/gpl/scripts/install.sh | |
chmod +x install.sh | |
./install.sh | |
unlink install.sh | |
# Start Varnish | |
chkconfig --level 345 varnish on | |
/etc/init.d/varnish restart | |
# Symbolically link node_modules (make global modules globally accessible) | |
sudo ln -s /usr/local/lib/node_modules /node_modules | |
# Install some useful Node.js modules globally | |
npm install -g express | |
npm install -g http-proxy | |
npm install -g supervisor | |
# Leave sudo | |
exit | |
# Create symbolic links for common configuration files | |
sudo ln -s /etc/varnish/default.vcl ~/varnish.vcl | |
sudo ln -s /etc/httpd/conf/httpd.conf ~/http.conf | |
sudo ln -s /etc/hosts ~/hosts | |
sudo ln -s /etc/httpd/conf.d/phpMyAdmin.conf ~/phpMyAdmin.conf | |
sudo ln -s /etc/webmin/miniserv.conf ~/webmin.miniserv.conf | |
sudo ln -s /etc/sysconfig/varnish ~/sysconfig.varnish | |
sudo ln -s /var/www/public_html ~/public_html | |
# Change ownership to current user (temp) | |
sudo chown $USER /etc/varnish/default.vcl | |
sudo chown $USER /etc/httpd/conf/httpd.conf | |
sudo chown $USER /etc/yum.repos.d | |
sudo chown $USER /etc/hosts # Can edit hosts if needed | |
sudo chown $USER /etc/sysconfig/network # Can edit hostname here if needed. | |
sudo chown $USER /etc/httpd/conf.d/phpMyAdmin.conf | |
sudo chown $USER /etc/webmin/miniserv.conf | |
sudo chown $USER /etc/sysconfig/varnish | |
# Restart network service (if hostname changed) | |
# hostname $GOOGLE_COMPUTE_HOSTNAME | |
# /etc/init.d/network restart | |
# Setup basic node.js app and start it (will run on port 3000) | |
cd ~ && mkdir test-app | |
express test-app && cd test-app | |
npm install && node app | |
# Ensure Services are Enabled | |
sudo chkconfig mysqld on | |
sudo chkconfig httpd on | |
sudo chkconfig varnish on | |
# sudo chkconfig web-services on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add in : yum install links -y