2014年8月3日日曜日

AWS上でPiwikでウェブ解析

仕事でPiwikというWebアクセスログ解析ツールを使用する事になったので、AWSで構築してみます。
  • AWS EC2(Red Hat Enterprise Linux 6.5)
    • AWSは、契約済とします。
  • Piwik 2.4.1
  • MacBook Air 10.9.4 (クライアント端末)

  1. AWS EC2でのマシン作成手順。(既にある場合は読み飛ばしてください。)
    1. AWS マネジメントコンソールに接続する
      https://console.aws.amazon.com/console/home
    2. 「EC2」を選択する。
    3. 「Lunch Instance」を選択する。
    4. 「Red Hat Enterprise Linux 6.5(PV)」の「64-bit」を選択して「Select」を選択する。
    5. とりあえず、Type「t1.micro」を選択して「Next: Configure Instance Details」を選択する。
    6. Step 3: Configure Instance Details画面で「Enable termination protection」の「Protect against accidental termination」のチェックボックスをOnにして、「Next: Add Strage」を選択する。
    7. Sizeを「30」、Volume Typeを「General Purpose (SSD)」として、「Next: Tag Instance」を選択する。
    8. Tagは適当に、Name=「Name」、Value=「piwik_test」とかしておく。「Next: Configure Security Group」を選択する。
    9. Step 3: Configure Security Group画面でSSH通信の設定のSourceに「My  IP」を選択し、IPアドレスを確認して、「Review and Launch」を選択する。
    10. 「Lunch」を選択する。「Create a new key pair」を選択し、Key pair nameに「piwik_test」とでも入力し、「Download key pair」をクリックした後に、「Launch Instance」を選択する。
    11. マシンへsshで接続する。rootのパスワードを設定しておく。
      $ sudo su -
      # passwd
  2. piwikをインストールする。(主にrootで実施)
    1. 公式サイトからPiwikをダウンロードしておく。
      # wget http://builds.piwik.org/piwik.zip
      --2014-08-02 08:27:36--  http://builds.piwik.org/piwik.zip
      Resolving builds.piwik.org... 176.31.58.94
      Connecting to builds.piwik.org|176.31.58.94|:80... connected.
      HTTP request sent, awaiting response... 200 OK
      Length: 10143342 (9.7M) [application/zip]
      Saving to: “piwik.zip”
      
      100%[======================================>] 10,143,342  2.67M/s   in 4.6s
      
      2014-08-02 08:27:42 (2.10 MB/s) - “piwik.zip” saved [10143342/10143342]
    2. Apache(Webサーバ)のインストール
      # yum -y install httpd
    3. PHP関連パッケージインストール
      # yum -y install php php-mysql php-pdo php-mbstring php-xml php-gd
    4. MySQLインストール
      # yum -y install mysql mysql-server mysql-libs
    5. MySQL初期設定と起動
      # mysql_secure_installation
      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
            SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
      
      
      In order to log into MySQL to secure it, we'll need the current
      password for the root user.  If you've just installed MySQL, and
      you haven't set the root password yet, the password will be blank,
      so you should just press enter here.
      
      Enter current password for root (enter for none):
      OK, successfully used password, moving on...
      
      Setting the root password ensures that nobody can log into the MySQL
      root user without the proper authorisation.
      
      Set root password? [Y/n] Y
      New password:
      Re-enter new password:
      Password updated successfully!
      Reloading privilege tables..
       ... Success!
      
      
      By default, a MySQL installation has an anonymous user, allowing anyone
      to log into MySQL without having to have a user account created for
      them.  This is intended only for testing, and to make the installation
      go a bit smoother.  You should remove them before moving into a
      production environment.
      
      Remove anonymous users? [Y/n] Y
       ... Success!
      
      Normally, root should only be allowed to connect from 'localhost'.  This
      ensures that someone cannot guess at the root password from the network.
      
      Disallow root login remotely? [Y/n] Y
       ... Success!
      
      By default, MySQL comes with a database named 'test' that anyone can
      access.  This is also intended only for testing, and should be removed
      before moving into a production environment.
      
      Remove test database and access to it? [Y/n] Y
       - Dropping test database...
       ... Success!
       - Removing privileges on test database...
       ... Success!
      
      Reloading the privilege tables will ensure that all changes made so far
      will take effect immediately.
      
      Reload privilege tables now? [Y/n] Y
       ... Success!
      
      Cleaning up...
      
      
      
      All done!  If you've completed all of the above steps, your MySQL
      installation should now be secure.
      
      Thanks for using MySQL!
      # mysql -uroot -p
      <省略>
      mysql> create user piwik identified by '****';    パスワード「****」は、任意の文字列を入れる。
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> create database piwik;
      Query OK, 1 row affected (0.00 sec)
      
      mysql> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | piwik              |
      +--------------------+
      3 rows in set (0.00 sec)
      
      mysql> grant all on piwik.* to piwik;
      Query OK, 0 rows affected (0.00 sec)
      
      # mysql piwik -upiwik -p
      Enter password:
      

    1. Piwikインストール
      # mkdir /var/www/html/piwik
      # unzip piwik.zip
      # cp -rp piwik/* /var/www/html/piwik
      # rm -f How\ to\ install\ Piwik.html
      # chown -R apache:apache /var/www/html/piwik
    2. Apache起動
      # service httpd start
    3. ブラウザで「http://<Public DNS or IP adress of the instance>/piwik/」に接続する。と、以下のような画面が出る。「次へ」を選択する。
    4. システムの確認画面で、すべてチェックが入っていることを確認し、「次へ」を選択する。
    5. データベースのセットアップを以下の用に入力する。パスワードは、MySQKでpiwikユーザを作成した際に設定したものをしていする。
      「データベースサーバ」が、デフォルトで「127.0.0.1」になっているが、なぜか接続が失敗するので、「localhost」に変更するとうまくいった。が、原因は不明。。。
    6. 「次へ」を選択すると、テーブル作成が正常にできたメッセージが表示される。さらに、「次へ」を選択する。
    7. スーパーユーザ画面で、任意の名前とパスワードのユーザを作成する。「次へ」を選択すると進むウェブサイトのセットアップ画面でこのブログを登録してみる。

    8. 「次へ」を選択すると、解析対象のWebサイトに埋め込むJavaScriptのタグが表示されるので、それをコピーして対象Webサイトの「</body>」の前にペーストする。「次へ」を選択して、最後に「Piwikを続ける」を選択する。
    9. ブラウザで「http://<Public DNS or IP adress of the instance>/piwik/」に接続する。先ほど、作成したスーパユーザのアカウント情報を使ってログインする。

    10. 以下のようなダッシュボード画面がみれる。
なんかいろいろみれそうです!まさに、Google Analiticsに似ている。Piwikおもしろそうです。
また、AWSもすぐに仮想マシンが作成できて便利!

おわり

0 件のコメント:

コメントを投稿