<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.6.2">Jekyll</generator><link href="http://blog.atwata.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://blog.atwata.com/" rel="alternate" type="text/html" /><updated>2018-02-20T08:38:45+00:00</updated><id>http://blog.atwata.com/</id><title type="html">atwata developer blog</title><subtitle>ITエンジニアの技術メモ置き場
</subtitle><entry><title type="html"></title><link href="http://blog.atwata.com/2018/02/20/2017-09-06-rbenv-error.html" rel="alternate" type="text/html" title="" /><published>2018-02-20T08:38:45+00:00</published><updated>2018-02-20T08:38:45+00:00</updated><id>http://blog.atwata.com/2018/02/20/2017-09-06-rbenv-error</id><content type="html" xml:base="http://blog.atwata.com/2018/02/20/2017-09-06-rbenv-error.html">&lt;p&gt;rbenvを使って、ruby 2.4.1をインストールしようとしたが下記のエラー&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ rbenv install 2.4.1
Downloading ruby-2.4.1.tar.bz2...
-&amp;gt; https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.bz2
Installing ruby-2.4.1...

BUILD FAILED (CentOS Linux 7 using ruby-build 20170726-9-g86909bf)

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

Last 10 log lines:
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20170905165809.22615/ruby-2.4.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;configure: error: no acceptable C compiler found in $PATH&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;とのことなのでCコンパイラ(gcc)をインストール&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo yum install gcc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;再度試してみるが、今度は違うエラーが発生。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ rbenv install 2.4.1
Downloading ruby-2.4.1.tar.bz2...
-&amp;gt; https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.bz2
Installing ruby-2.4.1...

BUILD FAILED (CentOS Linux 7 using ruby-build 20170726-9-g86909bf)

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

Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies.

Configure options used:
  --prefix=/home/vagrant/.rbenv/versions/2.4.1
  LDFLAGS=-L/home/vagrant/.rbenv/versions/2.4.1/lib 
  CPPFLAGS=-I/home/vagrant/.rbenv/versions/2.4.1/include 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;ライブラリが足りないとコマンドまで教えてくれるので、それに従ってインストール&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo yum install -y openssl-devel readline-devel zlib-devel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;するとruby2.4.1をインストールできました！&lt;/p&gt;</content><author><name></name></author></entry><entry><title type="html">go言語のインストールからhello worldまで</title><link href="http://blog.atwata.com/app/2018/01/30/golang-hello-world.html" rel="alternate" type="text/html" title="go言語のインストールからhello worldまで" /><published>2018-01-30T00:00:00+00:00</published><updated>2018-01-30T00:00:00+00:00</updated><id>http://blog.atwata.com/app/2018/01/30/golang-hello-world</id><content type="html" xml:base="http://blog.atwata.com/app/2018/01/30/golang-hello-world.html">&lt;h2 id=&quot;インストール&quot;&gt;インストール&lt;/h2&gt;

&lt;p&gt;centos7環境でgo言語はyumでインストールできる。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo yum install golang
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;インストールできたのでバージョンを確認&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ go version
go version go1.8.3 linux/amd64
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;hello-worldの確認&quot;&gt;Hello Worldの確認&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;hello.go&lt;/code&gt; ファイルを作成する&lt;/p&gt;

&lt;p&gt;日本語の確認もしたかったので、公式ドキュメントにあるソースをコピペ。&lt;/p&gt;

&lt;p&gt;公式→ &lt;a href=&quot;http://golang-jp.org/&quot;&gt;http://golang-jp.org/&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;fmt&quot;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;fmt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Println&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, 世界&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;err&quot;&gt;実行する。&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;go&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;go&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;go&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unknown&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subcommand&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;hello.go&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;go ファイル名&lt;/code&gt; ではなく &lt;code class=&quot;highlighter-rouge&quot;&gt;go run ファイル名&lt;/code&gt; らしい&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ go run hello.go 
Hello, 世界
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;実行ファイルを作ることもできる（スクリプト言語と異なり、golangがない環境でも生成されたバイナリを実行可能）&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ go build hello.go 
$ ls
hello  hello.go
$ ./hello  
Hello, 世界
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Linux上でWindows向けにコンパイルすることもできる&lt;/p&gt;

&lt;p&gt;※-oで出力ファイル名を指定&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ GOOS=windows GOARCH=amd64 go build -o ./hello.exe
$ ls
hello  hello.exe  hello.go
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;このhello.exeとhelloをWindows環境に持っていって実行してみる&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;c:\tmp&amp;gt;dir
2018/01/30  18:38    &amp;lt;DIR&amp;gt;          .
2018/01/30  18:38    &amp;lt;DIR&amp;gt;          ..
2018/01/30  17:56         1,551,539 hello
2018/01/30  18:37         1,627,136 hello.exe

c:\tmp&amp;gt;hello
Hello, 世界

c:\tmp&amp;gt;hello.exe
Hello, 世界
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;あれ？helloもhello.exeも両方実行できる。なんでだろう。
helloのほうはエラーになることを期待してたのに&lt;/p&gt;</content><author><name></name></author><category term="golang" /><category term="centos7" /><summary type="html">インストール</summary></entry><entry><title type="html">rubyのrmagickで画像を結合・リサイズ・合成する</title><link href="http://blog.atwata.com/app/2018/01/05/rmagick-sample.html" rel="alternate" type="text/html" title="rubyのrmagickで画像を結合・リサイズ・合成する" /><published>2018-01-05T00:00:00+00:00</published><updated>2018-01-05T00:00:00+00:00</updated><id>http://blog.atwata.com/app/2018/01/05/rmagick-sample</id><content type="html" xml:base="http://blog.atwata.com/app/2018/01/05/rmagick-sample.html">&lt;h2 id=&quot;インストール&quot;&gt;インストール&lt;/h2&gt;

&lt;p&gt;まずはLinux上にImageMagickをインストールする(CentOS)&lt;/p&gt;

&lt;p&gt;言語に依存しない画像処理ソフトウェアであるImageMagick（イメージマジック）をインストールする。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo yum install ImageMagick ImageMagick-devel
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;rubyで扱えるようにするためのgemを入れる&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gem install rmagick
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;使い方&quot;&gt;使い方&lt;/h2&gt;

&lt;h3 id=&quot;画像をファイルから読み込んで２倍の大きさにしてファイルに書き出すサンプル&quot;&gt;画像をファイルから読み込んで２倍の大きさにしてファイルに書き出すサンプル&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;require 'rmagick'

image = Magick::ImageList.new(&quot;from.jpg&quot;)
image = image.scale(2.0)
image.write(&quot;to.jpg&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;２つの画像を結合するサンプル&quot;&gt;２つの画像を結合するサンプル&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;require 'rmagick'

image = Magick::ImageList.new(&quot;from1.jpg&quot;, &quot;from2.jpg&quot;)
image = image.append(false)	#falseだと左右につなげる。trueだと上下につなげる
image.write(&quot;to.jpg&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;画像をリサイズする&quot;&gt;画像をリサイズする&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;require 'rmagick'

imageList = Magick::ImageList.new(&quot;from.jpg&quot;)
imageList = imageList.resize(200, 200)
imageList.write(&quot;to.jpg&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;二つの画像を合成する&quot;&gt;二つの画像を合成する&lt;/h3&gt;

&lt;p&gt;透過pngなど透明部分がある画像ならそこは抜いてくっつける。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;imageListFrom = Magick::ImageList.new(&quot;from.jpg&quot;)
imageListFrame = Magick::ImageList.new(&quot;frame.png&quot;)
imageList = imageListFrom.composite(imageListFrame, 0, 0, Magick::OverCompositeOp)
imageList.write(&quot;to.png&quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="ruby" /><category term="rmagick" /><category term="imagemagick" /><summary type="html">インストール</summary></entry><entry><title type="html">centos7へのpostgresqlのインストール・初期設定</title><link href="http://blog.atwata.com/middle/2017/12/30/postgresql-install-and-setup.html" rel="alternate" type="text/html" title="centos7へのpostgresqlのインストール・初期設定" /><published>2017-12-30T00:00:00+00:00</published><updated>2017-12-30T00:00:00+00:00</updated><id>http://blog.atwata.com/middle/2017/12/30/postgresql-install-and-setup</id><content type="html" xml:base="http://blog.atwata.com/middle/2017/12/30/postgresql-install-and-setup.html">&lt;h2 id=&quot;インストール&quot;&gt;インストール&lt;/h2&gt;

&lt;p&gt;yumでインストールする。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yum install postgresql-server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;yumでインストールすると&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;postgresql-server&lt;/li&gt;
  &lt;li&gt;postgresql&lt;/li&gt;
  &lt;li&gt;postgresql-lib&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;がまとめてインストールされる&lt;/p&gt;

&lt;h2 id=&quot;データベース初期化&quot;&gt;データベース初期化&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;postgresql-setup initdb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;/var/lib/pgsql/dataに設定ファイルが作成される。&lt;/p&gt;

&lt;h2 id=&quot;自動起動設定&quot;&gt;自動起動設定&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl enable postgresql.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;postgresql起動&quot;&gt;postgresql起動&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl start postgresql.service
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;postgresqlにログイン&quot;&gt;postgresqlにログイン&lt;/h2&gt;

&lt;p&gt;postgresqlのログイン方法はいろいろあるが、ここではOSユーザpostgresqlでログインしてみる。postgresユーザならpostgresqlに対するパスワードの認証なしでDBにアクセスすることができる。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;su - postgres
psql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="postgresql" /><category term="centos7" /><summary type="html">インストール</summary></entry><entry><title type="html">ローカル環境のみでgitリポジトリを作り、履歴管理やブランチ操作を行いたい</title><link href="http://blog.atwata.com/tool/2017/10/10/init-local-bare-git-repository.html" rel="alternate" type="text/html" title="ローカル環境のみでgitリポジトリを作り、履歴管理やブランチ操作を行いたい" /><published>2017-10-10T00:00:00+00:00</published><updated>2017-10-10T00:00:00+00:00</updated><id>http://blog.atwata.com/tool/2017/10/10/init-local-bare-git-repository</id><content type="html" xml:base="http://blog.atwata.com/tool/2017/10/10/init-local-bare-git-repository.html">&lt;h2 id=&quot;ローカル環境にgitリモートブランチを作る&quot;&gt;ローカル環境にgitリモートブランチを作る&lt;/h2&gt;

&lt;p&gt;個人開発のちょっとしたツールやプログラムのソース管理について。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;githubを使ってもよいのだが、公開したくないタイプのソースである&lt;/li&gt;
  &lt;li&gt;gitlabをわざわざ立ち上げるのも面倒&lt;/li&gt;
  &lt;li&gt;有料のgithubプライベート版を使うまでもない&lt;/li&gt;
  &lt;li&gt;そもそもちょっとした履歴管理とローカルディレクトリ間でのpush、pullができればよい&lt;/li&gt;
  &lt;li&gt;具体的には開発環境で動かして試したソースをpusuして、本番環境でpullしたい&lt;/li&gt;
  &lt;li&gt;ちなみに開発も本番も同じサーバ&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;コマンドのみなら、すべてローカル環境で管理できる。&lt;/p&gt;

&lt;p&gt;以下手順。&lt;/p&gt;

&lt;h3 id=&quot;共有リポジトリを作成する&quot;&gt;共有リポジトリを作成する&lt;/h3&gt;

&lt;p&gt;ローカルサーバにあるがリモートリポジトリとして扱われる&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cd /path/to
$ mkdir myapp.git
$ cd myapp.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;リモートリポジトリのディレクトリは.gitをつけるのが慣例らしい&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ git --bare init --shared
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;リモートリポジトリとして初期化するコマンド&lt;/p&gt;

&lt;p&gt;–bareは作業ファイルをもたないpushされるための専用のリポジトリという意味&lt;/p&gt;

&lt;p&gt;–shareはこのリポジトリを共有可能にするためのオプション。これがないとpushしてもファイルを作成できない。&lt;/p&gt;

&lt;h3 id=&quot;ファイルが作成されていることを確認&quot;&gt;ファイルが作成されていることを確認&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ls
branches  config  description  HEAD  hooks  info  objects  refs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;別の場所にいってcloneする&quot;&gt;別の場所にいってcloneする&lt;/h3&gt;

&lt;p&gt;ちなみにローカルからのcloneとはネットワーク経由での取得なので、
 &lt;code class=&quot;highlighter-rouge&quot;&gt;ssh localhost&lt;/code&gt; で接続できるようになっている必要がある。&lt;/p&gt;

&lt;p&gt;公開鍵認証でログインできるようになっていればSSHエージェント転送を有効にするのがラク&lt;/p&gt;

&lt;p&gt;ためしにtmpディレクトリに移動しclone&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cd /tmp/
$ pwd
/tmp
$ git clone localhost:/path/to/myapp.git
Cloning into 'myapp'...
warning: You appear to have cloned an empty repository.
$ cd myapp/
$ ls
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これであとは通常のgithubに対してgit操作するようにソースの管理を行える&lt;/p&gt;

&lt;h2 id=&quot;既存のローカルディレクトリを管理対象にする&quot;&gt;既存のローカルディレクトリを管理対象にする&lt;/h2&gt;

&lt;p&gt;ついでにこのリポジトリに対してすでに存在するディレクトリをgit管理対象とした上で、pushする方法&lt;/p&gt;

&lt;h3 id=&quot;既存のファイルがあるディレクトリに移動して初期化リモートリポジトリ追加&quot;&gt;既存のファイルがあるディレクトリに移動して初期化、リモートリポジトリ追加&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd /path/to/hoge/
git init
git remote add origin localhost:/path/to/myapp.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;git fetchでエラーが出なければ正しくリモートリポジトリが設定されている&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git fetch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;既存のファイルを追加してコミットプッシュ&quot;&gt;既存のファイルを追加してコミット、プッシュ&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git add .
git commit
git push origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="git" /><summary type="html">ローカル環境にgitリモートブランチを作る</summary></entry><entry><title type="html">Rails5でnginx+pumaでproduction環境を構築する</title><link href="http://blog.atwata.com/middle/2017/09/30/rails5-nginx-puma.html" rel="alternate" type="text/html" title="Rails5でnginx+pumaでproduction環境を構築する" /><published>2017-09-30T00:00:00+00:00</published><updated>2017-09-30T00:00:00+00:00</updated><id>http://blog.atwata.com/middle/2017/09/30/rails5-nginx-puma</id><content type="html" xml:base="http://blog.atwata.com/middle/2017/09/30/rails5-nginx-puma.html">&lt;h2 id=&quot;nginxのインストール&quot;&gt;nginxのインストール&lt;/h2&gt;

&lt;p&gt;過去に書いたのこちらを参考&lt;/p&gt;

&lt;p&gt;http://blog.atwata.com/middle/2017/04/21/centos-nginx.html&lt;/p&gt;

&lt;h2 id=&quot;rails側puma設定&quot;&gt;rails側puma設定&lt;/h2&gt;

&lt;p&gt;rails5ならデフォルトで入っている&lt;/p&gt;

&lt;p&gt;rails serverで起動しているのもpuma(webrickではない)&lt;/p&gt;

&lt;p&gt;とりあえずpumaをproduction設定で起動&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec puma -t 5:5 -e production -C config/puma.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;secret_key_base未設定エラー&quot;&gt;secret_key_base未設定エラー&lt;/h3&gt;

&lt;p&gt;すると、こういうエラーがでる&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RuntimeError: Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;secret_key_baseがセットされていないというエラー&lt;/p&gt;

&lt;p&gt;対応は下記のようにsecretを生成して、環境変数にセットする&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec rake secret
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;を実行すると長いランダム文字列が生成させる&lt;/p&gt;

&lt;p&gt;これはconfig/secret.ymlで管理しているのだが、productionは下記のようになっている&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;production:
  secret_key_base: &amp;lt;%= ENV[&quot;SECRET_KEY_BASE&quot;] %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;cookieの生成に使うらしいので、セキュリティ上ファイル化は好ましくないらしい。&lt;/p&gt;

&lt;p&gt;都度生成し、環境変数として渡す仕組みになっている&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;export SECRET_KEY_BASE=hogehoge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;のようにする&lt;/p&gt;

&lt;p&gt;改めて起動&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec puma -t 5:5 -e production -C config/puma.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;assetsprecompile未実施エラー&quot;&gt;assets:precompile未実施エラー&lt;/h3&gt;

&lt;p&gt;起動ログにエラーは出ていないが画面にアクセスするとエラー。
productionはデフォルトでは起動したコンソールにエラーは出さず、ログファイルに出力される。&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;log/production.log&lt;/code&gt; を確認すると下記の表示。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ActionView::Template::Error (The asset &quot;application.css&quot; is not present in the asset pipeline.):
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;確認するとproduction環境では自動でcssやjsをコンパイルしてくれないので（デフォルト設定がそうなっているので）
自分でプリコンパイルする必要がある。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bundle exec rake assets:precompile RAILS_ENV=production
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;しかし&lt;/p&gt;

&lt;h3 id=&quot;yarnがインストールされていないエラー&quot;&gt;yarnがインストールされていないエラー&lt;/h3&gt;

&lt;p&gt;下記のエラーが発生&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
Download Yarn at https://yarnpkg.com/en/docs/install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;yarnがないというエラー。rails5では使うらしい。&lt;/p&gt;

&lt;p&gt;yarnとはjavascriptのパッケージマネージャ。npmの後継として利用され始めている。&lt;/p&gt;

&lt;p&gt;下記のようにインストール。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm install yarn -g
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;起動して画面が表示されるようになった、&lt;/p&gt;

&lt;h3 id=&quot;静的ファイルpublicにアクセスできない&quot;&gt;静的ファイル(public)にアクセスできない&lt;/h3&gt;

&lt;p&gt;しかしcssが効かない。画像も表示されない。&lt;/p&gt;

&lt;p&gt;確認すると&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;config/environments/production.rb&lt;/code&gt; が下記のような設定になっているために読み込みができなくなっていた&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;上記のように強制的にtrueにする。&lt;/p&gt;

&lt;p&gt;ついにproduction環境のpumaでrailsアプリが起動するようになった。&lt;/p&gt;

&lt;h2 id=&quot;次はnginxとのつなぎ込み&quot;&gt;次はnginxとのつなぎ込み&lt;/h2&gt;

&lt;p&gt;例として下記のように設定ファイルを記述する。&lt;/p&gt;

&lt;p&gt;/etc/nginx/conf.d/myapp.conf&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;upstream puma_myapp {
    server  unix:/path/to/myapp/tmp/puma_myapp.sock;
}

server {
    listen       80;
    server_name  [ホスト名];

    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    root /path/to/myapp/;

    client_max_body_size 100m;
    error_page  404              /404.html;
    error_page  500 502 503 504  /500.html;

    location / {
        proxy_pass http://127.0.0.1:3000/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;nginx再起動&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;これで無事に80番ポートでnginx経由でrailsアプリにアクセスできるようになりました。&lt;/p&gt;</content><author><name></name></author><category term="rails" /><category term="nginx" /><category term="puma" /><summary type="html">nginxのインストール</summary></entry><entry><title type="html">railsでpostgresを使ってテーブルを先に作ってそれを画面に表示</title><link href="http://blog.atwata.com/app/2017/09/27/rails-postgres-model.html" rel="alternate" type="text/html" title="railsでpostgresを使ってテーブルを先に作ってそれを画面に表示" /><published>2017-09-27T00:00:00+00:00</published><updated>2017-09-27T00:00:00+00:00</updated><id>http://blog.atwata.com/app/2017/09/27/rails-postgres-model</id><content type="html" xml:base="http://blog.atwata.com/app/2017/09/27/rails-postgres-model.html">&lt;h2 id=&quot;ざっくりやること&quot;&gt;ざっくりやること&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;database.ymlでのdb設定&lt;/li&gt;
  &lt;li&gt;テーブルと対になったModel作成&lt;/li&gt;
  &lt;li&gt;Modelを呼び出すコントローラと表示するビュー作成&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;db設定をpostgresとしてアプリ作成&quot;&gt;db設定をpostgresとしてアプリ作成&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails new myapp -d postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;databaseyml編集&quot;&gt;database.yml編集&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;config/database.yml
default:
  adapter: postgresql
  encoding: unicode
  pool: 5
  # dbにアクセスするユーザ名/パスワード/ホストを指定
  username: postgres
  password: postgres
  host: 127.0.0.1

# developmentのところにdatabase名を指定
development:
  &amp;lt;&amp;lt;: *default
#  database: myapp_development
  database: postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;空のモデル作成&quot;&gt;空のモデル作成&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;テーブル名はsampleとする&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails generate model sample
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;テーブル名とpkのカラムを指定&quot;&gt;テーブル名とPKのカラムを指定&lt;/h2&gt;

&lt;p&gt;sample.rbが作成されるのでテーブル名を指定&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;app/model/sample.rb
class Sample &amp;lt; ActiveRecord::Base
  self.table_name = 'sample'
end

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;マイグレーション&quot;&gt;マイグレーション&lt;/h2&gt;

&lt;p&gt;これをしないとPengindMigrationErrorが発生する&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rake db:migrate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;コントローラ作成&quot;&gt;コントローラ作成&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails generate controller samplelist index
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;コントローラ編集&quot;&gt;コントローラ編集&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;app/controllers/samplelist_controller.rb&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;SamplelistController&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ApplicationController&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@title&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Model Sample'&lt;/span&gt;
    &lt;span class=&quot;vi&quot;&gt;@datas&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;all&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ビュー編集&quot;&gt;ビュー編集&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;app/views/samplelist/index.html.erb&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;%= @title %&amp;gt;&amp;lt;/h2&amp;gt;
&amp;lt;table&amp;gt;
&amp;lt;% @datas.each do |data| %&amp;gt;
&amp;lt;tr&amp;gt;
  &amp;lt;td&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;column1&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;%= data.column2 %&amp;gt;&amp;lt;/td&amp;gt;
  &amp;lt;td&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;column3&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%&amp;gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;td&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;%= data.column4 %&amp;gt;&amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&amp;lt;% end %&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ブラウザで画面確認&quot;&gt;ブラウザで画面確認&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;下記にアクセス&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;http://localhost:3000/samplelist/index&lt;/p&gt;</content><author><name></name></author><category term="rails" /><category term="postgres" /><summary type="html">ざっくりやること</summary></entry><entry><title type="html">railsをとりあえず動かしてみる</title><link href="http://blog.atwata.com/app/2017/09/24/rails-try-to-run-first.html" rel="alternate" type="text/html" title="railsをとりあえず動かしてみる" /><published>2017-09-24T00:00:00+00:00</published><updated>2017-09-24T00:00:00+00:00</updated><id>http://blog.atwata.com/app/2017/09/24/rails-try-to-run-first</id><content type="html" xml:base="http://blog.atwata.com/app/2017/09/24/rails-try-to-run-first.html">&lt;h2 id=&quot;まずはrailsをインストール&quot;&gt;まずはrailsをインストール&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;rubyとgemがインストールされていることが前提&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gem install rails
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;インストール完了後、バージョン確認&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ひな形の作成&quot;&gt;ひな形の作成&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;sampleという名前で作ってみる&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails new sample
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;試しに起動してみる&quot;&gt;試しに起動してみる&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;localhost以外からの接続も受け付ける場合は &lt;code class=&quot;highlighter-rouge&quot;&gt;-b 0.0.0.0&lt;/code&gt; をつける&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd sample
rails server -b 0.0.0.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下記にアクセスしてようこそ画面がでてくればまずはOK&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://動かしているIP:3000/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;起動するポートを変更したい場合&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Address already in useエラーが発生して、起動できない場合がある。
その場合は指定するポート番号を変更する。&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rails server -b 0.0.0.0 -p 3001
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="ruby" /><category term="rails" /><summary type="html">まずはrailsをインストール</summary></entry><entry><title type="html">centos7でcronを時間通り動かす</title><link href="http://blog.atwata.com/os/2017/09/13/centos7-cron.html" rel="alternate" type="text/html" title="centos7でcronを時間通り動かす" /><published>2017-09-13T00:00:00+00:00</published><updated>2017-09-13T00:00:00+00:00</updated><id>http://blog.atwata.com/os/2017/09/13/centos7-cron</id><content type="html" xml:base="http://blog.atwata.com/os/2017/09/13/centos7-cron.html">&lt;h2 id=&quot;anacron&quot;&gt;anacron&lt;/h2&gt;

&lt;p&gt;centos7デフォルトだとanacronが動くため設定した時間通りにcronが実行されない&lt;/p&gt;

&lt;h2 id=&quot;通常のcronを入れなおす&quot;&gt;通常のcronを入れなおす&lt;/h2&gt;

&lt;p&gt;noanacronをインストールし、anacronをインストールする（この順番で入れる必要がある）&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo yum -y install cronie-noanacron
sudo yum -y remove cronie-anacron
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;インストール後は再起動が必要&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo systemctl restart crond
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下記設定ファイルに実行したジョブを記載&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo vi /etc/cron.d/dailyjobs

# Run the daily, weekly, and monthly jobs if cronie-anacron is not installed
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# run-parts
2 4 * * * root [ ! -f /etc/cron.hourly/0anacron ] &amp;amp;&amp;amp; run-parts /etc/cron.daily
22 4 * * 0 root [ ! -f /etc/cron.hourly/0anacron ] &amp;amp;&amp;amp; run-parts /etc/cron.weekly
42 4 1 * * root [ ! -f /etc/cron.hourly/0anacron ] &amp;amp;&amp;amp; run-parts /etc/cron.monthly
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="cron" /><category term="anacron" /><summary type="html">anacron</summary></entry><entry><title type="html">postgresqlにログインできない（Ident authentication failedエラー）</title><link href="http://blog.atwata.com/db/2017/09/07/postgresql-login.html" rel="alternate" type="text/html" title="postgresqlにログインできない（Ident authentication failedエラー）" /><published>2017-09-07T00:00:00+00:00</published><updated>2017-09-07T00:00:00+00:00</updated><id>http://blog.atwata.com/db/2017/09/07/postgresql-login</id><content type="html" xml:base="http://blog.atwata.com/db/2017/09/07/postgresql-login.html">&lt;h2 id=&quot;下記のエラーが出てログインできない場合の対処法&quot;&gt;下記のエラーが出てログインできない場合の対処法&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;psql: FATAL:  Ident authentication failed for user &quot;postgres&quot;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;通常イメージするユーザ名とパスワードでログインできるようにする。&lt;/p&gt;

&lt;h3 id=&quot;パスワードを設定する&quot;&gt;パスワードを設定する&lt;/h3&gt;

&lt;p&gt;まずはOSのpostgresユーザにスイッチし、postgres上のパスワードを設定する&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ su - postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ psql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;postgres=# alter role postgres with password 'postgres';
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;ログイン周りの設定をきちんとする&quot;&gt;ログイン周りの設定をきちんとする&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo vi /var/lib/pgsql/data/pg_hba.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# TYPE  DATABASE        USER            ADDRESS                 METHOD

# &quot;local&quot; is for Unix domain socket connections only
#local   all             all                                     peer
local   all             all                                     md5
# IPv4 local connections:
#host    all             all             127.0.0.1/32            ident
host    all             all             127.0.0.1/32            md5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;上記のMETHODを適宜変更する&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;md5だと通常イメージするパスワード認証&lt;/li&gt;
  &lt;li&gt;trustだとOS認証（OSユーザで認証済みならパスワードなしでログインできる）&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;typeがlocalのところはこうやってログインするときの設定&quot;&gt;TYPEがlocalのところはこうやってログインするときの設定&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;psql -U postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;typeがhostのところはこうやってログインするときの設定&quot;&gt;TYPEがhostのところはこうやってログインするときの設定&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;psql -U postgres -h 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;postgresql再起動&quot;&gt;postgresql再起動&lt;/h3&gt;

&lt;p&gt;設定ファイルを変更したらpostgresqlを再起動しないと反映されない&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ sudo service postgresql restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="postgresql" /><summary type="html">下記のエラーが出てログインできない場合の対処法</summary></entry></feed>