Linux/AWS/Lambda/プログラミング のエラーと対応集

# <i class="fa fa-map-marker"></i> 目的

サーバ構築・プログラミング関連で、エラーがおきて困ったときの情報を記載します。
主に自分でググって自分でたどり着く為に記載しています。
内容は随時追記していきます。

# <i class="fa fa-exclamation-triangle"></i> [Linux/rails] ERROR:  Error installing rails: activesupport requires Ruby version >= 2.2.2.
gem install rails したらエラー。

```bash:console
[USER ~]$ gem install rails io-console --no-rdoc --no-ri
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.9.0.gem (100%)
Successfully installed minitest-5.9.0
Fetching: concurrent-ruby-1.0.2.gem (100%)
Successfully installed concurrent-ruby-1.0.2
Fetching: activesupport-5.0.0.1.gem (100%)
ERROR:  Error installing rails:
        activesupport requires Ruby version >= 2.2.2.
Fetching: io-console-0.4.6.gem (100%)
Building native extensions.  This could take a while...
Successfully installed io-console-0.4.6
1 gem installed
[USER ~]$ rails -v
-bash: rails: command not found
```

バージョン指定してインストールしたらいけました。

```bash:console
[USER ~]$ sudo gem install rails -v 4.2.4 --no-rdoc --no-ri
Fetching: activesupport-4.2.4.gem (100%)
Successfully installed activesupport-4.2.4
Fetching: rack-1.6.4.gem (100%)
Successfully installed rack-1.6.4
Fetching: rack-test-0.6.3.gem (100%)
Successfully installed rack-test-0.6.3
Fetching: mini_portile2-2.1.0.gem (100%)
Successfully installed mini_portile2-2.1.0
Fetching: pkg-config-1.1.7.gem (100%)
Successfully installed pkg-config-1.1.7
Fetching: nokogiri-1.6.8.gem (100%)
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.8
Fetching: loofah-2.0.3.gem (100%)
Successfully installed loofah-2.0.3
Fetching: rails-html-sanitizer-1.0.3.gem (100%)
Successfully installed rails-html-sanitizer-1.0.3
Fetching: rails-deprecated_sanitizer-1.0.3.gem (100%)
Successfully installed rails-deprecated_sanitizer-1.0.3
Fetching: rails-dom-testing-1.0.7.gem (100%)
Successfully installed rails-dom-testing-1.0.7
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: actionview-4.2.4.gem (100%)
Successfully installed actionview-4.2.4
Fetching: actionpack-4.2.4.gem (100%)
Successfully installed actionpack-4.2.4
Fetching: activemodel-4.2.4.gem (100%)
Successfully installed activemodel-4.2.4
Fetching: arel-6.0.3.gem (100%)
Successfully installed arel-6.0.3
Fetching: activerecord-4.2.4.gem (100%)
Successfully installed activerecord-4.2.4
Fetching: globalid-0.3.7.gem (100%)
Successfully installed globalid-0.3.7
Fetching: activejob-4.2.4.gem (100%)
Successfully installed activejob-4.2.4
Fetching: mime-types-data-3.2016.0521.gem (100%)
Successfully installed mime-types-data-3.2016.0521
Fetching: mime-types-3.1.gem (100%)
Successfully installed mime-types-3.1
Fetching: mail-2.6.4.gem (100%)
Successfully installed mail-2.6.4
Fetching: actionmailer-4.2.4.gem (100%)
Successfully installed actionmailer-4.2.4
Fetching: rake-11.2.2.gem (100%)
Successfully installed rake-11.2.2
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: railties-4.2.4.gem (100%)
Successfully installed railties-4.2.4
Fetching: bundler-1.12.5.gem (100%)
Successfully installed bundler-1.12.5
Fetching: sprockets-3.7.0.gem (100%)
Successfully installed sprockets-3.7.0
Fetching: sprockets-rails-3.1.1.gem (100%)
Successfully installed sprockets-rails-3.1.1
Fetching: rails-4.2.4.gem (100%)
Successfully installed rails-4.2.4
30 gems installed
[USER ~]$ rails -v
Rails 4.2.4
```
- 参考
    - CocoaPodsのインストールについてのメモ - Qiita
        - http://qiita.com/shinog/items/d2de491276d86a08aedf
    - bundle install しようとしたら ruby のバージョン違くてコケた話 - Qiita
        - http://qiita.com/white_aspara25/items/d5e19b82be17048d9215
    - CentOSにRailsをインストールしてみる - yk5656 diary
        - http://d.hatena.ne.jp/yk5656/20131222/1387696718

# <i class="fa fa-exclamation-triangle"></i> [Linux/rake] LoadError: cannot load such file -- nokogiri/nokogiri
rake db:createしたいのにエラー。

```bash:console
[USER APPLICATION]$ rake db:create
rake aborted!
LoadError: cannot load such file -- nokogiri/nokogiri
/usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `require'
/usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `rescue in <top (required)>'
/usr/local/share/ruby/gems/2.0/gems/nokogiri-1.6.8/lib/nokogiri.rb:28:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/loofah-2.0.3/lib/loofah.rb:3:in `require'
/usr/local/share/ruby/gems/2.0/gems/loofah-2.0.3/lib/loofah.rb:3:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `require'
/usr/local/share/ruby/gems/2.0/gems/rails-html-sanitizer-1.0.3/lib/rails-html-sanitizer.rb:2:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/sanitize_helper.rb:3:in `require'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/sanitize_helper.rb:3:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/text_helper.rb:32:in `<module:TextHelper>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/text_helper.rb:29:in `<module:Helpers>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/text_helper.rb:6:in `<module:ActionView>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/text_helper.rb:4:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_tag_helper.rb:18:in `<module:FormTagHelper>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_tag_helper.rb:14:in `<module:Helpers>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_tag_helper.rb:8:in `<module:ActionView>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_tag_helper.rb:6:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_helper.rb:4:in `require'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers/form_helper.rb:4:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:50:in `<module:Helpers>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:4:in `<module:ActionView>'
/usr/local/share/ruby/gems/2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:3:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:7:in `<module:Context>'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:6:in `<module:Rails>'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:5:in `<module:Sprockets>'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/rails/context.rb:4:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:7:in `require'
/usr/local/share/ruby/gems/2.0/gems/sprockets-rails-3.1.1/lib/sprockets/railtie.rb:7:in `<top (required)>'
/home/USER/APPLICATION/config/application.rb:11:in `require'
/home/USER/APPLICATION/config/application.rb:11:in `<top (required)>'
/home/USER/APPLICATION/Rakefile:4:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)

[USER ~]$ gem 'nokogiri'
ERROR:  While executing gem ... (Gem::CommandLineError)
    Unknown command nokogiri
```

nokogiri をインストールしたら直りました。

```bash:console
[USER ~]$ gem install nokogiri
Fetching: nokogiri-1.6.8.gem (100%)
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.6.8
Parsing documentation for nokogiri-1.6.8
Installing ri documentation for nokogiri-1.6.8
Done installing documentation for nokogiri after 3 seconds
1 gem installed
```
- 参考
    - Support Ruby 2.2 on Windows · Issue #1256 · sparklemotion/nokogiri · GitHub
        - https://github.com/sparklemotion/nokogiri/issues/1256


# <i class="fa fa-exclamation-triangle"></i> [Linux/rake] Specified 'mysql2' for database adapter, but the gem is not loaded.
rake db:create したいのにエラー。

```bash:console
[USER MYAPPLICATION]$ rake db:create
Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/share/ruby/2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/lib/mysql/mysql.sock", "database"=>"MYAPPLICATION_development"}
Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/share/ruby/2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/lib/mysql/mysql.sock", "database"=>"MYAPPLICATION_test"}
rake aborted!
Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:109:in `create_current'
/usr/local/share/ruby/gems/2.0/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
```

Gemfile 修正、mysql 0.3.20 指定しましたが、

```bash:Gemfile
# Use mysql as the database for Active Record
# gem 'mysql2'
gem 'mysql2', '~> 0.3.20'
```

別のエラーが起きたので Gemfile は戻しました。

```bash:console
[USER MYAPPLICATION]$ rake db:create
rake aborted!
LoadError: cannot load such file -- mysql2/mysql2
/usr/local/share/ruby/gems/2.0/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `require'
/usr/local/share/ruby/gems/2.0/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
/usr/local/share/ruby/gems/2.0/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
/home/USER/MYAPPLICATION/config/application.rb:16:in `<top (required)>'
/home/USER/MYAPPLICATION/Rakefile:4:in `<top (required)>'
/usr/local/share/ruby/gems/2.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
```

sudo ありで gem install mysql2 すると不具合が起きるそうなので、一度 mysql2 アンインストール、sudo なしで再度インストールしました。

```bash:console
[USER MYAPPLICATION]$ sudo gem uninstall mysql2 

Select gem to uninstall:
 1. mysql2-0.4.4
 2. mysql2-0.3.20
 3. All versions
> 3
Successfully uninstalled mysql2-0.4.4
Successfully uninstalled mysql2-0.3.20
[USER MYAPPLICATION]$ gem install mysql2 
Fetching: mysql2-0.4.4.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.4.4
Parsing documentation for mysql2-0.4.4
Installing ri documentation for mysql2-0.4.4
Done installing documentation for mysql2 after 0 seconds
1 gem installed
[USER MYAPPLICATION]$ gem install mysql2 -v 0.3.20
Fetching: mysql2-0.3.20.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.20
Parsing documentation for mysql2-0.3.20
Installing ri documentation for mysql2-0.3.20
Done installing documentation for mysql2 after 0 seconds
1 gem installed
```

いけました。

```bash:console
[USER MYAPPLICATION]$ rake db:create
[USER MYAPPLICATION]$ rake db:migrate
[USER MYAPPLICATION]$ rails server -b 0.0.0.0
Warning: You're using Rubygems 2.0.14.1 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
```

- 参考
    - Rails4.2でmysql2を認識しない mysql2 is not loaded? - Qiita
        - http://qiita.com/oshin/items/f5ff336f63366c364909
    - Could not load such file mysql2/mysql2 - Redmine
        - http://www.redmine.org/boards/1/topics/42235
    - Rails mysql2でrake db:createがエラー問題 - Qiita
        - http://qiita.com/shizuma/items/0f9660d5d46a0012eb9e
    - LoadError: cannot load such file -- mysql2/mysql2 - Google グループ
        - https://groups.google.com/forum/#!topic/tracksapp/rusKNEtSS3o
    - mysql2 0.4.0ルビー宝石はエラーを必要とする - スタックオーバーフローを
        - http://stackoverflow.com/questions/32534879/mysql2-0-4-0-ruby-gem-require-error


# <i class="fa fa-exclamation-triangle"></i> [Linux/mount] mount: wrong fs type, bad option, bad superblock
xfs で mount しようとしたらエラー

```bash:console
[USER ~]$ sudo mount -t xfs /dev/xvdk /mnt/ebs/2
mount: wrong fs type, bad option, bad superblock on /dev/xvdk,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
```

mkfs でファイルシステム変更したら解消

```bash:console
[USER ~]$ sudo mkfs -t xfs /dev/sdk
meta-data=/dev/sdk               isize=256    agcount=4, agsize=983040 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=3932160, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[USER ~]$ sudo mount -t xfs /dev/sdk /mnt/ebs/2
```

- 参考
    - 俺の覚書 Linuxでmkfsコマンドを用いてファイルシステムを変更する
        - http://192168111.blog71.fc2.com/blog-entry-83.html

# <i class="fa fa-exclamation-triangle"></i> [Linux/fio] fio: posix_fallocate fails: No space left on device
fio で IOPS 図ろうとしたらエラー


```bash:console
[USER ~]$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/xvda1     ext4      7.8G  2.0G  5.8G  26% /
devtmpfs       devtmpfs  488M   88K  488M   1% /dev
tmpfs          tmpfs     498M     0  498M   0% /dev/shm
/dev/xvdf      xfs       4.0G   33M  4.0G   1% /mnt/ebs/0
/dev/md0       xfs        16G   33M   16G   1% /mnt/ebs/1
/dev/xvdk      xfs        15G   33M   15G   1% /mnt/ebs/2
[USER ~]$ cd /mnt/ebs/2
[USER 2]$ sudo fio -name=r -direct=1 -rw=read -bs=4k -size=10G -numjobs=3 -runtime=3 -gro
up_reporting
r: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1
...
r: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1
fio-2.1.5
Starting 3 processes
r: Laying out IO file(s) (1 file(s) / 10240MB)
r: Laying out IO file(s) (1 file(s) / 10240MB)
fio: posix_fallocate fails: No space left on device
^C
fio: terminating on signal 2
r: Laying out IO file(s) (1 file(s) / 10240MB)
fio: posix_fallocate fails: No space left on device


Run status group 0 (all jobs):
```

サイズ(-size) を見直して再実行。

```bash:console
[USER 2]$ sudo fio -name=r -direct=1 -rw=read -bs=4k -size=1000M -numjobs=3 -runtime=3 -g
roup_reporting
r: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1
...
r: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1
fio-2.1.5
Starting 3 processes
r: Laying out IO file(s) (1 file(s) / 1000MB)
r: Laying out IO file(s) (1 file(s) / 1000MB)
r: Laying out IO file(s) (1 file(s) / 1000MB)
Jobs: 3 (f=3): [RRR] [100.0% done] [2044KB/0KB/0KB /s] [511/0/0 iops] [eta 00m:00s]
r: (groupid=0, jobs=3): err= 0: pid=3358: Fri Aug 26 12:38:12 2016
  read : io=7128.0KB, bw=2372.5KB/s, iops=593, runt=  3005msec
    clat (usec): min=218, max=9054, avg=5052.51, stdev=2005.53
     lat (usec): min=218, max=9054, avg=5052.73, stdev=2005.56
    clat percentiles (usec):
     |  1.00th=[  247],  5.00th=[  278], 10.00th=[  306], 20.00th=[ 5792],
     | 30.00th=[ 5856], 40.00th=[ 5856], 50.00th=[ 5856], 60.00th=[ 5856],
     | 70.00th=[ 5920], 80.00th=[ 5920], 90.00th=[ 5920], 95.00th=[ 5920],
     | 99.00th=[ 7136], 99.50th=[ 7904], 99.90th=[ 8768], 99.95th=[ 9024],
     | 99.99th=[ 9024]
    bw (KB  /s): min=  678, max= 1388, per=34.30%, avg=813.60, stdev=276.08
    lat (usec) : 250=1.23%, 500=13.02%, 750=0.22%, 1000=0.17%
    lat (msec) : 2=0.22%, 4=0.67%, 10=84.46%
  cpu          : usr=0.00%, sys=0.27%, ctx=1786, majf=0, minf=22
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=1782/w=0/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=7128KB, aggrb=2372KB/s, minb=2372KB/s, maxb=2372KB/s, mint=3005msec, maxt=3005msec

Disk stats (read/write):
  xvdk: ios=1733/0, merge=0/0, ticks=8704/0, in_queue=8720, util=96.68%
```

# <i class="fa fa-exclamation-triangle"></i> [Linux/nginx] （111） Connection refused
nginx の HTTP サーバにて、IP だと繋がるけれど DNS だと繋がらない。DNS はちゃんと設定済み。

```Text:client/ブラウザ
Connection Failed 
The system returned: 
(111) Connection refused
The remote host or network may be down. Please try the request again. 
```

クライアント側(Windows)で DNS キャッシュクリアしても変化なし。

```Text:client/console
C:\>ipconfig /flushdns

Windows IP 構成

DNS リゾルバー キャッシュは正常にフラッシュされました。
```

nginx のサービス確認。

```bash:server/console
[USER ~]$ service nginx status 
nginx dead but pid file exists
```

だめっぽいのでサービス再起動したら解決。
※サーバログは確認しませんでした。

```bash:server/console
[USER ~]$ sudo service nginx stop
[USER ~]$ sudo service nginx start
Starting nginx:                                            [  OK  ]
```


# <i class="fa fa-exclamation-triangle"></i> [AWS/R53] Alias Target contains an invalid value.
Route 53 の ヘルスチェック時のフェイルオーバー先に S3 の静的コンテンツを設定するため、
S3 に TESTBUCKET を作成し適当なHTMLを入れ、Create Record Set Alias Target: に設定しようとしたところ対象として S3 のエンドポイントが表示されない。下記の表示となっている。

> \- S3 website endpoint - 
>  No Targets Available

また、TESTBUCKET.s3-website-ap-northeast-1.amazonaws.com を直接記入してもエラー表示で RecordSet 作成できない。

> The record set could not be saved because:
> - Alias Target contains an invalid value.

下記のとおり、S3 設定変更

- バケット名を TESTBUCKET から DOMAIN.NAME(ドメイン名と同じ名前) で作成しなおし。
- ウェブサイトのホスティングを有効にする
    - インデックスドキュメント：
        - index.html
    - エラードキュメント：
        - error.html

そのあと再度 Route53 の設定を実施、S3 エンドポイントが表示された。


- 参考
    - AWS Developer Forums: Alias for S3 endpoints not working. ...
        - https://forums.aws.amazon.com/thread.jspa?messageID=411546

# <i class="fa fa-exclamation-triangle"></i> [AWS/R53] Failure: The health checker could not establish a connection within the timeout limit
クライアントからは IP:PORT で接続できるのに、Route 53 → EC2インスタンスへの
 「Specify endpoint by IP address」のヘルスチェックがずっと Unhealty、ログは以下。

> |Health checker region|Health checker IP|Last checked|Status|
> |:--|:--|:--|:--|
> |Asia Pacific (Tokyo)|54.248.220.14|Aug 29, 2016 11:21:42 AM UTC|Failure: The health checker could not establish a connection within the timeout limit.|
> |Asia Pacific (Sydney)|54.252.254.238|Aug 29, 2016 11:21:46 AM UTC|Failure: The health checker could not establish a connection|
> |以下略|-|-|-|

※日時はUTC表記なので注意

セキュリティグループより、一時的に任意の場所(0.0.0.0/0)、HTTP(80)を許可してステータスが正常になることを確認

> Success: HTTP Status Code 200, OK

ヘルスチェック元のIPは以下に記載されているので、下記IPを記載したEC2 セキュリティグループを作成し、EC2へのヘルスチェック対象ポート(80) の接続を許可するよう変更。EC2 インスタンスのセキュリティグループに追加してあげる。

https://ip-ranges.amazonaws.com/ip-ranges.json

```json:ip-ranges.json
    {
      "ip_prefix": "54.183.255.128/26",
      "region": "us-west-1",
      "service": "ROUTE53_HEALTHCHECKS"
    },
    {
      "ip_prefix": "54.228.16.0/26",
      "region": "eu-west-1",
      "service": "ROUTE53_HEALTHCHECKS"
    },
以下略
```

- 参考
    - Amazon Web Services ブログ: 【AWS発表】AWSのIPアドレスレンジをJSONで提供
        - http://aws.typepad.com/aws_japan/2014/11/aws-cidr-json.html
    - AWSが利用しているIPアドレスを取り出してみた - Qiita
        - http://qiita.com/SatoHiroyuki/items/5d77f6e7219016a639a6
    - AWSサービスのPublic IPレンジを簡単に取得する ｜ Developers.IO
        - http://dev.classmethod.jp/cloud/aws/get-ec2-public-ip-range-by-powershell/
        - ※ハードコーディングしてはいけない、とのこと。セキュリティグループをしないとだめそうです
    - AWSのIPアドレスレンジを都合よく加工してみる | 株式会社SUPINF
        - https://www.supinf.co.jp/tech/2014/11/26/aws-ip-ranges/

# <i class="fa fa-exclamation-triangle"></i> No suitable driver found for jdbc:sqlserver://
AWS Lambda で SQL Server に JDBC 接続しようとしたらエラー

```
START RequestId: 2eafb5e9-90e0-11e6-be55-75fcab119a17 Version: $LATEST
Input: com.amazonaws.services.lambda.runtime.events.S3Event@149e0f5d
Starting My Function
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://SQLSERVER;databaseName=DATABASENAME
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at saito20161013.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:29)
at saito20161013.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:1)
at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:370)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:972)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:257)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:62)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94)
Caught exception: No suitable driver found for jdbc:sqlserver://SQLSERVER;databaseName=DATABASENAME
END RequestId: 2eafb5e9-90e0-11e6-be55-75fcab119a17
REPORT RequestId: 2eafb5e9-90e0-11e6-be55-75fcab119a17	Duration: 1.17 ms	Billed Duration: 100 ms Memory Size: 512 MB	Max Memory Used: 54 MB	
```

JDBCドライバの参照追加をしていなかった。
[Download Microsoft JDBC Driver 6.0 for SQL Server、Microsoft JDBC Driver 4.2 for SQL Server、Microsoft JDBC Driver 4.1 for SQL Server、および Microsoft JDBC Driver 4.0 for SQL Server from Official Microsoft Download Center](https://www.microsoft.com/ja-jp/download/details.aspx?id=11774)

# Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
EclipseでTomcat立ち上げようとするとエラー。

```
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
	at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:60)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	... 1 more


```
```
Server Tomcat v7.0 Server at localhost failed to start.
```
プロジェクトに TOMCAT/bin/tomcat-juli.jar のExternal JAR を参照追加してあげるとよいとかなんとか。未確認。
[eclipse - java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory - Stack Overflow](http://stackoverflow.com/questions/7955442/java-lang-noclassdeffounderror-org-apache-juli-logging-logfactory)

## がんばった結果
Tomcat v7.0 を削除、v8.0 を追加しなおしたら治りました。
原因不明のまま。

# [Windows 10] Windows Update でエラー「更新サービスに接続できませんでした。後で自動的に再試行されますが、今すぐ手動で確認することもできます。この問題が引き続き発生する場合は、インターネットに接続していることを確認してください。」
## 対応方法

管理者でコマンドプロンプト起動
サービス停止

```
net stop wuauserv
net stop cryptSvc
net stop bits
net stop msiserver
```

BITS サービスと Windows Update サービスを、既定のセキュリティ記述子にリセット

```
sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
```

WindowsUpdateファイルを削除

```
ren %systemroot%\SoftwareDistribution SoftwareDistribution.old
del %ALLUSERSPROFILE%\Microsoft\Network\Downloader\qmgr.db
del %ALLUSERSPROFILE%\Microsoft\Network\Downloader\qmgr.jfm
del %systemroot%\SoftwareDistribution.old\Doenload /s/q > null
rmdir %systemroot%\SoftwareDistribution.old\Doenload /s/q
```

Winsock、プロキシ設定をリセット

```
netsh winsock reset
netsh winhttp reset proxy
```

展開イメージのサービスと管理ツール を実行

```
DISM.EXE /online /cleanup-image /restorehealth
```

システムスキャンを実行

```
SFC /scannow
```

レジストリ設定

```
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsSelfHost\Applicability]

"BranchName"="fbl_impressive"

"Ring"="WIF"

"ThresholdRiskLevel"="low"
```

サービスを起動

```
net start bits
net start wuauserv
net start appidsvc
net start cryptsvc
```

更新プログラムのチェックを再実行

```
usoclient startscan
```

治った

## 参考
- [windowsupdateで更新がなされない - マイクロソフト コミュニティ](https://answers.microsoft.com/ja-jp/windows/forum/windows_10-update/windowsupdate%E3%81%A7%E6%9B%B4%E6%96%B0%E3%81%8C/745a1c4c-4c92-481e-b5ac-39ae55cd7139)
- [Windows 10 - Windows Update に失敗する場合の対処法 - マイクロソフト コミュニティ](https://answers.microsoft.com/ja-jp/windows/forum/windows_10-update/windows-10-windows-update/a8a3a4cb-9d67-406e-8ae6-d25451c237d7)
- [Windows 10 Service Registration is Missing or Corrupt - Microsoft Community](https://answers.microsoft.com/en-us/insider/forum/insider_wintp-insider_update/windows-10-service-registration-is-missing-or/a2bfb3c3-665f-4f22-92d9-cf82f0a950be)
- [Windows Updateに失敗するなら、よりアグレッシブな方法で | Solomonレビュー[redémarrage]](https://solomon-review.net/windows10-update-fail-repair/)
- [DismのRestoreHealthがエラー:0x800f081fで失敗する問題 (RS2 / 解消) - ぼくんちのTV 別館](https://freesoft.tvbok.com/win10/rs2/dism-0x800f081f.html)
- [Microsoft Update カタログ](http://www.catalog.update.microsoft.com/Search.aspx?q=KB4016871)