Skip to content

Instantly share code, notes, and snippets.

@hilotech
Created July 2, 2015 02:38
Show Gist options
  • Save hilotech/5ede0ddd2ceaad6f8b51 to your computer and use it in GitHub Desktop.
Save hilotech/5ede0ddd2ceaad6f8b51 to your computer and use it in GitHub Desktop.
ConoHa : memcachedインストールスクリプト
#!/bin/bash
set -e
set -u
# must replace with your own configuration
WEB_SERVER_A_IP='your_ip_addr'
WEB_SERVER_B_IP='your_ip_addr'
MEMCACHED_SERVER_IP='your_ip_addr'
IS_MEMCACHED_SERVER='yes'
# Prerequisite
[[ ${IS_MEMCACHED_SERVER-} = 'yes' ]] \
&& yum -y install memcached
yum -y install \
httpd php-pecl-memcached
# setting up PHP memcached
sed -i \
-e 's|^\(session.save\)|;\1|' \
/etc/php.ini
cat <<_EOF_ > /etc/php.d/mymemcached.ini
session.save_handler = memcached
session.save_path = "${MEMCACHED_SERVER_IP-}:11211"
_EOF_
# setting up Apache
sed -i \
-e 's|^\(Listen\)|#\1|' \
/etc/httpd/conf/httpd.conf
echo 'Listen 8080' > /etc/httpd/conf.d/port.conf
/bin/rm /etc/httpd/conf.d/welcome.conf
mv /var/www/html{,.old}
ln -s /mnt/conohaobj/myfuse /var/www/html
# sample script
cat <<'_EOF_' > /var/www/html/test.php
<?php
session_start();
if ( ! isset($_SESSION['counter']) ) {
$_SESSION['counter'] = 0;
}
$_SESSION['counter']++;
print(
'<pre>'
. 'This is your '
. $_SESSION['counter']
. "th visit.\n"
. 'I am running @ '
. $_SERVER['SERVER_ADDR']
);
_EOF_
# nginx
if [[ ${IS_MEMCACHED_SERVER-} = 'yes' ]]; then
yum -y install nginx
mv /etc/nginx/conf.d/default.conf{,.orig}
cat <<_EOF_ > /etc/nginx/conf.d/proxy.conf
upstream app {
server ${WEB_SERVER_A_IP-}:8080;
server ${WEB_SERVER_B_IP-}:8080;
}
server {
listen 80 default_server;
server_name _;
location / {
proxy_pass http://app/;
}
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
_EOF_
chkconfig nginx on
service nginx start
fi
# spawn services
if [[ ${IS_MEMCACHED_SERVER-} = 'yes' ]]; then
chkconfig memcached on
service memcached start
iptables -I INPUT -p tcp --dport 11211 -j ACCEPT
fi
chkconfig httpd on
service httpd start
iptables -I INPUT -p tcp --dport http -j ACCEPT
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
service iptables save
service iptables reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment