Last active
December 19, 2015 17:39
-
-
Save ysaotome/5993248 to your computer and use it in GitHub Desktop.
2台構成(Web/APPサーバ1台、DBサーバ1台)のWordpressをセットアップする時のチートシート
Japan TechFesta 2013 E30: 「ニフティクラウドを使ったインフラオートメーションハンズオン」http://www.techfesta.jp/p/program-2.html#E30の Chef vs 人力対決用
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
#Wordpress構築チートシート | |
#元ネタ:https://gist.github.com/ysaotome/2235302 | |
#対決相手:http://tily.github.io/jtf2013/ | |
############################################### | |
# 環境変数を定義 WEB/APPサーバおよびDBサーバの双方で実行 | |
############################################### | |
## MySQL管理ユーザのパスワード | |
export MYSQL_ROOT_PASS='mysql##123' | |
## Wordpressデータベース名 | |
export WP_MYSQL_DB_NAME='wordpress' | |
## WordpressDB管理ユーザ名 | |
export WP_MYSQL_ADMIN_NAME='wpsql' | |
## WordpressDB管理ユーザのパスワード | |
export WP_MYSQL_ADMIN_PASS='wpsql##123' | |
## WordpressBLOGタイトル | |
export WP_BLOG_TITLE='にふくら で わーどぷれす' | |
## WordpressBLOG管理ユーザ名 | |
export WP_BLOG_ADMIN_NAME='wpadmin' | |
## WordpressBLOG管理ユーザのパスワード | |
export WP_BLOG_ADMIN_PASSWORD='wpadmin##123' | |
## WordpressBLOG管理ユーザのメールアドレス | |
export WP_BLOG_ADMIN_MAIL='[email protected]' | |
## OSのアーキテクチャ | |
export HOST_ARC=$(/bin/uname -m) | |
## ホスト名をVMware Toolsで取得(コンパネで設定した名前が取得できる) | |
export HOST_NAME=$(/usr/sbin/vmtoolsd --cmd 'info-get guestinfo.hostname') | |
## サーバのグローバルIPアドレス取得 | |
export HOST_IPADDR_GRO=$(ip addr show eth0 2>/dev/null | grep 'inet ' | sed -e 's/.*inet \([^ ]*\)\/.*/\1/') | |
## サーバのプライベートIPアドレス取得 | |
export HOST_IPADDR_PRI=$(ip addr show eth0 2>/dev/null | grep 'inet ' | sed -e 's/.*inet \([^ ]*\)\/.*/\1/') | |
############################################### | |
# Webサーバをセットアップ | |
############################################### | |
## Apache,PHP5.3.x,postfixをインストール | |
/usr/bin/yum -y install httpd.${HOST_ARC} mysql.${HOST_ARC} php.${HOST_ARC} php-mbstring.${HOST_ARC} php-mysql.${HOST_ARC} postfix.${HOST_ARC} | |
## Apacheの設定 | |
/bin/rm -rf /etc/httpd/conf.d/welcome.conf | |
/bin/rm -rf /var/www/error/noindex.html | |
/bin/sed -i.org -e 's/Options Indexes FollowSymLinks/Options FollowSymLinks/' /etc/httpd/conf/httpd.conf | |
/bin/sed -i 's/ServerTokens OS/ServerTokens ProductOnly/' /etc/httpd/conf/httpd.conf | |
/bin/sed -i 's/ServerSignature On/ServerSignature Off/' /etc/httpd/conf/httpd.conf | |
/etc/init.d/httpd start | |
/sbin/chkconfig httpd on | |
## PHPの設定 | |
/bin/sed -i.org -e "s/;date.timezone =/date.timezone = Asia\/Tokyo/g" /etc/php.ini | |
## postfixの設定 | |
/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix | |
/bin/cp -p /etc/postfix/main.cf /etc/postfix/main.cf.org | |
/bin/cat << _PF_CONFIG_ >> /etc/postfix/main.cf | |
mynetworks = 127.0.0.1 | |
inet_interfaces = localhost | |
alias_maps = hash:/etc/aliases | |
mynetworks_style = host | |
_PF_CONFIG_ | |
/bin/echo 'root:'${WP_BLOG_ADMIN_MAIL} >> /etc/aliases | |
/usr/bin/newaliases | |
/etc/init.d/postfix start | |
/sbin/chkconfig --add postfix | |
/sbin/chkconfig postfix on | |
### DBサーバのセットアップへ移動 | |
### DBサーバとの接続を確認 | |
mysql -u ${WP_MYSQL_ADMIN_NAME} -p${WP_MYSQL_ADMIN_PASS} -h DBサーバのプライベートIPアドレス | |
## Wordpressのパッケージ取得と展開 | |
/usr/bin/wget -P /var/www/html/ 'http://ja.wordpress.org/latest-ja.tar.gz' | |
/bin/tar zxf /var/www/html/latest-ja.tar.gz -C /var/www/html/ | |
/bin/rm -f /var/www/html/latest-ja.tar.gz | |
/bin/chown -R apache:apache /var/www/html/wordpress/ | |
### wp-config.phpファイルの作成(3.3時点) | |
/bin/cat << _WP_CONFIG_1_ >> /var/www/html/wordpress/wp-config.php | |
<?php | |
define('DB_NAME', '${WP_MYSQL_DB_NAME}'); | |
define('DB_USER', '${WP_MYSQL_ADMIN_NAME}'); | |
define('DB_PASSWORD', '${WP_MYSQL_ADMIN_PASS}'); | |
define('DB_HOST', 'localhost'); | |
define('DB_CHARSET', 'utf8'); | |
define('DB_COLLATE', 'utf8_general_ci'); | |
_WP_CONFIG_1_ | |
/usr/bin/wget -O wp_salt.txt 'https://api.wordpress.org/secret-key/1.1/salt/' | |
/bin/cat wp_salt.txt >> /var/www/html/wordpress/wp-config.php | |
/bin/rm -f wp_salt.txt | |
/bin/cat << _WP_CONFIG_2_ >> /var/www/html/wordpress/wp-config.php | |
\$table_prefix = 'wp_'; | |
define('WPLANG', 'ja'); | |
define('WP_DEBUG', false); | |
if ( !defined('ABSPATH') ) | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
require_once(ABSPATH . 'wp-settings.php'); | |
_WP_CONFIG_2_ | |
/bin/chown apache:apache /var/www/html/wordpress/wp-config.php | |
## DBサーバへの接続部分を編集 | |
vi /var/www/html/wordpress/wp-config.php | |
### wordpressの初期設定 | |
/usr/bin/wget -O /tmp/wp_install_result.txt --post-data 'weblog_title='${WP_BLOG_TITLE}'&user_name='${WP_BLOG_ADMIN_NAME}'&admin_password='${WP_BLOG_ADMIN_PASSWORD}'&admin_password2='${WP_BLOG_ADMIN_PASSWORD}'&admin_email='${WP_BLOG_ADMIN_MAIL} 'http://'${HOST_IPADDR_GRO}'/wordpress/wp-admin/install.php?step=2' | |
############################################### | |
# DBサーバをセットアップ | |
############################################### | |
## MySQL,postfixをインストール | |
/usr/bin/yum -y install mysql.${HOST_ARC} mysql-server.${HOST_ARC} | |
## MySQLの設定 | |
/etc/init.d/mysqld start | |
/sbin/chkconfig mysqld on | |
/usr/bin/mysqladmin -u root password ${MYSQL_ROOT_PASS} | |
/usr/bin/mysql -u root -p${MYSQL_ROOT_PASS} -e "DROP DATABASE test; DELETE FROM mysql.user WHERE user=''; DELETE FROM mysql.user WHERE host='"${HOST_NAME}"';" | |
## WordpressのDB作成と権限設定 | |
/usr/bin/mysql -u root -p${MYSQL_ROOT_PASS} -e "CREATE DATABASE "${WP_MYSQL_DB_NAME}" DEFAULT CHARACTER SET utf8;" | |
/usr/bin/mysql -u root -p${MYSQL_ROOT_PASS} -e "GRANT ALL PRIVILEGES ON "${WP_MYSQL_DB_NAME}".* TO '"${WP_MYSQL_ADMIN_NAME}"'@'localhost' IDENTIFIED BY '"${WP_MYSQL_ADMIN_PASS}"';" | |
/usr/bin/mysql -u root -p${MYSQL_ROOT_PASS} -e "GRANT ALL PRIVILEGES ON "${WP_MYSQL_DB_NAME}".* TO '"${WP_MYSQL_ADMIN_NAME}"'@'Webサーバのプライベート側IPアドレス' IDENTIFIED BY '"${WP_MYSQL_ADMIN_PASS}"';" | |
/usr/bin/mysql -u root -p${MYSQL_ROOT_PASS} -e "FLUSH PRIVILEGES;" | |
## DBサーバへの接続を確認 | |
mysql -u root -p${MYSQL_ROOT_PASS} | |
> show databases; | |
> select Host, User, Password from mysql.user; | |
## Webサーバのセットアップに戻る | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment