Last active
April 2, 2019 19:51
-
-
Save stewartadam/6b3dc11cf6cee856a344 to your computer and use it in GitHub Desktop.
Script used for the SCS Linux Basics tutorial at Concordia University (2016) - discussion about Linux basics & setting up Wordpress on a CentOS 7 machine
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
#!/bin/sh | |
### | |
### Example usage of common commands | |
### | |
# pwd | |
# ls # it's empty | |
# cd /var/log # there are some files | |
### | |
### Different ways to grab content from files | |
### | |
# tail yum.log | |
# cat yum.log | |
# grep NetworkManger yum.log | |
### | |
### Adding arguments/parameters to commands | |
### | |
# cd / | |
# ls --help | |
# ls -l /bin | |
# ls -lh /bin | |
### | |
### Get documentation for a command | |
### | |
# man ls | |
# man grep | |
### | |
### Mode bits: sum the digits | |
### | |
# 4 = read | |
# 2 = write | |
# 1 = execute | |
# R/W owner, R else: | |
# chmod 644 securefile | |
# Everyone can do everything: | |
# chmod 777 insecurefile | |
# R/W/X owner, R/X everyone else: | |
# chmod 755 binaryfile | |
# chown user:group filename | |
### | |
### Update your system | |
### | |
yum update -y | |
### | |
### Basic packages we'll use later. | |
### | |
yum install -y nano wget psmisc postfix epel-release | |
### | |
### Install and configure webserver | |
### | |
yum install -y httpd php php-pdo php-gd php-mysql php-mbstring | |
systemctl start httpd | |
### | |
### Now, open your Linode IP in a web browser | |
### | |
# Comment out welcome.conf | |
sed -i -e 's/^\([^#]\)/#\1/g' /etc/httpd/conf.d/welcome.conf | |
# Set a timezone for PHP | |
sed -i 's|;date.timezone =|date.timezone = America/New_York|' /etc/php.ini | |
# Configure the Apache server request limits | |
# Writes the contents between "cat" line and "EOF" to /etc/httpd/conf.d/tuning.conf | |
cat << EOF > /etc/httpd/conf.d/tuning.conf | |
StartServers 2 | |
MinSpareServers 6 | |
MaxSpareServers 12 | |
MaxClients 30 | |
MaxRequestsPerChild 3000 | |
KeepAlive On | |
KeepAliveTimeout 5 | |
EOF | |
# Start the Apache webserver | |
systemctl enable httpd | |
systemctl restart httpd | |
### | |
### Install and configure the MySQL database server | |
### | |
yum install -y mariadb-server | |
systemctl enable mariadb | |
systemctl start mariadb | |
# Secure the server and setup the Wordpress database | |
cat << EOF | mysql -u root | |
UPDATE mysql.user SET Password=PASSWORD('randompw') WHERE User='root'; | |
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); | |
DELETE FROM mysql.user WHERE User=''; | |
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; | |
CREATE DATABASE wordpress; | |
GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'morerandompw'; | |
FLUSH PRIVILEGES; | |
EOF | |
### | |
### Download and unpack wordpress | |
### | |
cd /var/www/html | |
wget https://wordpress.org/latest.tar.gz | |
tar xfz latest.tar.gz | |
nano /var/www/html/wordpress/wp-config.php | |
### | |
### System monitoring to automatically restart failed services | |
### | |
# Monit is going to monitor the Apache status page - so we need to make sure it's there | |
sed -i 's|#LoadModule status_module modules/mod_status.so|LoadModule status_module modules/mod_status.so|' /etc/httpd/conf.modules.d/00-base.conf | |
cat << EOF > /etc/httpd/conf.d/server-status.conf | |
ExtendedStatus On | |
<Location /server-status> | |
SetHandler server-status | |
</Location> | |
EOF | |
service httpd restart | |
# Install Monit | |
yum install -y monit | |
# Configure monitoring for MySQL | |
cat << EOF > /etc/monit.d/mysql | |
check process mysql with pidfile /var/run/mariadb/mariadb.pid | |
start program = "/bin/systemctl start mariadb" | |
stop program = "/bin/systemctl stop mariadb" | |
if failed port 3306 protocol mysql then restart | |
if 3 restarts within 5 cycles then timeout | |
EOF | |
# Configure monitoring for Apache | |
cat << EOF > /etc/monit.d/httpd | |
check process httpd with pidfile /var/run/httpd/httpd.pid | |
start program = "/bin/systemctl start httpd" | |
stop program = "/bin/systemctl stop httpd" | |
if failed host 127.0.0.1 port 80 protocol http then restart | |
if 3 restarts within 5 cycles then timeout | |
EOF | |
systemctl enable monit | |
systemctl start monit | |
monit status | |
tail /var/log/monit.log | |
# Kill the services, they'll restart automatically <= 1 minute | |
killall httpd | |
killall mysqld | |
### | |
### Keep refreshing your web browser - you should get a timeout, but it will | |
### come back within 1 minute | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment