経理からエンジニア転向した人のメモ

元経理マンがエンジニアに転向して現在

エンジニアになって3ヶ月目を振り返る

業務

Server

SSL

  • SSL(Let's encrypt)の取得〜自動更新

  • Nginxの設定と証明書取得の流れを理解できた。

logrotate

  • ログの肥大化によるディスク溢れを防止する
  • ログの世代管理やサイズ制限できる

monit

  • サーバー監視ツールの設定
    • サービスを監視しサービスがダウンしていた場合に、自動でサービスの復旧を行える

Nginx

Digest認証

  • ウェブサイトの閲覧制限をBASIC認証より安全に行える

cron

  • 特定のスクリプトやコマンドを自動化し、サーバーの保守運用を行える

Docker

CircleCIでDockerが動いているみたいなので、体験した。

GCP

  • インスタンス生成〜複製
    • immutable deployment と Blue Green Deployment のサーバー運用(厳密にはどちらとも異なる)。
      • ダウンタイムの最小化を実現

Program

Ruby

まだひよこ状態 dotinstall完了

PHP

こちらもひよこ状態 dotinstall完了 コード見てなんとなく修正はできる

Wordpress

  • キャッシュの制御(ハードとソフト?)をし、変更後にリロードもさせずに「あれ、変わっていませんよ?」を防止する。

Tools

Google Tag Manager

  • 基本的なタグとトリガーの設定し、今後も増加するタグの一元管理を行う
  • タグをバージョン管理することで、いつ、何の目的でタグを入れたかが明確になり、属人的な面から開放される & 管理が楽になる。

OWASP ZAP / Burp Suite

  • OWASP ZAPをインストール、プロキシとして動作させてHTTP通信を観察
  • Firefoxの拡張期である「FoxyProxy-statdard」を追加して、VirtualBox上で動作する特別な環境のみにプロキシを設定させる。

→指定したドメインを通る時だけOWASP ZAPを通してからリクエストを送ることで他の余計な通信を抽出しない。

  • POSTしたパラメータをOWASP ZAP / Burp でブレークして内容を書き換えて送信。

  • Basic認証で送信した際のBase64エンコードデータをリクエストヘッダで確認し、ツールのデコード機能で元の文字列を見る。

vagrant 2.1.5にアップデートしたら動かなくなったのを修正した

Vagrantをアップデートしたら動かなくなった。

VirtualBoxkusanagiRuby on Railsの勉強でもしようと思って 不用意にもvagrantを2.1.1から2.1.5にアップデートして、いざvagrant upを実行したら以下のエラーが出た。

$ vagrant up
Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant (= 2.1.1)'

あまり何も考えずにvagrant plugin expunge --reinstall

何故真ん中のコマンドを実行したのかわからないが、

vagrant plugin expunge --reinstall

This command permanently deletes all currently installed user plugins. It
should only be used when a repair command is unable to properly fix the
system.

Continue? [N]: y

All user installed plugins have been removed from this Vagrant environment!

Vagrant will now attempt to reinstall user plugins that were removed.
Installing the 'sahara' plugin. This can take a few minutes...
Fetching: open4-1.3.4.gem (100%)
Fetching: Platform-0.4.1.gem (100%)
Fetching: popen4-0.1.2.gem (100%)
Fetching: sahara-0.0.17.gem (100%)
Fetching: micromachine-2.0.0.gem (100%)
Fetching: vagrant-vbguest-0.16.0.gem (100%)
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Unable to resolve dependency: user requested 'vagrant (= 2.1.1)'

なんだこれは。となって色々ググっても みんなこのコマンドで直っていて、ここでエラー出ている人が見つからなかった。

その後も3つあるコマンドを色々繰り返しても同じようなエラーが出る。

しまいにはさっきと違うエラーが出たので結構やばいと思った。

$  vagrant plugin expunge --reinstall

This command permanently deletes all currently installed user plugins. It
should only be used when a repair command is unable to properly fix the
system.

Continue? [N]: 

Vagrant expunge has been declined. Skipping removal of plugins.

Vagrant will now attempt to reinstall user plugins that were removed.
Installing the 'vagrant' plugin. This can take a few minutes...
/opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/plugin/manager.rb:156:in `install_plugin': undefined method `name' for nil:NilClass (NoMethodError)
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/action/install_gem.rb:30:in `call'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/action/builder.rb:116:in `call'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/action/runner.rb:66:in `block in run'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/util/busy.rb:19:in `busy'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/action/runner.rb:66:in `run'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/command/base.rb:14:in `action'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/command/expunge.rb:77:in `block in execute'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/command/expunge.rb:69:in `each'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/command/expunge.rb:69:in `execute'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/plugins/commands/plugin/command/root.rb:66:in `execute'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/cli.rb:54:in `execute'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/lib/vagrant/environment.rb:291:in `cli'
    from /opt/vagrant/embedded/gems/2.1.5/gems/vagrant-2.1.5/bin/vagrant:164:in `<main>'

意を決して.vagrant.dディレクトリを探る。

*ここからは、たまたまうまくいっただけだと思うので、万が一があっても自己責任でお願いします。。。 自分もそこまで理解してやっているわけではございませんので、、

プラグイン周りのエラーぽかったので、plugins.jsonを見てみる。

Unable to resolve dependency: user requested 'vagrant (= 2.1.1)'
最初からこのエラーがずっと出ていたので、気になっていた。
vagrant2.1.1の設定のままになっているファイルがあるはずと。

プラグインのreinstallやらを最初からコマンドで紹介されていたので、 plugins.jsonを見つけてピンときた。

{"version":"1","installed":{"vagrant":{"ruby_version":"2.4.4","vagrant_version":"2.1.1","gem_version":"","require":"","sources":["https://rubygems.org/","https://gems.hashicorp.com/"],"installed_gem_version":"2.1.1"}}}

ここに2.1.1の記述があるので、2.1.5に変更してやってみた、

{"version":"1","installed":{"vagrant":{"ruby_version":"2.4.4","vagrant_version":"2.1.5","gem_version":"","require":"","sources":["https://rubygems.org/","https://gems.hashicorp.com/"],"installed_gem_version":"2.1.5"}}}

そしてvagrant upしたら

 $ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'yuya_tajima/kusanagi'...
==> default: Matching MAC address for NAT networking...

うごいた!!

ディレクトリ内を見ても他に2.1.1の設定がなさそうだったので、解決したぽい。

エラー時に意味も理解しないで不用意にコマンドうちまくるとなかなか苦労します。。

CentOS7にrbenvでRubyをインストールする

Gitのインストール

// 入っているか確認する
$ git --version
-bash: git: command not found


// gitのインストール
$ sudo yum -y install git

rbenvのインストール

(rbenv)https://github.com/rbenv/rbenvとは、rubyバージョンを簡単に切り替えてくれる。 複数のバージョンを管理できるツール。

// git cloneする
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

// pathを通す
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

// 初期化する
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

// シェルの再起動をして内容を反映
$ exec $SHELL -l

$ rbenv --version
rbenv 1.1.1-39-g59785f6

rbenvはインストールできた。

ruby-buildをclone

rbenvのプラグインだそうで。 こちらの記事が詳しく書いてある。

rbenv + ruby-build はどうやって動いているのか - takatoshiono's blog

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

rubyが使えるようになるまで

rbenvでインストールできるリストを見る。 指定すれば複数のrubyバージョンをインストールできる。

$ rbenv install --list
Available versions:
...
(略)

// Ruby 2.5.0の安定版をインストール
$ rbenv install 2.5.0-rc1
Downloading ruby-2.5.0-rc1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0-rc1.tar.bz2
Installing ruby-2.5.0-rc1...

BUILD FAILED (CentOS Linux 7 using ruby-build 20180822-6-g44f0f53)

Inspect or clean up the working tree at /tmp/ruby-build.20180904003149.6259
Results logged to /tmp/ruby-build.20180904003149.6259.log

Last 10 log lines:
installing rdoc:                    /home/vagrant/.rbenv/versions/2.5.0-rc1/share/ri/2.5.0/system
installing capi-docs:               /home/vagrant/.rbenv/versions/2.5.0-rc1/share/doc/ruby
The Ruby readline extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y readline-devel` to fetch missing dependencies.

Configure options used:
  --prefix=/home/vagrant/.rbenv/versions/2.5.0-rc1
  LDFLAGS=-L/home/vagrant/.rbenv/versions/2.5.0-rc1/lib 
  CPPFLAGS=-I/home/vagrant/.rbenv/versions/2.5.0-rc1/include 

失敗した。

以下に記載してあるように、エラーを見てみると、、、yum install -y readline-develしろって書いてある。 他のパッケージとの依存関係でエラーになったぽい。

ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y readline-devel` to fetch missing dependencies.

試してみる。

$ sudo yum install -y readline-devel

もう一度トライ

$ rbenv install 2.5.0-rc1
Downloading ruby-2.5.0-rc1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0-rc1.tar.bz2
Installing ruby-2.5.0-rc1...
Installed ruby-2.5.0-rc1 to /home/vagrant/.rbenv/versions/2.5.0-rc1

できた!

$  rbenv versions
  2.5.0-rc1

$ rbenv global 2.5.0-rc1

$ ruby -v
ruby 2.5.0rc1 (2017-12-14 trunk 61243) [x86_64-linux]

rbenv globalで複数のバージョンを指定している時に使いたいバージョンを指定できる。