install.sh 7.13 KB
Newer Older
Owain Jones's avatar
Owain Jones committed
1
#!/bin/sh
Owain Jones's avatar
Owain Jones committed
2 3
# Install the packages we need to set up our gliders website + backend.
# This file doubles up as notes/instructions.
Owain Jones's avatar
Owain Jones committed
4

5
# Installed on a VirtualBox VM with 2gb RAM, 1 CPU, 8gb storage
Owain Jones's avatar
Owain Jones committed
6

Owain Jones's avatar
Owain Jones committed
7 8 9 10 11 12 13
# Based on a clean CentOS 7 minimal x64 installation
# (CentOS-7-x86_64-Minimal-1503-01)
# All configuration during CentOS install process was left as defaults
# Base installation chosen.
# One user added: gliders, pw: gliders9876

# As root:
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
14 15
yum check-update -y
yum install -y epel-release  # enables 'enterprise' software repo
16
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
17
yum install yum-plugin-replace
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
18
yum update -y 
Owain Jones's avatar
Owain Jones committed
19 20

# Install needed tools
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
21
yum install -y git rsync wget vim ansible tmux htop iotop dstat lsof telnet
Owain Jones's avatar
Owain Jones committed
22

Owain Jones's avatar
Owain Jones committed
23
# And inotify tools
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
24
yum install -y inotify-tools incron
Owain Jones's avatar
Owain Jones committed
25

Owain Jones's avatar
Owain Jones committed
26
# And development tools (needed to compile python libs from pip)
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
27
yum groupinstall -y "Development Tools"
Owain Jones's avatar
Owain Jones committed
28 29

# Install python libraries
30
yum install -y python-inotify numpy python-matplotlib python-virtualenv python-pip python-pandas libffi-devel python-daemon netcdf4-python ipython
Owain Jones's avatar
Owain Jones committed
31
pip install css-html-js-minify
32
pip install bcrypt
33 34
pip install future
pip install dbdreader
Owain Jones's avatar
Owain Jones committed
35 36

# Install (& configure) sendmail
37 38
# This isn't needed yet! But eventually we'd like to have theystem
# email people alerts for things (e.go velogs an alarm)
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
39
yum install -y sendmail sendmail-cf m4
Owain Jones's avatar
Owain Jones committed
40
systemctl enable sendmail
Owain Jones's avatar
Owain Jones committed
41 42

# Install & config MariaDB (MySQL)
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
43 44
yum install -y mariadb mariadb-server mariadb-devel
systemctl start mariadb.service
Owain Jones's avatar
Owain Jones committed
45 46 47 48
mysql_secure_installation
# ^ mariadb root pw was set to gliders9876, anon users + test db removed,
# remote root login disabled
systemctl enable mariadb
Owain Jones's avatar
Owain Jones committed
49

50
# Install ElasticSearch
51
# (Used for full-text searching of glider log files)
52 53 54 55 56 57
yum install -y java-1.8.0-openjdk
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cp elasticsearch.repo /etc/yum/repos.d/
yum check-update -y 
yum install -y elasticsearch
systemctl enable elasticsearch
58 59 60 61

# Install MongoDB
yum install -y mongodb python-pymongo php-pecl-mongo
systemctl enable mongod
62

root's avatar
root committed
63
# Install SQLAlchemy
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
64
yum install -y MySQL-python python-sqlalchemy
Owain Jones's avatar
Owain Jones committed
65 66

# Install PHP
67
yum install -y php php-fpm php-apc php-pdo php-mcrypt php-mbstring php-pecl-runkit phpmyadmin phpize php-intl
68 69 70 71 72 73 74 75 76 77 78 79

# We install normal PHP *then* replace with php7 packages because phpmyadmin
# wants original PHP, by replacing with php7 after the phpMA package doesn't
# complain about wrong package versions.
yum replace php-common --replace-with=php70w-common
yum install php70w-fpm php70w-opcache php70w-devel php70w-pecl-apcu

# Install "backwards compatability" extension for PHP-APC; our site and a bunch
# of other stuff depends on it.
pecl install "channel://pecl.php.net/apcu_bc-1.0.3"
echo "extension=apc.so" >> /etc/php.d/apcu.ini

80 81
cp php.ini /etc/php.ini
cp php-d-fpm.ini /etc/php.d/fpm.ini
Owain Jones's avatar
Owain Jones committed
82 83
cp php-fpm-www.conf /etc/php-fpm.d/www.conf
systemctl enable php-fpm
Owain Jones's avatar
Owain Jones committed
84

85 86
# Install NodeJS, NPM, Bower and some tools for shrinking down
# javascript and CSS
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
87
yum install -y nodejs npm
88
npm install -g bower
89 90
npm install -g uglifyjs
npm install -g uglifycss
91

Owain Jones's avatar
Owain Jones committed
92 93 94
# As for the webserver -- either apache or nginx...
# nginx is nice and fast, apache gets better support from
# CentOS etc.
95 96
# Haven't tested apache *at all* and have added stuff
# to the nginx config that makes the site work correctly
Owain Jones's avatar
Owain Jones committed
97 98 99

# FOR NGINX
# Based on https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
100 101
yum check-update -y 
yum install -y nginx
Owain Jones's avatar
Owain Jones committed
102 103 104
useradd -m gliders
gpasswd -a nginx gliders
gpasswd -a apache gliders
105
gpasswd -a wheel gliders  # let gliders user do sudo?
106
mkdir -p /var/gliders/logs /var/gliders/www/ /var/gliders/www_dev/ /var/gliders/daemon/logs/
Owain Jones's avatar
Owain Jones committed
107
chmod -R g+x /home/gliders
108
chown -R gliders:nginx /var/gliders
Owain Jones's avatar
Owain Jones committed
109
cp nginx.conf /etc/nginx/
Owain Jones's avatar
Owain Jones committed
110
cp *.nginx.conf /etc/nginx/conf.d/
111
chown gliders:nginx /etc/nginx/conf.d/gliders.nginx.conf # allow gliders user to edit their nginx config?
Owain Jones's avatar
Owain Jones committed
112 113
systemctl enable nginx

114 115 116
# Install fail2ban: This is some intrusion detection software
# that can help to block people trying to do brute-force
# logins etc.
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
117
yum install -y fail2ban
Owain Jones's avatar
Owain Jones committed
118
systemctl enable fail2ban
Owain Jones's avatar
Owain Jones committed
119 120

# Allow web through the firewall
121 122
systemctl enable firewalld
systemctl start firewalld
Owain Jones's avatar
Owain Jones committed
123
firewall-cmd --permanent --zone=public --add-service=ssh
Owain Jones's avatar
Owain Jones committed
124 125
firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
Owain Jones's avatar
Owain Jones committed
126
firewall-cmd --permanent --zone=public --add-service=8000/tcp  # port 8080 for dev branch of site
Owain Jones's avatar
Owain Jones committed
127 128
firewall-cmd --reload

129 130
# Set the system timezone to UTC
timedatectl set-timezone UTC
Owain Jones's avatar
Owain Jones committed
131

Owain Jones's avatar
Owain Jones committed
132 133 134
# And enable NTP, since for some reason it's not on by default..
timedatectl set-ntp true

Owain Jones's avatar
Owain Jones committed
135 136 137 138 139
# Install haveged to stop crypto stuff from hanging so much
# when it depletes /dev/random..! (The bcrypt library on PHP
# has a tendency to do this, which causes the occasional
# gateway timeout when registering / changing user passwords
# on the website.
Alvaro Lorenzo's avatar
test  
Alvaro Lorenzo committed
140
yum install -y haveged
Owain Jones's avatar
Owain Jones committed
141
systemctl enable haveged
Owain Jones's avatar
Owain Jones committed
142 143 144 145

# Enable SystemD User services to start automatically on machine
# boot and continue running even if the user never logs in...
loginctl enable-linger gliders
146

147 148 149 150 151 152 153 154
# Increase open file limits. The 'fetchlogs' service connects to a bunch of
# stuff in parallel and with everything else running on the server this could
# push it over the default 4096 (or is it 1024?) open files per user limit,
# causing programs to quit.
# https://easyengine.io/tutorials/linux/increase-open-files-limit/
cp security-limits.d-10-files.conf /etc/security/limits.d/10-files.conf
cp sysctl.d-0-filelimits.conf /etc/sysctl.d/0-filelimits.conf

155 156 157 158 159 160
# Add dev.gliders.localhost and gliders.localhost entries
# This allows us to access the gliders website from nginx on this
# machine.
echo '127.0.0.1 dev.gliders.localhost gliders.localhost' >> /etc/hosts
echo '::1 dev.gliders.localhost gliders.localhost' >> /etc/hosts

161 162 163 164 165 166 167 168 169 170 171 172 173 174
# (optional) Compile HHVM -- this will take ages!
# yum install cpp gcc-c++ cmake git psmisc {binutils,boost,jemalloc}-devel \
# {ImageMagick,sqlite,tbb,bzip2,openldap,readline,elfutils-libelf,gmp,lz4,pcre}-devel \
# lib{xslt,event,yaml,vpx,png,zip,icu,mcrypt,memcached,cap,dwarf}-devel \
# {unixODBC,expat,mariadb}-devel lib{edit,curl,xml2,xslt}-devel \
# glog-devel oniguruma-devel ocaml gperf enca libjpeg-turbo-devel openssl-devel \
# mariadb mariadb-server make -y
# git clone https://github.com/facebook/hhvm -b master hhvm --recursive
# cd hhvm
# cmake .
# make -j4
# make install
# cd -
# cp hhvm.service /etc/systemd/system/
175
# systemctl enable hhvm
176

177 178 179 180 181
# Install memcached
yum install -y memcached memcached-devel libmemcached-devel
systemctl enable memcached
systemctl start memcached

182 183
# Create gliders dirs and allow the webserver to read/write to them
# (Mostly this sets up SELinux rules)
Owain Jones's avatar
Owain Jones committed
184
mkdir -p /var/gliders/www_dev /var/gliders/www /var/gliders/incoming /var/gliders/logs /var/gliders/static /var/gliders/daemon/logs /var/gliders/www_tmp
185 186
chown -R gliders /var/gliders
setsebool -P httpd_can_network_connect 1
Owain Jones's avatar
Owain Jones committed
187
chcon -R -t httpd_sys_rw_content_t /usr/share/nginx
188 189 190 191 192
chcon -R -t httpd_sys_rw_content_t /var/gliders/www
chcon -R -t httpd_sys_rw_content_t /var/gliders/www_dev
chcon -R -t httpd_sys_rw_content_t /var/gliders/incoming
chcon -R -t httpd_sys_rw_content_t /var/gliders/static
chcon -R -t httpd_sys_content_t /var/gliders/logs