Tag Archives: ansible

Rackspace – Cloud Monitoring – Ansible plugins

Install the required packages (Ubunto/Centos):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
apt-get update && apt-get install python-apt python-pip build-essential python-dev git python-virtualenv -y
yum install python-pip git python-devel python-virtualenv gcc -y
apt-get update && apt-get install python-apt python-pip build-essential python-dev git python-virtualenv -y yum install python-pip git python-devel python-virtualenv gcc -y
apt-get update && apt-get install python-apt python-pip build-essential python-dev git python-virtualenv -y

yum install python-pip git python-devel python-virtualenv gcc -y

Prepare the virtual environment

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
virtualenv /root/monitorenv
. /root/monitorenv/bin/activate
pip install paramiko PyYAML jinja2 httplib2 ansible
virtualenv /root/monitorenv . /root/monitorenv/bin/activate pip install paramiko PyYAML jinja2 httplib2 ansible
virtualenv /root/monitorenv
. /root/monitorenv/bin/activate
pip install paramiko PyYAML jinja2 httplib2 ansible

Download the playbook

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git clone https://github.com/stevekaten/cloud-monitoring-plugin-deploy
cd cloud-monitoring-plugin-deploy
git clone https://github.com/stevekaten/cloud-monitoring-plugin-deploy cd cloud-monitoring-plugin-deploy
git clone https://github.com/stevekaten/cloud-monitoring-plugin-deploy
cd cloud-monitoring-plugin-deploy

Install the required plugin:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ansible-playbook -i hosts holland_mysqldump.yml
This will configure the holland_mysqldump plugin on the localhost.
ansible-playbook -i hosts mysql_slave.yml
This will configure the mysql_slave plugin on the localhost.
ansible-playbook -i hosts port_check.yml
This will fail with an error message informing you that you need to set a port.
ansible-playbook -i hosts port_check.yml -e port=8080
This will configure the port_check plugin on the localhost checking if port 8080 is open.
ansible-playbook -i hosts port_check.yml -e '{"host":"rackspace.com","port":"80"}'
This will configure the port_check plugin to check rackspace.com:80.
ansible-playbook -i hosts port_check.yml -e '{"host":"10.X.X.X","port":"3306"}'
This will configure the port_check plugin to check mysql's port 3306 on the ServiceNet address.
ansible-playbook -i hosts lsyncd_status.yml
This will configure the lsyncd_check plugin.
ansible-playbook -i hosts holland_mysqldump.yml This will configure the holland_mysqldump plugin on the localhost. ansible-playbook -i hosts mysql_slave.yml This will configure the mysql_slave plugin on the localhost. ansible-playbook -i hosts port_check.yml This will fail with an error message informing you that you need to set a port. ansible-playbook -i hosts port_check.yml -e port=8080 This will configure the port_check plugin on the localhost checking if port 8080 is open. ansible-playbook -i hosts port_check.yml -e '{"host":"rackspace.com","port":"80"}' This will configure the port_check plugin to check rackspace.com:80. ansible-playbook -i hosts port_check.yml -e '{"host":"10.X.X.X","port":"3306"}' This will configure the port_check plugin to check mysql's port 3306 on the ServiceNet address. ansible-playbook -i hosts lsyncd_status.yml This will configure the lsyncd_check plugin.
ansible-playbook -i hosts holland_mysqldump.yml

	This will configure the holland_mysqldump plugin on the localhost.

ansible-playbook -i hosts mysql_slave.yml

	This will configure the mysql_slave plugin on the localhost.

ansible-playbook -i hosts port_check.yml

	This will fail with an error message informing you that you need to set a port.

ansible-playbook -i hosts port_check.yml -e port=8080

	This will configure the port_check plugin on the localhost checking if port 8080 is open.

ansible-playbook -i hosts port_check.yml -e '{"host":"rackspace.com","port":"80"}'

	This will configure the port_check plugin to check rackspace.com:80.

ansible-playbook -i hosts port_check.yml -e '{"host":"10.X.X.X","port":"3306"}'

	This will configure the port_check plugin to check mysql's port 3306 on the ServiceNet address.

ansible-playbook -i hosts lsyncd_status.yml

	This will configure the lsyncd_check plugin.

To UNINSTALL the monitoring, you need to delete the check, removing the related file from /etc/rackspace-monitoring-agent.conf.d/ and restart the Cloud Monitoring agent.

WordPress PHP-FPM and Apache (with variables)

Sample setup for Apache virtual host and PHP-FPM pool with variables instead hard coded user details.
This could be handy if your are scripting your deploy (e.g. with Ansible).

In our example we are using the following:

Domain: example.com
SFTP user: example.com
Document root: /var/www/vhosts/example.com/httpdocs/

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/vhosts/example.com/httpdocs
<Directory /var/www/vhosts/example.com/httpdocs>
require all granted
Options Indexes
AllowOverride All
</Directory>
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" combined env=!forwarded
CustomLog "logs/example.com-access_log" proxy env=forwarded
# Configure proxy connector
<Proxy "unix:/dev/shm/example.com-php5-fpm.sock|fcgi://php-fpm">
# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time
ProxySet disablereuse=off
</Proxy>
#
# Redirect to the proxy connector
<FilesMatch \.php$>
SetHandler proxy:fcgi://php-fpm
</FilesMatch>
<Directory /var/www/vhosts/example.com/httpdocs/wp-content/uploads>
# Important for security, prevents someone from
# uploading a malicious .htaccess
AllowOverride None
SetHandler none
SetHandler default-handler
Options -ExecCGI
php_flag engine off
RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
<Files *>
AllowOverride None
SetHandler none
SetHandler default-handler
Options -ExecCGI
php_flag engine off
RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/vhosts/example.com/httpdocs <Directory /var/www/vhosts/example.com/httpdocs> require all granted Options Indexes AllowOverride All </Directory> ErrorLog "logs/example.com-error_log" CustomLog "logs/example.com-access_log" combined env=!forwarded CustomLog "logs/example.com-access_log" proxy env=forwarded # Configure proxy connector <Proxy "unix:/dev/shm/example.com-php5-fpm.sock|fcgi://php-fpm"> # we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time ProxySet disablereuse=off </Proxy> # # Redirect to the proxy connector <FilesMatch \.php$> SetHandler proxy:fcgi://php-fpm </FilesMatch> <Directory /var/www/vhosts/example.com/httpdocs/wp-content/uploads> # Important for security, prevents someone from # uploading a malicious .htaccess AllowOverride None SetHandler none SetHandler default-handler Options -ExecCGI php_flag engine off RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo <Files *> AllowOverride None SetHandler none SetHandler default-handler Options -ExecCGI php_flag engine off RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo </Files> </Directory> </VirtualHost>
<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com

        DocumentRoot /var/www/vhosts/example.com/httpdocs
        <Directory /var/www/vhosts/example.com/httpdocs>
                require all granted
                Options Indexes
                AllowOverride All
        </Directory>

        ErrorLog "logs/example.com-error_log"
        CustomLog "logs/example.com-access_log" combined env=!forwarded
        CustomLog "logs/example.com-access_log" proxy env=forwarded

	# Configure proxy connector
	<Proxy "unix:/dev/shm/example.com-php5-fpm.sock|fcgi://php-fpm">
    		# we must declare a parameter in here (doesn't matter which) or it'll not register the proxy ahead of time
	    	ProxySet disablereuse=off
	</Proxy>
	#
	# Redirect to the proxy connector
	<FilesMatch \.php$>
    		SetHandler proxy:fcgi://php-fpm
	</FilesMatch>


        <Directory /var/www/vhosts/example.com/httpdocs/wp-content/uploads>
            # Important for security, prevents someone from
            # uploading a malicious .htaccess
            AllowOverride None

            SetHandler none
            SetHandler default-handler

            Options -ExecCGI
            php_flag engine off
            RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
            <Files *>
                    AllowOverride None

                    SetHandler none
                    SetHandler default-handler

                    Options -ExecCGI
                    php_flag engine off
                    RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
            </Files>
        </Directory>
</VirtualHost>

Create a file called example.com.conf in /etc/php-fpm/pool/

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[example.com]
listen = /dev/shm/$pool-php5-fpm.sock
user = $pool
group = $pool
listen.owner = $pool
listen.group = apache
listen.mode = 0666
pm = dynamic
pm.max_children = 35
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 25
slowlog = /var/log/php-fpm/$pool-slow.log
php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session/$pool
[example.com] listen = /dev/shm/$pool-php5-fpm.sock user = $pool group = $pool listen.owner = $pool listen.group = apache listen.mode = 0666 pm = dynamic pm.max_children = 35 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 25 slowlog = /var/log/php-fpm/$pool-slow.log php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log php_admin_flag[log_errors] = on php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session/$pool
[example.com]

listen = /dev/shm/$pool-php5-fpm.sock
user = $pool
group = $pool
listen.owner = $pool
listen.group = apache
listen.mode = 0666

pm = dynamic
pm.max_children = 35
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 25
slowlog = /var/log/php-fpm/$pool-slow.log
php_admin_value[error_log] = /var/log/php-fpm/$pool-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session/$pool