-
-
Save keokent/5811088 to your computer and use it in GitHub Desktop.
| MySQLのインストール | |
| $ sudo yum -y install mysql-server | |
| Nginxのインストール | |
| $ ls /etc/yum.repos.d/ | |
| $ cat /etc/yum.repos.d/cobbler-config.repo | |
| % rpm -ql nginx | |
| % sudo /usr/sbin/nginx これで起動 | |
| % sudo service nginx start/stop 起動と停止 | |
| % emacs /etc/init.d/nginx | |
| % sudo chmod a+x /etc/init.d/nginx | |
| % sudo /sbin/chkconfig --add ngin | |
| % sudo /sbin/chkconfig --list | grep nginx | |
| % sudo /sbin/chkconfig --level 35 nginx on | |
| ユーザの追加 | |
| $ sudo groupadd -g 1000 appuser | |
| $ sudo useradd -u 1000 -g appuser appuser | |
| $ cat /etc/passwd | |
| $ visudo | |
| appuser ALL=(ALL) ALLこれでappuserにsudoが使えるようになる | |
| % sudo yum -y install git | |
| rbenvのインストール システムワイドに | |
| % cd /usr/local | |
| [appuser@app001]/usr/local% sudo git clone git://github.com/sstephenson/rbenv.git Ruben | |
| [appuser@app001]/usr/local% sudo chgrp -R appuser rbenv | |
| [appuser@app001]/usr/local% sudo chmod -R g+rwxXs rbenv | |
| [appuser@app001]/usr/local% export RBENV_ROOT=/usr/local/rbenv × | |
| [appuser@app001]/usr/local% export PATH="$RBENV_ROOT/bin:$PATH" × | |
| [appuser@app001]/usr/local% eval "$(rbenv init -)" × | |
| [appuser@app001]~% mkdir /usr/local/rbenv/plugins | |
| [appuser@app001]~% cd /usr/local/rbenv/plugins | |
| [appuser@app001]/usr/local/rbenv/plugins% git clone git://github.com/sstephenson/ruby-build.git | |
| [appuser@app001]/usr/local/rbenv/plugins% chgrp -R appuser ruby-build | |
| [appuser@app001]/usr/local/rbenv/plugins% chmod -R g+rwxs ruby-build | |
| [appuser@app001]/usr/local/rbenv/plugins% rbenv install --list | |
| ログアウトしたあとrbenvコマンドがないって言われた | |
| [appuser@app001]~% sudo emacs /etc/profile.d/rbenv.sh | |
| export RBENV_ROOT="/usr/local/rbenv | |
| export PATH="/usr/local/rbenv/bin:$PATH" | |
| eval "$(rbenv init -)" | |
| [appuser@app001]~% source /etc/profile.d/rbenv.sh | |
| rbenvでruby-2.0.0-p195のインストール | |
| [appuser@app001]~% rbenv install --list | |
| [appuser@app001]~% rbenv install 2.0.0-p195 | |
| gccがないって怒られた | |
| BUILD FAILED | |
| Inspect or clean up the working tree at /tmp/ruby-build.20130617180123.2421 | |
| Results logged to /tmp/ruby-build.20130617180123.2421.log | |
| Last 10 log lines: | |
| /tmp/ruby-build.20130617180123.2421/ruby-2.0.0-p195 /tmp/ruby-build.20130617180123.2421 /usr/local/rbenv/plugins | |
| checking build system type... x86_64-unknown-linux-gnu | |
| checking host system type... x86_64-unknown-linux-gnu | |
| checking target system type... x86_64-unknown-linux-gnu | |
| checking for gcc... no | |
| checking for cc... no | |
| checking for cl.exe... no | |
| configure: error: in `/tmp/ruby-build.20130617180123.2421/ruby-2.0.0-p195': | |
| configure: error: no acceptable C compiler found in $PATH | |
| See `config.log' for more details | |
| [appuser@app001]~% sudo yum -y install gcc make wget git radline-devel | |
| [appuser@app001]~% rbenv install 2.0.0-p195 | |
| opensslがないって怒られた | |
| BUILD FAILED | |
| Inspect or clean up the working tree at /tmp/ruby-build.20130617185115.12552 | |
| Results logged to /tmp/ruby-build.20130617185115.12552.log | |
| Last 10 log lines: | |
| installing default gems: /usr/local/rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications) | |
| bigdecimal 1.2.0 | |
| io-console 0.4.2 | |
| json 1.7.7 | |
| minitest 4.3.2 | |
| psych 2.0.0 | |
| rake 0.9.6 | |
| rdoc 4.0.0 | |
| test-unit 2.0.0.0 | |
| The Ruby openssl extension was not compiled. Missing the OpenSSL lib? | |
| [appuser@app001]~% sudo yum -y install openssl openssl-devel | |
| [appuser@app001]~% rbenv install 2.0.0-p195 | |
| [appuser@app001]~% ruby -v | |
| ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux] | |
| 入った! | |
| Rails4のインストール | |
| [appuser@app001]~% gem install rails --version 4.0.0.rc2 --no-ri --no-rdoc | |
| [appuser@app001]~% rails -v | |
| Rails 4.0.0.rc2 | |
| 入った! | |
| Unicornのインストール | |
| gem install unicornではなくアプリケーションごとにGemfileで定義しろとのことらしい | |
| [appuser@app001]~% cd | |
| [appuser@app001]~% git clone https://github.com/keokent/sample_app.git | |
| [appuser@app001]~% cd sample_app | |
| [appuser@app001]~/sample_app% emacs Gemfile | |
| gem 'unicorn' | |
| gem 'execjs' | |
| gem 'therubyacer' の追加 | |
| [appuser@app001]~/sample_app% bundle install | |
| エラーがでた libxm2がない | |
| Building native extensions. This could take a while... | |
| ERROR: Error installing nokogiri: | |
| ERROR: Failed to build gem native extension. | |
| /usr/local/rbenv/versions/2.0.0-p195/bin/ruby extconf.rb | |
| checking for libxml/parser.h... no | |
| ----- | |
| libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies. | |
| ----- | |
| *** extconf.rb failed *** | |
| Could not create Makefile due to some reason, probably lack of necessary | |
| libraries and/or headers. Check the mkmf.log file for more details. You may | |
| need configuration options. | |
| ・ | |
| ・ | |
| An error occurred while installing nokogiri (1.5.9), and Bundler cannot continue. | |
| Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling. | |
| [appuser@app001]~% sudo yum -y install libxml2-devel | |
| [appuser@app001]~% sudo yum -y install libxslt-devel | |
| [appuser@app001]~/sample_app% bundle install | |
| エラーが出た gem install pg -v '0.14.1'をやったかと聞かれた | |
| em::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. | |
| /usr/local/rbenv/versions/2.0.0-p195/bin/ruby extconf.rb | |
| checking for pg_config... no | |
| No pg_config... trying anyway. If building fails, please try again with | |
| --with-pg-config=/path/to/pg_config | |
| checking for libpq-fe.h... no | |
| Can't find the 'libpq-fe.h header | |
| *** extconf.rb failed *** | |
| Could not create Makefile due to some reason, probably lack of necessary | |
| libraries and/or headers. Check the mkmf.log file for more details. You may | |
| need configuration options. | |
| ・ | |
| ・ | |
| An error occurred while installing pg (0.14.1), and Bundler cannot continue. | |
| Make sure that `gem install pg -v '0.14.1'` succeeds before bundling. | |
| pgは使わないのでproduction環境にmysql2を追加 | |
| [appuser@app001]~/sample_app% emacs Gemfile | |
| productionに gem 'mysql2'を追加 | |
| [appuser@app001]~/sample_app% bundle install | |
| また怒られた | |
| Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. | |
| /usr/local/rbenv/versions/2.0.0-p195/bin/ruby extconf.rb | |
| checking for rb_thread_blocking_region()... yes | |
| checking for rb_wait_for_single_fd()... yes | |
| checking for mysql.h... no | |
| checking for mysql/mysql.h... no | |
| ----- | |
| mysql.h is missing. please check your installation of mysql and try again. | |
| ----- | |
| *** extconf.rb failed *** | |
| Could not create Makefile due to some reason, probably lack of necessary | |
| libraries and/or headers. Check the mkmf.log file for more details. You may | |
| need configuration options. | |
| [appuser@app001]~% ls /usr/include | |
| mysql.hがない | |
| [appuser@app001]~% sudo yum -y install mysql-devel | |
| [appuser@app001]~/sample_app% bundle install | |
| またまた怒られた | |
| Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. | |
| /usr/local/rbenv/versions/2.0.0-p195/bin/ruby extconf.rb | |
| checking for sqlite3.h... no | |
| sqlite3.h is missing. Try 'port install sqlite3 +universal' | |
| or 'yum install sqlite-devel' and check your shared library search path (the | |
| location where your sqlite3 shared library is located). | |
| *** extconf.rb failed *** | |
| Could not create Makefile due to some reason, probably lack of necessary | |
| libraries and/or headers. Check the mkmf.log file for more details. You may | |
| need configuration options. | |
| [appuser@app001]~/sample_app% emacs Gemfile | |
| development内の gem 'sqlite'を gem 'mysql2'に置き換える | |
| [appuser@app001]~/sample_app% bundle install | |
| またまたまたエラーがでた | |
| Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. | |
| /usr/local/rbenv/versions/2.0.0-p195/bin/ruby extconf.rb | |
| checking for main() in -lpthread... yes | |
| creating Makefile | |
| make | |
| compiling script.cc | |
| make: g++: コマンドが見つかりませんでした | |
| make: *** [script.o] エラー 127 | |
| g++とやらを入れる | |
| [appuser@app001]~% sudo yum install -y gcc-c++ | |
| [appuser@app001]~/sample_app% bundle install 通ったあ | |
| [appuser@app001]~/sample_app% source /etc/profile.d/rbenv.sh | |
| MySQLの初期設定とユーザの追加 | |
| [keoken@app001]~% emacs /etc/my.conf | |
| character-set-server = utf8 を追加 | |
| [keoken@app001]~% service mysqld start | |
| [keoken@app001]~% mysql_secure_installation | |
| [keoken@app001]~% chkconfig mysqld on | |
| [keoken@app001]~% mysql -u root | |
| mysql> GRANT ALL PRIVILEGES ON *.* TO keoken@localhost IDENTIFIED BY 'passwd'; | |
| mysql> exit | |
| [keoken@app001]~% mysql -u keoken -p | |
| mysql> CREATE DATABASE sample_app_production; | |
| Nginx設定 | |
| [appuser@app001]/etc/nginx% sudo mv nginx.conf nginx.conf.original | |
| [appuser@app001]/etc/nginx% sudo wget https://raw.github.com/defunkt/unicorn/master/examples/nginx.conf | |
| [appuser@app001]/etc/nginx% sudo emacs nginx.conf | |
| Unicorn.rb作成 | |
| [appuser@app001]~% cd sample_app/config | |
| [appuser@app001]~% wget -O unicorn.rb https://raw.github.com/defunkt/unicorn/master/examples/unicorn.conf.rb | |
| [appuser@app001]~% emacs unicorn.rb | |
| rails_env | |
| working_directory | |
| listen これらの書き換え | |
| pid | |
| stderr_path | |
| stdout_path | |
| [appuser@app001]~% mkdir -p shared/{pids,log} | |
| Unicornの起動 | |
| [appuser@app001 sample_app]$ bundle exec unicorn -c /home/appuser/sample_app/config/unicorn.rb --env production -D | |
| 怒られた ログで確認 | |
| [appuser@app001]~% cat /var/log/nginx.error.log | |
| データベースのマイグレートをしていなかった | |
| [appuser@app001 sample_app]$ RAILS_ENV=production bundle exec rake db:migrate | |
| [appuser@app001 sample_app]$ RAILS_ENV=production bundle exec rake db:populate | |
| assetsのprecompileもついでにやる | |
| [appuser@app001 sample_app]$ RAILS_ENV=production bundle exec rake assets:precompile | |
| database.ymlを編集していなかった | |
| [appuser@app001]~% emacs sample_app/config/database.yml | |
| Unicornの起動に成功 | |
| [appuser@app001 sample_app]$ bundle exec unicorn -c /home/appuser/sample_app/config/unicorn.rb --env production -D | |
| [appuser@app001 sample_app]$ ps aux | grep unicorn | |
| Nginxの再起動 | |
| [keoken@app001 ~]$ sudo service nginx restart | |
| ブラウザでhttp://app001.keoken.pbを確認 | |
| 404エラー | |
| ログを確認 | |
| [appuser@app001]~% tail -f /var/log/nginx.error.log | |
| 2013/06/18 18:53:57 [crit] 19068#0: *46 stat() "/home/appuser/sample_app/public//index.html" failed (13: Permission denied) | |
| Permission deniedだと言っている | |
| statでPermissionを確認 | |
| [appuser@app001]~% stat /home/appuser | |
| File: `/home/appuser' | |
| Size: 4096 Blocks: 8 IO Block: 4096 ディレクトリ | |
| Device: fd00h/64768d Inode: 24623 Links: 7 | |
| Access: (0700/drwx------) Uid: ( 1000/ appuser) Gid: ( 1000/ appuser) | |
| Access: 2013-06-18 18:39:29.073776207 +0900 | |
| Modify: 2013-06-18 18:37:51.547782159 +0900 | |
| Change: 2013-06-18 18:37:51.547782159 +0900 | |
| 権限がないっぽい | |
| Permissionの変更 | |
| [appuser@app001]~% chmod 755 /home/appuser | |
| ブラウザでhttp://app001.keoken.pbを確認 | |
| エラーログは吐き出されないけど、見れない | |
| [appuser@app001 sample_app]$ emacs config/environments/production.rb | |
| config.force_ssl = false trueからfalseに変更 | |
| Unicornの再起動 | |
| [appuser@app001 sample_app]$ ps ax | grep unicorn | |
| [appuser@app001 sample_app]$ kill -QUIT ○○○unicornのプロセスid | |
| [appuser@app001 sample_app]$ bundle exec unicorn -c /home/appuser/sample_app/config/unicorn.rb --env production -D | |
| ブラウザでsample_appを確認! |
% emacs /etc/init.d/nginx
% sudo chmod a+x /etc/init.d/nginx
ここは何か不具合があったのかな ?
yum や RPM で入れたミドルウェアの起動スクリプト ( /etc/init.d/ 以下のファイル ) は基本何もいじらなくて良いように調整されています。( 特にいじった訳でなくて emacs で中味見てただけなら ok です )
typo 直しておこう :octcat:
% sudo /sbin/chkconfig --add ngin
appuser ALL=(ALL) ALLこれでappuserにsudoが使えるようになる
ここは okkun にもコメントしたので https://gist.github.com/Tacahilo/5795684#comment-846534 を読んでね
gccがないって怒られた
... 略
opensslがないって怒られた
...
ハマったポイントを残しているので 👍
gcc や openssl-devel などをインストールする場合にも「なぜ」入れたかがログを追って分かるので よい記録です
yum -y install
-y付けない方がいいね。スクリプトとかでバッチ処理する場合は別だけど、yumは依存パッケージもまとめていれてくれるので、そのリストをよく確認してからポチった方がよいです。特に初めて入れるものは。
プロダクション環境だと、意図的にパッケージのバージョンを固定してたり独自リポジトリで管理してたりってことがあるので、軽い気持ちで入れた全然関係無さ気なパッケージの依存で、それらに影響を与えてしまうってことがあります。
あと、依存リストを見ることで単純に勉強にもなるよ。
@hibomaさん
レビューありがとうございます!起動スクリプトのファイルは中身が
どんなふうになってるのか見たかっただけでした。
% sudo /sbin/chkconfig --add ngin
に関しては、gistへのコピーミスでした・・・
appuserへのsudo権限に関しては、なにも考えずに与えていました。
自分もこの辺りのことよくわかっていないので、勉強します。
最後の方はメモの取り忘れとか、前後関係がぐちゃぐちゃかもしれないです。