自宅回線の品質とか、いろいろと監視したい情報があったのでConoHa上にcactiをセットアップします。
今後はセンサー用の端末からrrdファイルをConoHa上にpushしてグラフ化させていこうとぼんやり考え中。
■目的
ConoHaのVPS(CentOS 6.4 x64)上でcactiを動かしたい。
Webサーバはnginxを使い、cactiアクセス専用にあらかじめ取得したDynamic DNSのドメインを使う。
■パッケージインストール
■PHP設定(nginxからPHPを使うために必要)
・php-fpmの設定(nginxでphpを動かすために必要)
※設定はデフォルトのままでよさげ
■MySQL設定
・mysqlにcactiの設定を追加
■cactiの設定(ユーザ名、パスワードはいろいろと変更すること)
・DB作成
今後はセンサー用の端末からrrdファイルをConoHa上にpushしてグラフ化させていこうとぼんやり考え中。
■目的
ConoHaのVPS(CentOS 6.4 x64)上でcactiを動かしたい。
Webサーバはnginxを使い、cactiアクセス専用にあらかじめ取得したDynamic DNSのドメインを使う。
■パッケージインストール
$ sudo yum install nginx php-fpm mysql-server cacti
(..snip..)
$
(..snip..)
$
■PHP設定(nginxからPHPを使うために必要)
・php-fpmの設定(nginxでphpを動かすために必要)
※設定はデフォルトのままでよさげ
$ cat /etc/php-fpm.d/www.conf
(..snip..)
listen = 127.0.0.1:9000
(..snip..)
listen.allowed_clients = 127.0.0.1
(..snip..)
user = apache
(..snip..)
group = apache
(..snip..)
$
$ service php-fpm status
php-fpm is stopped
$ service php-fpm start
(..snip..)
[ OK ]
$
$ netstat -na | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN ←起動できてる
$
$ chkconfig --list | grep php-fpm
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
$ sudo chkconfig php-fpm on
$ chkconfig --list | grep php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$
(..snip..)
listen = 127.0.0.1:9000
(..snip..)
listen.allowed_clients = 127.0.0.1
(..snip..)
user = apache
(..snip..)
group = apache
(..snip..)
$
$ service php-fpm status
php-fpm is stopped
$ service php-fpm start
(..snip..)
[ OK ]
$
$ netstat -na | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN ←起動できてる
$
$ chkconfig --list | grep php-fpm
php-fpm 0:off 1:off 2:off 3:off 4:off 5:off 6:off
$ sudo chkconfig php-fpm on
$ chkconfig --list | grep php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$
■MySQL設定
・mysqlにcactiの設定を追加
$ service mysqld status
mysqld is stopped
$ sudo service mysqld start
[ OK ]
Starting mysqld: [ OK ]
$ chkconfig | grep mysql
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
$ sudo chkconfig mysqld on
$ mysql_secure_installation
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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y ★rootパスワードを作成する
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!
$
mysqld is stopped
$ sudo service mysqld start
[ OK ]
Starting mysqld: [ OK ]
$ chkconfig | grep mysql
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
$ sudo chkconfig mysqld on
$ mysql_secure_installation
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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y ★rootパスワードを作成する
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!
$
■cactiの設定(ユーザ名、パスワードはいろいろと変更すること)
・DB作成
$ mysql -u root -p
Enter password: ←先ほど設定したmysqlのrootパスワードを聞かれます
(..snip..)
mysql> CREATE DATABASE cacti;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'; ←利用に合わせて変更する
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -u cactiuser -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql
Enter password:cactiuser
$</div>
・cactiのDBアクセス設定変更
■nginxにcacti設定を追加
・認証ファイルを準備
・nginxにサイトを追加
■Firewallを変更
・ファイアウォール設定
■そのままだとrraファイルが作成されないので、一旦ポーリングが正しく動作するか確認
・cactiのrraを作成する
・ポーリングの自動実行コメントアウトを解除する(rrdファイル書込みのためポーリングはcactiユーザで実行させる)
Enter password: ←先ほど設定したmysqlのrootパスワードを聞かれます
(..snip..)
mysql> CREATE DATABASE cacti;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'; ←利用に合わせて変更する
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
$ mysql -u cactiuser -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql
Enter password:cactiuser
$</div>
・cactiのDBアクセス設定変更
$ sudo vi /etc/cacti/db.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser"; ←DB作成に合わせて変更
$database_password = "cactiuser"; ←DB作成に合わせて変更
$database_port = "3306";
$database_ssl = false;
(..snip..)
$
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser"; ←DB作成に合わせて変更
$database_password = "cactiuser"; ←DB作成に合わせて変更
$database_port = "3306";
$database_ssl = false;
(..snip..)
$
■nginxにcacti設定を追加
・認証ファイルを準備
$ sudo mkdir /etc/nginx/auth
$ sudo htpasswd -c /etc/nginx/auth/htpasswd.cacti cacti
New password:
Re-type new password:
Adding password for user cacti
$
$ sudo htpasswd -c /etc/nginx/auth/htpasswd.cacti cacti
New password:
Re-type new password:
Adding password for user cacti
$
・nginxにサイトを追加
$ sudo cat /etc/nginx/conf.d/cacti.conf
server {
listen 80;
server_name XXXX.XXXX.XXXX; ←Cacti用アクセスドメインを指定
index index.html index.php;
location / {
root /data/www;
index index.html;
}
## cacti
location /cacti {
alias /usr/share/cacti;
# Basic Authentication
auth_basic "cacti";
auth_basic_user_file auth/htpasswd.cacti; ←/etc/nginx/auth/htpasswd.cactiが使われる
}
location ~ ^/cacti/(.*\.php)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^/cacti(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/cacti/$fastcgi_script_name;
include fastcgi_params;
# Basic Authentication
auth_basic "cacti";
auth_basic_user_file auth/htpasswd.cacti;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /\.ht {
deny all;
}
}
$
$ sudo service nginx start
Starting nginx: [ OK ]
$
server {
listen 80;
server_name XXXX.XXXX.XXXX; ←Cacti用アクセスドメインを指定
index index.html index.php;
location / {
root /data/www;
index index.html;
}
## cacti
location /cacti {
alias /usr/share/cacti;
# Basic Authentication
auth_basic "cacti";
auth_basic_user_file auth/htpasswd.cacti; ←/etc/nginx/auth/htpasswd.cactiが使われる
}
location ~ ^/cacti/(.*\.php)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^/cacti(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME /usr/share/cacti/$fastcgi_script_name;
include fastcgi_params;
# Basic Authentication
auth_basic "cacti";
auth_basic_user_file auth/htpasswd.cacti;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /\.ht {
deny all;
}
}
$
$ sudo service nginx start
Starting nginx: [ OK ]
$
■Firewallを変更
・ファイアウォール設定
$ sudo system-config-firewall-tui
※「Customize」から「WWW (HTTP)」にチェックを入れて保存する
$
※「Customize」から「WWW (HTTP)」にチェックを入れて保存する
$
■そのままだとrraファイルが作成されないので、一旦ポーリングが正しく動作するか確認
・cactiのrraを作成する
$ sudo -u cacti /usr/bin/php /usr/share/cacti/poller.php
$
$
・ポーリングの自動実行コメントアウトを解除する(rrdファイル書込みのためポーリングはcactiユーザで実行させる)
$ sudo vi /etc/cron.d/cacti
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
$
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
$