2019年1月3日木曜日

セブ島にあるシェアハウスひなた(ひなたハウス)のレビュー

セブ島の「シェアハウスひなた」は最悪です。
http://hinatashare.com/

夫妻が二人で経営しているシェアハウスです。
端的に言って、私は二度と使うことはありません。
その理由を下に書いていきます。
  • 大通り沿いなので、車の音がうるさい。
  • 大通り沿いなので、部屋の空気が悪い。
  • 近くにライブハウス?があるため、クリスマス、年末、その他のイベント時には重低音のサウンドが流れてきます。
    普通の人は眠れないと思います。
  • 値段が高い。サイトからは読み取りづらいのですが、賃料+光熱費で14,000ペソから16,000ペソほど取られます。
    これなら、別のコンドミニアムで個室をAirbnbで借りても同じ値段ですね。
  • 日中、常に部屋にいる人は追加で1,000ペソを払う必要があります。
  • 洗濯は、一週間に一度しかできません。
    洗濯物は夕方の16時までに取り込まないと駄目です。
    天気や働いている人の生活は、完全に無視ですね。
  • トイレットペーパー、洗剤、石鹸といったものは一切、ついていません。
  • 部屋でのSEXは禁止。

2015年12月23日水曜日

Capistranoの実行環境を作成する3

Front1 serverでの作業
SSLのkeyを作成
sudo openssl req -new -days 365 -x509 -nodes -keyout cert.key -out cert.crt
mv cert.key /etc/nginx
mv cert.crt /etc/nginx
udo vi /etc/nginx/conf.d/target.conf
try_filesの設定が重要になります。
1、$uri
2、$uri.html
3、$uri/index.html
とアクセスして、最後に@appにアクセスします。
4、location @appに遷移
5、proxy_passでupstream backend-unicornに遷移。
6、Rails側でも設定したunicorn.sockにアクセスがいきます。
upstream backend-unicorn {
    server unix:/srv/www/target/shared/tmp/sockets/unicorn.sock;
}
 
server {
    allow all;
    listen 80;
    listen 443 ssl;
    ssl_certificate      /etc/nginx/cert.crt;
    ssl_certificate_key  /etc/nginx/cert.key;
    server_name target.com;
    root /srv/www/target/current/public;
    try_files $uri $uri.html $uri/index.html @app;
    access_log /var/log/nginx/target_access.log;
    error_log /var/log/nginx/target_error.log;

    location @app {
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X_FORWARDED_PROTO $scheme;
        proxy_set_header Host $http_host;
        proxy_pass http://backend-unicorn;
        proxy_redirect off;
    }
    if (-f /srv/www/target/shared/public/system/maintenance.html) {
        return 503;
    }
    error_page 503 @503;
    location @503 {
        if (-f $request_filename) {
            break;
        }
        rewrite ^(.*)$ /system/maintenance.html break;
    }
    gzip_vary on;
    gzip_static on;
}
SELinuxをoff
setenforce 0
Unicornに問い合わせがいかないように設定
config/environmebts/production.rb
config.serve_static_assets = false
js, cssの動的なcompileをしないように設定。 逆に言えば、js,cssが正しく設定されていないと、ファイルが見つからないのでエラーが出ます。
config.assets.compile = false
localのMacサーバーでhostsを設定します。
sudo vi /etc/hosts
192.168.43.62 target.com
このURLからアクセスできます。
https://target.com/

Capistranoの実行環境を作成する2

japan user in Host
ssh-keygen -t rsa
パスワードはpassword
su - japan
git cloneで対象をダウンロード
git clone git@github.com
cd your dir
bundle install --path vendor/bundle
確認
bundle exec cap -T
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
ここにはdevelopment, staging, productionに共通の設定を記述
vi config/deploy.rb
lock '3.2.1'
set :user, 'japan'
set :application, 'target'
set :repo_url, 'git@github.com:target.git'
set :scm, :git
set :deploy_via, :remote_cache
set :keep_releases, 5
set :deploy_to, "/srv/www/#{fetch(:application)}"
shared_path = "#{fetch(:deploy_to)}/shared"
release_path = "#{fetch(:deploy_to)}/current"
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets bundle}
set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid"
set :unicorn_config_path, "#{release_path}/config/unicorn.rb"
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
  task :restart do
    invoke 'unicorn:restart'
  end
end
ここにはproduction用の設定を記述 
vi config/deploy/production.rb
set :rails_env, 'production'
set :branch, 'master'
server '192.168.43.62', user: 'japan', roles: %w{web app db}, :primary => true
set :ssh_options, keys: %w(/home/japan/.ssh/id_rsa), forward_agent: true, auth_methods: %w(publickey)
set :unicorn_rack_env, 'production'
vi config/unicorn.rb
app_path = "/srv/www/target"
 
# Set unicorn options
worker_processes 4
preload_app true
#integration server is slow
timeout = 30
listen "#{app_path}/shared/tmp/sockets/unicorn.sock"
working_directory = "#{app_path}/current"
# Spawn unicorn master worker for user apps (group: apps)
# Should be 'production' by default, otherwise use other env
rails_env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
# Set master PID location
pid "#{app_path}/shared/tmp/pids/unicorn.pid"
preload_app true
before_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
  old_pid = "#{server.config[:pid]}.oldbin"
  puts "old_pid=#{old_pid}"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end
after_fork do |server, worker|
  if defined?(ActiveRecord::Base)
    config = Rails.application.config.database_configuration[Rails.env]
    config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
    config['pool']              = ENV['DB_POOL'] || 5
    ActiveRecord::Base.establish_connection(config)
  end
end
before_exec do |server|
  ENV["BUNDLE_GEMFILE"] = "/srv/www/target/current/Gemfile"
end
bundle exec cap production deploy
nokogiriでエラーが出る時は、これを忘れずに。
bundle config build.nokogiri --use-system-libraries

2015年12月22日火曜日

Capistranoの実行環境を作成する1

前提

  • Mac環境
  • VirtualBoxはinstall済み
  • Vagrantはinstall済み

mkdir cap_test
cd cap_test
vagrant box add "centos_6.6" https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
vagrant init
vi Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.define "host" do |node|
    node.vm.box = "centos_6.6"
    node.vm.hostname = "host"
    node.vm.network :private_network, ip: "192.168.43.61"
  end
  config.vm.define "front1" do |node|
    node.vm.box = "centos_6.6"
    node.vm.hostname = "front1"
    node.vm.network :private_network, ip: "192.168.43.62"
  end
end
vagrant up
vagrant status

Set UP Ansible in Host

vagrant ssh host
#password is vagrant
su -
wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install -y ansible

Setup ssh

ssh-keygen -t rsa
vi ~/.ssh/config
Host front1
  HostName 192.168.43.62
chmod 600 ~/.ssh/config
ssh-copy-id front1
これはHostとFrontの両方
sudo yum -y update

Anslbleを使用

Host
vi hosts
[host]
192.168.43.61
[front1]
192.168.43.62
ansibleの確認
ansible all -i hosts -m ping
machineのスペックの確認
ansible all -i hosts -m setup
パスワード作成: passwordという文字列を暗号化
sa3tHJ3/KuYvI
python -c 'import crypt; print crypt.crypt("password", "salt")'   
create japan group and japan user
---
- hosts: all
  sudo: yes
  tasks:
    - name: create japan group
      group: name=japan state=present
    - name: add a japan user
      user: name=japan append=yes group=japan groups=japan,wheel password=sa0l6dugPm7w2
    - name: create directory
      file: path=/srv/www state=directory owner=japan group=japan mode=0755
    - name: install libselinux-python
      yum: name=libselinux-python state=latest
    - name: install git
      yum: name=git state=latest
    - name: remove ruby packages
      yum: name={{item}} state=absent
      with_items:
       - ruby
       - ruby-augeas
       - ruby-libs
       - libselinux-ruby
    - name: download ruby
      get_url: url="ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.0.tar.gz" dest=/usr/local/src
    - name: tar
      unarchive: src=/usr/local/src/ruby-2.1.0.tar.gz dest=/usr/local/src
    - name: configure
      command: ./configure --prefix=/usr/local/ruby-2.1.0 --disable-install-rdoc --disable-install-capi chdir=/usr/local/src/ruby-2.1.0
    - name: make
      command: make chdir=/usr/local/src/ruby-2.1.0
    - name: make install
      command: make install chdir=/usr/local/src/ruby-2.1.0
    - name: change .bashrc for root
      lineinfile: dest=/root/.bashrc
                  line='PATH=$PATH:$HOME/bin:/usr/local/ruby-2.1.0/bin'
                  backup=yes
                  state=present
    - name: export .bashrc
      lineinfile: dest=/root/.bashrc
                  line='export PATH'
                  state=present
    - name: source .bashrc for root
      shell: source /root/.bashrc
    - name: change .bashrc for japan
      lineinfile: dest=/home/japan/.bashrc
                  line='PATH=$PATH:$HOME/bin:/usr/local/ruby-2.1.0/bin'
                  backup=yes
                  state=present
    - name: export .bashrc
      lineinfile: dest=/home/japan/.bashrc
                  line='export PATH'
                  state=present
    - name: source .bashrc for japan
      shell: source /home/japan/.bashrc
    - name: gem update
      shell: /usr/local/ruby-2.1.0/bin/gem update --system
    - name: gem install bundle
      shell: /usr/local/ruby-2.1.0/bin/gem install bundle
ansible-playbook -v -i hosts playbook_all.yml
vi playbook_host.yml
---
- hosts: front1
  sudo: yes
  tasks:
    - name: install memcached
      yum: name=memcached state=present
    - name: install ImageMagick packages
      yum: name={{item}} state=present
      with_items:
       - ImageMagick
       - ImageMagick-perl
    - name: update mysql rpm
      yum: name="http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm" state=present
    - name: install mysql packages
      yum: name={{item}} state=present
      with_items:
       - mysql
       - mysql-server
       - mysql-devel
    - name: update nginx rpm
      yum: name="http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm" state=present
    - name: install nginx
      yum: name=nginx
    - name: install libxml2 packages
      yum: name={{item}} state=present
      with_items:
       - libxml2
       - libxml2-devel
    - name: install libxslt packages
      yum: name={{item}} state=present
      with_items:
       - libxslt
       - libxslt-devel
    - name: service mysql nginx memcached
      service: name={{item}} state=started enabled=yes
      with_items:
       - mysqld
       - nginx
       - memcached
ansible-playbook -v -i hosts playbook_host.yml

Set UP ssh

vagrant ssh host 
#password is vagrant
su -
visudo
変更
#%wheel  ALL=(ALL)
%wheel  ALL=(ALL)       ALL
su - japan
set id_rsa.pub
vi ~/.ssh/config
Host front1
  HostName 192.168.43.62
chmod 600 ~/.ssh/config
user is japan
ssh-copy-id front1
ログインを確認
ssh front1

2015年10月23日金曜日

phpはThreadセーフみたい

php -v
PHP 5.4.42 (cli) (built: Jul 1 2015 22:46:17) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
php -i | grep -i "thread"
Thread Safety => enabled

今はphpはthreadセーフなのか。。。
てことはApacheのmpmは何でもいいですね。

2015年9月13日日曜日

PHPでApacheを使う時のパラメータチューニングとメモ

ApacheのMPMは、どちらを選択するべきか?
  • mod_phpは非スレッドセーフ
  • prefork MPM
    リクエストごとにプロセスを生成し、処理が終わればそのプロセスが死ぬ。
  • worker MPM
    リクエストごとにスレッドを生成する。
    スレッドセーフでないApacheモジュールがあるとバグる
phpを使う時はperforkを使う必要がある。
Apache2.4からはdefaultのmpmがeventのため、コンパイル時には気をつける必要がある。
./configure \
--prefix=/usr/local/apache2.4.12 \
--enable-so \
--enable-ssl \
--enable-mods-shared=all \
--with-expat=builtin \
--with-included-apr \
--enable-proxy \
--enable-proxy-http \
--enable-proxy-ajp \
--with-mpm=prefork \
--enable-rewrite

httpd.confの中身

    StartServers             5
    MinSpareServers         10
    MaxSpareServers         30
    MaxRequestWorkers       1000
    ServerLimit             1000
    MaxConnectionsPerChild  30000

StartServers:最初に起動する子プロセスの数
MinSpareServers: 待機する子プロセスの最小数
MaxSpareServers: 待機する子プロセスの最大数
MaxRequestWorkers: スタート時に許される子プロセスの最大数
ServerLimit: MaxRequestWorkersに上限値をつける
MaxRequestsPerChild: それぞれの子プロセスが扱うリクエスト数の制限数

Apache2.4からMaxClientsという名前がMaxRequestWorkersに変更になりました。
httpdのMPMを確認
httpd -V

2015年8月31日月曜日

MySQL5.6のsql_mode

MySQL5.6でsql_modeがdefaultで設定された。今まではMySQL5.5を使っていたので、それは困る。ということでsql_modeを無効にする。sqll_modeを設定しているところが/usr/my.cnfにもあって、少しはまったというお話。

コマンドラインからはこんな感じで確認。

show variables LIKE 'sql_mode';

vi /usr/my.cnf


これをコメントアウト
今度は/etc/my.cnfの方に追記
vi /etc/my.cnf
[mysqld]
sql_mode=''
/etc/init.d/mysql restart