オープンソースIT資産管理ツール Snipe-ITのインストール

メモ:  Category:centos

パソコンやプリンタ、その他周辺機器の管理にどのようなツールが使われているのでしょうか? そんなIT資産管理ツールである「Snipe-IT」をインストールしてみたので記録していきます。 最初は、CentOS/Redhat又はDebian/Ubuntu用に用意されたインストーラーを使ってみたのですが 最後までインストールできなかったため、必要なものを個別にインストールしています。

オープンソースのIT資産管理ソフト Snipe-ITとは

管理はしたいが予算は無い。と、いうことで趣味と実益を兼ねるべく、良さそうなIT資産管理ソフトを物色してみました。

資産管理できそうなソフトはいくつかあるのですが、このSnipe-ITはシンプルに機器の台帳管理、ソフトウェアのライセンス管理だけを したい時に向いているのではないかと思います。Snipe-ITで出来そうなことは、資産(パソコンやプリンター)やユーザー、ライセンスを台帳管理しそれぞれを紐付けしたり 貸し出し機の貸出先や期限管理、減価償却など色々できそうです。

他にもあるIT資産管理関係ソフト

Snipe-IT以外でIT資産管理に使えそうなソフトも残しておきます。

Snipe-ITのインストール要件

ここでは、CentOS 7.3へSnipe-IT v3.6.6 build 1をインストールしていきます。Snipe-ITのドキュメントを確認すると Snipe-ITを動作させる為には次のものが必要となります。

  • PHP >= 5.5.9 <=7.0
  • PHP Extensions:
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • cURL PHP Extension
  • MySQL PHP Extension
  • PHPZIP extension
  • Fileinfo
  • LDAP extension (only if using LDAP)
  • MySQL or MariaDB
  • GD Library (>=2.0) or Imagick PHP extension (>=6.3.8)
  • Git

WebサーバーとPHP、データベースのインストール

Snipe-ITに必要な動作環境を構築していきます。nginx、PHP、PHP-FPR、MariaDBをインストールしてWebサーバーを経由してPHPが動作できる環境を構築していきます。

ちなみに、selinuxは、無効にしてあります。

nginxのインストール

最初にEPEL及びremiリポジトリが使えるように用意します。

# yum -y install epel-release
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

nginxをインストールします。

# yum -y --enablerepo=epel install nginx

サービスとして実行するように登録し、nginxを起動します。

# systemctl enable nginx
# systemctl start nginx

httpd (80番ポート)への通信を許可するため、次のコマンドにてファイアウォールの設定を行います。

# firewall-cmd --add-service=http --zone=public --permanent
success
# firewall-cmd --reload
success

PHP及びPHP-FPMのインストール

PHP及び拡張機能をインストールします。 LDAPは使用する予定がないので、インストールしていません、必要な場合は、php-ldapを追加します。

# yum -y --enablerepo=remi-php70 install php php-fpm php-mbstring php-pdo php-mysqlnd php-mcrypt php-gd php-zip

テキストエディタを使用して、php-fpmの実行ユーザとグループを初期値のapacheからnginxへ変更します。

# vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

サービスとして実行するように登録し、php-fpmを起動します。

# systemctl enable php-fpm
# systemctl start php-fpm

MariaDBのインストール

MariaDBをインストールします。

# yum install mariadb mariadb-server

サービスとして実行するようにMariaDBの起動と自動起動を設定しておきます。

# systemctl enable mariadb.service
# systemctl start mariadb.service

MariaDBのセキュリティ向上のため、mysql_secure_installationを実行して rootパスワードの設定や不要なデータベースの削除を行います。

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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): (そのままEnterキーを押す)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:  (MariaDBのrootユーザーに新たに設定するパスワードを入力)
Re-enter new password:  (新パスワードを再入力)
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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  (rootユーザーの接続元をlocalhostに限定)
 ... Success!

By default, MariaDB 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  (testデータベースを削除)
 - 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!

Snipe-ITのインストール

動作環境が整ったので、Snipe-ITをインストールしていきます。Snipe-ITは、Gitから取得できるようなので最初に gitをインストールしておきます。

# yum -y install git

gitをインストールしたらSnipe-ITをcloneします。ここでは、「/var/www/」へ配置することとしています。

# git clone https://github.com/snipe/snipe-it /var/www/snipe-it

データベースとデータベースユーザーの作成

MariaDBへSnipe-IT用のデータベースとユーザーを作成します。

# mysql -u root -p
MariaDB [(none)]< create database snipeit;
MariaDB [(none)]< grant all on snipeit.* to user_snipeit@localhost identified by 'パスワード';
MariaDB [(none)]< flush privileges;
MariaDB [(none)]< exit;

Snipe-ITの環境設定

Snipe-ITの環境設定を行います。

# cd /var/www/snipe-it
# cp .env.example .env
# vi .env

~ 設定した内容に合わせて修正します。

APP_URL=(インストールしているSnipe-ITのアドレス)
APP_TIMEZONE=(タイムゾーン「'Asia/Tokyo'」)
APP_LOCALE=(ロケール「ja」)
 
# REQUIRED: DATABASE SETTINGS
DB_HOST=localhost
DB_DATABASE=snipeit
DB_USERNAME=user_snipeit
DB_PASSWORD=(パスワード)
 
# REQUIRED: OUTGOING MAIL SERVER SETTINGS
MAIL_HOST=(環境に合わせてSMTPサーバーを設定)
MAIL_PORT=(SMTPのポート)
MAIL_FROM_ADDR=(メールアドレス)
MAIL_REPLYTO_ADDR=(メールアドレス)

パーミッションの設定

配置したSnipe-ITのpublic/uploadsやstorageにパーミッションを設定します。

# chown -R nginx:nginx /var/www/snipe-it
# chmod -R 755 storage
# chmod -R 755 storage/private_uploads
# chmod -R 755 public/uploads

composerのインストール及びパッケージのインストール

Snipe-ITを配置したディレクトリへ「/var/www/snipe-it/」composerをダウンロードします。

# curl -sS https://getcomposer.org/installer | php

このコマンドはPHPの設定内容をチェックして、composer.pharを作業ディレクトリにダウンロードします。 composer.pharは、Composerのバイナリファイルで、PHAR(PHP archive)はPHPのためのアーカイブ形式です。 composer.pharは、コマンドラインなどから実行することができます。

composerを使ってパッケージをインストールします。

# php composer.phar install --no-dev --prefer-source

APP_KEYの生成

APP_KEYを生成します。このキーは、Snipe-ITの環境設定ファイル(.env)に書かれます。データを復号するために別途バックアップを取っておいたほうが良いようです。

# php artisan key:generate
Application key [base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=] set successfully.

nginxの設定

nginxとPHP-FPMの連携設定やDocumentRootなどを設定します。

# vi /etc/nginx/nginx.conf

~ 以下、設定
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  snipe-it.bnote.net;         ← 変更  
        root         /var/www/snipe-it/public;   ← 配置パスへ変更
        index index.php index.html index.htm;   ← 追記

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            try_files $uri $uri/ /index.php$is_args$args;   ← 追記
        }
        ↓ 追記
        location ~ \.php$ {
            try_files $uri $uri/ =404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}

設定が完了したらnginxを再起動しておきます。

# systemctl reload nginx

ここまで設定したらブラウザからSnipe-ITの設定をしていきます。

Snipe-ITを使う準備

インストール作業が完了したらブラウザからSnipeーITへ接続してみます。次のような画面が表示されれば、インストールが成功していると思います。 URLの部分が赤い×になっていますが、これはAPP_URLにIPアドレスで指定したためです。そのまま、次へ進みましたが問題ないようです。

Snipe-ITの設定確認

次に進むとデータベースのテーブル作成になります。

データベースへテーブルを作成

管理者ユーザーを設定します。「姓」「名」の部分が「姓」「姓」となっていますが雰囲気でわかると思うので気にしないで進めていきます。

管理者の設定

設定が完了するとダッシュボードが表示されます。

最初の画面 ダッシュボード

以上でインストール完了です。

メモ

snipe-itがうまく起動しない場合、次のログを確認すると何かわかるかもしれません。

  • /var/www/snipe-it/storage/logs/laravel.log
  • /var/log/nginx/error.log

また、より詳細にエラーを追いたい場合は「.env」のAPP_DEBUGをtrueにすると良いです。

bluenote by BBB