mamori017.log

歴史的クソブログ

Visual Studio CodeでPHPファイルを開くと警告が出るときの対応

f:id:mamori017:20170429032033p:plain

Windows版のVisual Studio CodeでPHPファイルを開くと、Cannot calidate since no PHP executable is set. Use the setting php.validate.executablePath' to configure PHP executable.と警告が出る。

これはVisual Studio CodeにPHPの実行ファイルのパスが設定されていないことで表示されるので、 警告にある通り[ファイル]-[基本設定]-[設定]からsetting.jsonを開き、php.validate.executablePathphp.exeのフルパスを設定する。*1

setting.json
{
    "php.validate.executablePath": "php.exeのフルパス"
}

php.exeのパスを設定していない時は構文に誤りがあってもシンタックスエラーにならなかったが、設定後はシンタックスエラーが発生するようになった。

f:id:mamori017:20170425221004p:plain

入力中に構文チェックをする場合は、リンターを入力時に実行するようsetting.jsonphp.validate.runの項目を追記する。

setting.json
{
    "php.validate.run": "onType"
}

*1:Mac版でも構文チェックが行われなかったのでたぶん同じ設定が必要。

LogstashをインストールしてElasticsearchにデータを登録する

(2018/02/18) LogstashからElasticsearchへのデータ登録については新しい記事があります。 mamori017.hatenablog.com

前提

Elasticsearch、Kibanaがインストール済みの環境にLogstashをインストールすることを前提にしています。

Logstash

www.elastic.co

リポジトリを登録する。

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

httpsに対応したapt methodをインストールする。

$ sudo apt-get install apt-transport-https

パッケージのダウンロード元を追記する。

$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list

Logstashをインストールする。

$ sudo apt-get update
$ sudo apt-get install logstash

Elasticsearchにデータを登録する

適当にログを用意する。試しにWindows IISログを/home/share/ubuntu/test.logとして保存したものを使用する。

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2017-04-12 01:48:53
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2017-04-12 01:51:31 127.0.0.1 GET / - 80 - 127.0.0.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 - 200 0 0 1280
2017-04-12 01:51:31 127.0.0.1 GET /iisstart.png - 80 - 127.0.0.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://127.0.0.1/ 200 0 0 11
2017-04-12 01:51:31 127.0.0.1 GET /favicon.ico - 80 - 127.0.0.1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/56.0.2924.87+Safari/537.36 http://127.0.0.1/ 404 0 2 2

データを取り込むための設定を行う。

$ sudo vi /etc/logstash/conf.d/pipeline.conf

pipeline.confについてはよくわかっていないので、とりあえず登録を行うファイルとファイルの読み込み開始位置の設定、登録先のElasticsearchのURLだけを記述した。

input {
    file {
        path => "/home/share/test.log"
        start_position => "beginning"
    }
}

output {
    elasticsearch {
        hosts => ["localhost:9200"]
    }
}

logstashを起動する。

$ sudo service logstash start

curl 'localhost:9200/_cat/indices?v'で登録されているか確認してみる。index項目名がlogstash-yyyy.mm.ddのデータが存在しているはず。

$ sudo curl 'localhost:9200/_cat/indices?v'
health status index               uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   logstash-2017.04.21 MgSZzLJLSdaFJfhLlUao6A   5   1          7            0     22.4kb         22.4kb
yellow open   .kibana             TjYeEr9cRZShGEaM-BAd0g   1   1          2            0      9.6kb          9.6kb

Kibanaでは取り込んだログを見ることができた。

f:id:mamori017:20170421171232p:plain

データ分析基盤構築入門[Fluentd、Elasticsearch、Kibanaによるログ収集と可視化]

データ分析基盤構築入門[Fluentd、Elasticsearch、Kibanaによるログ収集と可視化]

Ubuntu 16.04にElasticSearch 5.3.0とKibana 5.3.0をインストールする

OpenJDK

ElasticsearchはJava 8が必要になるのでOpenJDKを使用してインストールする。

$ apt-get install openjdk-8-jdk

Javaバージョンを確認する。

ubuntu@ubuntu:~$ java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

Elasticsearch

www.elastic.co

リポジトリを登録する。

$ wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

パッケージのダウンロード元を追記する。

$ echo "deb http://packages.elastic.co/elasticsearch/5.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-5.x.list

Elasticsearchをインストールする。

$ sudo apt-get update
$ sudo apt-get install elasticsearch

この時点でElasticsearchのバージョンは5.0.0-alphaになっているはずなので5.3.0にアップデートする。このアップデートをスキップした場合、ブラウザでKibanaを見たときにElasticsearchとKibanaでバージョンが違うと警告が出る。

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.deb
$ sudo dpkg -i elasticsearch-5.3.0.deb

リモート接続を許可するため、/etc/elasticsearch/elasticsearch.ymlの設定を変更する。

変更前
#network.host: "localhost"
変更後
network.host: "0.0.0.0"

Elasticsearchを開始する。

ubuntu@ubuntu:~$ sudo /etc/init.d/elasticsearch start
[ ok ] Starting elasticsearch (via systemctl): elasticsearch.service.

curl http://localhost:9200でElasticsearchが動作しているか確認したところ、curl: (7) Failed to connect to localhost port 9200 接続を拒否されましたと出力された。

blog.johtani.info

この記事によると、ElasticsearchはIPv4IPv6どちらにもバインドするようなので、IPv6を無効にするようhostsファイルを変更する。

変更前
::1 localhost
変更後
#::1 localhost

再度確認してみたところ表示されるようになった。

ubuntu@ubuntu:~$ curl "http://localhost:9200/"
{
  "name" : "EVAwQeO",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "y0uAjCj5TE2M6Z-Zw4TK9g",
  "version" : {
    "number" : "5.3.0",
    "build_hash" : "3adb13b",
    "build_date" : "2017-03-23T03:31:50.652Z",
    "build_snapshot" : false,
    "lucene_version" : "6.4.1"
  },
  "tagline" : "You Know, for Search"
}

Kibana

www.elastic.co

リポジトリを登録する。

$ sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

httpsに対応したapt methodをインストールする。

$ sudo apt-get install apt-transport-https

パッケージのダウンロード元を追記する。

$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list

Kibanaをインストールする。

$ sudo apt-get update
$ sudo apt-get install kibana

リモート接続を許可するため、/etc/kibana/kibana.ymlの設定を変更する。

server.host: "0.0.0.0"

Kibanaを開始する。

ubuntu@ubuntu:~$ sudo /etc/init.d/kibana start
kibana started

ブラウザからhttp://localhost:5601にアクセスして確認する。 ここで警告が出ていなければインストールは完了。

f:id:mamori017:20170418145559p:plain

Elasticsearchが起動していなかったり、ElasticsearchとKibanaのバージョンが異なっていたりするとStatus:Redと表示される。この画面の場合はElasticsearchが起動していない場合。

f:id:mamori017:20170419102308p:plain

データ分析基盤構築入門[Fluentd、Elasticsearch、Kibanaによるログ収集と可視化]

データ分析基盤構築入門[Fluentd、Elasticsearch、Kibanaによるログ収集と可視化]