# getenforce Enforcing
# getenforce Permissive
# setenforce 0
# vi /etc/sysconfig/selinux -) SELINUX=enforcing +) SELINUX=disabled
# vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# /etc/rc.d/init.d/iptables restart
download - Pre-Built Packages と辿る。 http://nginx.org/en/linux_packages.html#stable
RHEL や CentOS のリンクがあるので、CentOS6のURLを確認する。 http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# less /etc/yum.repos.d/nginx.repo
# nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1
# yum -y install nginx
# nginx -v nginx version: nginx/1.6.2
# /etc/init.d/nginx start
# chkconfig nginx on
# yum -y --enablerepo=remi install php php-mbstring php-mysql php-pear php-devel # vi /etc/php.ini /etc/php.ini.org 869c869 < date.timezone = "Asia/Tokyo" --- > ;date.timezone = 1350c1350 < session.save_path = "/var/lib/php/session/" --- > ;session.save_path = "/tmp" # ll /var/lib/php/ 合計 4 drwxrwx---. 2 root apache 4096 10月 16 17:24 2014 session # chown -R root.nginx /var/lib/php/session # ll /var/lib/php/ 合計 4 drwxrwx---. 2 root nginx 4096 10月 16 17:24 2014 session
# yum -y --enablerepo=remi install gcc # pecl install apc # echo "extension=apc.so" | sudo tee /etc/php.d/apc.ini
# yum -y --enablerepo=remi install php-fpm
# vi /etc/php-fpm.d/www.conf
39c39
< user = nginx
---
> user = apache
41c41
< group = nginx
---
> group = apache
nginx への設定追加
# vi /etc/nginx/conf.d/default.conf
9,10c9,10
<         root   /var/www/html;
<         index  index.php;
---
>         root   /usr/share/nginx/html;
>         index  index.html index.htm;
30,36c30,36
<     location ~ \.php$ {
<         root           /var/www/html;
<         fastcgi_pass   127.0.0.1:9000;
<         fastcgi_index  index.php;
<         fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
<         include        fastcgi_params;
<     }
---
>     #location ~ \.php$ {
>     #    root           html;
>     #    fastcgi_pass   127.0.0.1:9000;
>     #    fastcgi_index  index.php;
>     #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
>     #    include        fastcgi_params;
>     #}
	
PHP-FPM 起動	
# /etc/init.d/php-fpm start
自動起動設定
# chkconfig php-fpm on
nginx 再起動(設定反映)
# /etc/init.d/nginx restart
	●参考サイト
	http://blog.livedoor.jp/sasata299/archives/51322051.html
	> TokyoCabinet が key-valueストアの機能を持っていて、データを保存したり、
	> 取り出したり出来ます。TokyoTyrant は TokyoCabinet をネットワーク越しに
	> 操作できるようにしたラッパーです。キャビネット(内閣)を傀儡にするタイ
	> ラント(僭主)ということでこのような名前が付けられたそうです
	
	使ってみようTokyo Cabinet
	http://fallabs.com/mikio/tech/promenade.cgi?id=72
	
	公式
	http://fallabs.com/
	
	tokyo_tyrant
	http://www.php.net/manual/ja/book.tokyo-tyrant.php
	
	TokyoTyrant の定数
	http://www.php.net/manual/ja/class.tokyotyrant.php#tokyotyrant.constants.types
	
	
	●下準備
	# yum -y install zlib-devel bzip2-devel
	
	
	● TokyoCabinet インストール
	# wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.46.tar.gz
	# tar xvzf tokyocabinet-1.4.46.tar.gz
	# cd tokyocabinet-1.4.46
	# ./configure
	# make
	# make install
	
	● TokyoTyrant インストール
	# wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
	# tar xvzf tokyotyrant-1.1.41.tar.gz
	# cd tokyotyrant-1.1.41
	# ./configure
	# make
	# make install
	
	● PECL::tokyo_tyrantをインストール
	# pecl install tokyo_tyrant-beta
	# echo "extension=tokyo_tyrant.so" | sudo tee /etc/php.d/tokyo_tyrant.ini
	# /etc/rc.d/init.d/php-fpm restart
	
	以下、動作確認用コードサンプル
	<?php
	$tt = new TokyoTyrant('localhost', 1978);
	$tt->put('some_key', 'some_value');
	echo $tt->get('some_key');
	
	● chkconfig 登録
		■ 自動起動ファイルを修正する
		# vi /usr/local/sbin/ttservctl
		
		3行目付近、以下の6行を追加
		# chkconfig: 345 99 01
		# description: Startup script for the server of Tokyo Tyrant
		# processname: tokyotyrant
		
		# Source function library.
		. /etc/init.d/functions
		
		17行目付近、以下の行変更
		#cmd="ttserver"
		cmd="/usr/local/bin/ttserver"
		
		152行目付近、以下の3行追加
		status)
		  status -p "$pidfile" $prog
		  ;;
		
		163行目付近、以下の行変更
		#  printf 'Usage: %s {start|stop|restart|hup}\n' "$prog"
		  printf 'Usage: %s {start|stop|status|restart|hup}\n' "$prog"
		
		■ シンボリックリンク作成
		# ln -s /usr/local/sbin/ttservctl /etc/rc.d/init.d/
		
		■ 確認
		起動
		# service ttservctl start
		
		終了
		# service ttservctl stop
		
		状態確認
		# service ttservctl status
		
	● 不正終了など、サービス再起動できないときの対処(pidファイルの削除)
	# rm /var/ttserver/pid
	
	Tips)
	/usr/local/sbin/ttservctl stop
	rm /var/ttserver/pid
	/usr/local/sbin/ttservctl start
	/etc/rc.d/init.d/php-fpm restart
	/etc/init.d/nginx restart
	
	
発行される証明書と対になるファイル。
e.g. パスフレーズ無し、鍵長2,048bitの秘密鍵「server.key」を作成する
[root@adm01 ~]# openssl genrsa -out server.key 2048 Generating RSA private key, 2048 bit long modulus ........................+++ ...+++ e is 65537 (0x10001) [root@adm01 ~]# ll -rw-r--r--. 1 root root 1675 11月 4 18:05 2014 server.key [root@adm01 ~]# cat server.key -----BEGIN RSA PRIVATE KEY----- ~省略~ -----END RSA PRIVATE KEY-----
証明書の申請時に提出するファイル。
e.g. 作成した秘密鍵「server.key」で、CSR「server.csr」を作成する
[root@adm01 ~]# openssl req -new -key server.key -out aserver.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:JP State or Province Name (full name) []:Osaka Locality Name (eg, city) [Default City]:Osaka-shi,Cyuoh-ku Organization Name (eg, company) [Default Company Ltd]:Clown Inc. Organizational Unit Name (eg, section) []:Clown Section Common Name (eg, your name or your server's hostname) []:clown.com Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: [root@adm01 ~]# ll -rw-r--r--. 1 root root 1029 11月 4 18:08 2014 server.csr -rw-r--r--. 1 root root 1675 11月 4 18:05 2014 server.key [root@adm01 ~]# cat server.csr -----BEGIN CERTIFICATE REQUEST----- ~省略~ -----END CERTIFICATE REQUEST-----
いわゆる、SSL証明書。
e.g. 有効期限10年で、秘密鍵「server.key」とCSR「server.csr」を使用して証明書「server.crt」を作成する
[root@adm01 ~]# openssl x509 -days 3650 -req -signkey server.key -in server.csr -out server.crt Signature ok subject=/C=JP/ST=Osaka/L=Osaka-shi,Cyuoh-ku/O=Clown Inc./OU=Clown Section/CN=clown.com Getting Private key [root@adm01 ~]# ll -rw-r--r--. 1 root root 1257 11月 4 18:09 2014 server.crt -rw-r--r--. 1 root root 1029 11月 4 18:08 2014 server.csr -rw-r--r--. 1 root root 1675 11月 4 18:05 2014 server.key [root@adm01 ~]# cat server.crt -----BEGIN CERTIFICATE----- ~省略~ -----END CERTIFICATE-----
適当な場所にデジタル証明書、秘密鍵を設置
[root@adm01 ~]# mkdir /etc/nginx/conf.d/ssl.crt/ [root@adm01 ~]# mv server.crt /etc/nginx/conf.d/ssl.crt/ [root@adm01 ~]# mkdir /etc/nginx/conf.d/ssl.key/ [root@adm01 ~]# mv server.key /etc/nginx/conf.d/ssl.key/ [root@adm01 ~]# rm -rf server.csr [root@adm01 ~]# chmod 700 /etc/nginx/conf.d/ssl.key [root@adm01 ~]# chmod 400 /etc/nginx/conf.d/ssl.key/server.key
nginx の SSL設定ファイルを設定
# mv /etc/nginx/conf.d/example_ssl.conf /etc/nginx/conf.d/ssl.conf # vi /etc/nginx/conf.d/ssl.conf
5行目付近「sever {」以下のコメントをすべてはずす。 10~11行目付近、鍵のパスを修正
# HTTPS server
#
server {
    listen       443 ssl;
    server_name  localhost;
#    ssl_certificate      /etc/nginx/cert.pem;
#    ssl_certificate_key  /etc/nginx/cert.key;
    ssl_certificate      /etc/nginx/conf.d/ssl.crt/server.crt;
    ssl_certificate_key  /etc/nginx/conf.d/ssl.key/server.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
SSL 有効化(nginx 再起動)
# /etc/init.d/nginx restart