2012年7月24日火曜日

さくらのVPS1G移設作業 phpMyAdminインストール(CentOS6.2)



■phpMyAdminのインストール

# cd ~
# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8.1/phpMyAdmin-3.3.8.1-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1291797693&use_mirror=jaist
# tar -zxvf phpMyAdmin-3.3.8.1-all-languages.tar.gz
# mv ./phpMyAdmin-3.3.8.1-all-languages /var/lib/phpMyAdmin
# cd /var/lib/phpMyAdmin/
# cp /var/lib/phpMyAdmin/config.sample.inc.php /var/lib/phpMyAdmin/config.inc.php
# vi /var/lib/phpMyAdmin/config.inc.php
# diff config.inc.php config.sample.inc.php
17c17
< $cfg['blowfish_secret'] = 'gqearjgjbykdc.sgS8zjdtayjz3fmgezncxxbRxzoxstvx'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
---
> $cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
44,45c44,45
< $cfg['Servers'][$i]['controluser'] = 'pma';
< $cfg['Servers'][$i]['controlpass'] = 'hogepass';
---
> // $cfg['Servers'][$i]['controluser'] = 'pma';
> // $cfg['Servers'][$i]['controlpass'] = 'pmapass';
48,61c48,61
< $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
< $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
< $cfg['Servers'][$i]['relation'] = 'pma_relation';
< $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
< $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
< $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
< $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
< $cfg['Servers'][$i]['history'] = 'pma_history';
< $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
< $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
< $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
< $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
< $cfg['Servers'][$i]['recent'] = 'pma_recent';
< $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
---
> // $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
> // $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
> // $cfg['Servers'][$i]['relation'] = 'pma_relation';
> // $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
> // $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
> // $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
> // $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
> // $cfg['Servers'][$i]['history'] = 'pma_history';
> // $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
> // $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
> // $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
> // $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
> // $cfg['Servers'][$i]['recent'] = 'pma_recent';
> // $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
63c63
< $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
---
> // $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';

# mkdir config
# chmod o+rwx ./config
# mysql -uroot -p < /var/lib/phpMyAdmin/examples/create_tables.sql
# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant all on phpmyadmin.* to pma@localhost identified by "hogepass";
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye



・ベーシック認証設定
# vi virtualhost.conf

以下の設定を追加する。

    ServerName phpmyadmin.example.jp
    DocumentRoot /var/lib/phpMyAdmin
        
                AuthType Basic
                AuthName "phpmyadmin.example.jp"
                AuthUserFile /etc/httpd/conf/phpmyadmin.example.jp_auth_file
                Require valid-user
        


ベーシック認証ファイル準備
# htpasswd -c /etc/httpd/conf/phpmyadmin.example.jp_auth_file hogehoge

# /etc/init.d/mysqld restart
mysqld を停止中:                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]


これで
http://phpmyadmin.example.jp
にアクセスする。
ベーシンク認証後にphpMyAdminのログイン画面が表示されれば成功

http://phpmyadmin.example.jp/setup
にて設定が可能らしいがまだ未検証、どうやら設定すると"/var/lib/phpMyAdmin/config/"に設定ファイルが出来るので、手動で"/var/lib/phpMyAdmin/config.inc.php"にコピー?などして反映させるらしい。

2012年6月19日火曜日

さくらのVPS1G移設作業 mysql(CentOS6.2)

前回の基本設定からの続きでmysqlのインストールと設定


■mysqlインストール
○なんだか設定失敗した様子でMYSQLが動かない、だいぶ嵌ったので再インストールしました。

・mysqlをアンインストール
# yum remove mysql mysql-server mysql-devel
# ll /usr/share/mysql/
# ll /var/lib/mysql/
なんだかフォルダが色々残っている。

完全クリーンインストールしたいのでフォルダごと削除してみる。
# rm -rf /usr/share/mysql
# rm -rf /var/lib/mysql

・mysqlをインストール
# yum install mysql mysql-server mysql-devel
# /etc/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
120607 15:44:48 [Warning] '--default-character-set' is deprecated and will be removed in a future release. Please use '--character-set-server' instead.
120607 15:44:48 [ERROR] Can't find messagefile '/usr/share/mysql/english/errmsg.sys'
120607 15:44:48 [ERROR] Aborting

120607 15:44:48 [Note] 

Installation of system tables failed!  Examine the logs in
/var/lib/mysql for more information.

You can try to start the mysqld daemon with:

    shell> /usr/libexec/mysqld --skip-grant &

and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:

    shell> /usr/bin/mysql -u root mysql
    mysql> show tables

Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /var/lib/mysql that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the /usr/bin/mysqlbug script!

[失敗]
起動失敗!"[ERROR] Can't find messagefile '/usr/share/mysql/english/errmsg.sys'"とあるので完全クリーンインストールしようとして、"/usr/share/mysql"を消したのが原因か?

フォルダを確認する
# ll /usr/share/mysql/
確かに、たくさんあったディレクトリが1コも無い
"'/usr/share/mysql/english/errmsg.sys'"等一式のファイルは"mysql-libs"に含まれているっぽいので、"mysql-libs"を再インストールしてみる
# yum -reinstall mysql-libs
# ll /usr/share/mysql/
色々なフォルダが復活!
各種errmsg.sysファイルが復旧した様子!!

今までは、こんな事しなかったのだが、
きっと昔はyumで"mysql mysql-server mysql-devel"を再インストールすると依存関係でmysql-libsも再インストールされていたが途中から変わったのかな?
とにかく随分ハマッてしまった。

気を取り直してmysql起動
# /etc/init.d/mysqld restart
mysqld を停止中:  [  OK  ]
MySQL Daemon failed to start.
mysqld を起動中:  [失敗]
またも起動失敗_| ̄|○
ログに以下の記述を発見
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

と言うことで以下を実行する。
# mysql_install_db
# /etc/init.d/mysqld start
mysqld を起動中:  [  OK  ]
起動成功!!!
これでようやくmysqlが初期状態になったはず

2012年6月12日火曜日

さくらのVPS1G移設作業 基本設定(CentOS6.2)

さくらのVPS512が、大幅グレードアップした なんとメモリ2倍(512M→1G)!! 旧VPS512の料金980円だったのだが、新プランではVPS1Gが利用可能 こちらは、なんとメモリ2倍の1Gに加えHDDは5倍(20G→100G)なんて太っ腹!! 以前のコストパフォーマンスもなかなか良いと思っていたが、 メモリ1G HDD100Gで980円だとコストパフォーマンス3倍くらい? 今回の移設の様子を見て、近くのサーバーから順次移設するのかな?また忙しくなりそうだ それはさて置き、そのまま使ってもメモリは1Gに増設になるのだが、すでにHDD80%弱を消費している状況、 HDDを5倍にするには再契約してサーバー移設作業が必要なので、面倒だがサーバー移設を行う。 ■サーバー初期設定 ○新サーバーのCentOSのバージョン確認
# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m

# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m

# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
すると6.2、旧サーバーは5.5でした。 きっと、同じバージョンで作業したほうが楽なのだが、「きっと色々ハマるんだろうな~」と思いながらイバラの道を進んでみる。 主な移設項目 MYSQL ZABBIX Redmine XOOPS SVN よく512Mのメモリでこんなに動いてたもんだ、チューニングしつつ綱渡り的な運用だったので、 今回はギリギリのチューニングしなくても安定動作してくれることを願う。 ○ユーサー設定 とりあえずrootログイン&rootパスワード変更

# passwd
Changing password for user root.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

# useradd -m hoge
# passwd hoge
Changing password for user hoge.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
この接続を残したまま 作成したユーザーhogeで新規SSH接続&su

$ su -
Password: 
※万が一rootとhoge共にパスワードタイプミスした時にレスキューモードで起動とかは面倒なので、 ログインできてかつ、suに成功してから、rootログインの接続を切る ○SSHポート変更

# cd /etc/ssh/
# mkdir /etc/ssh/00Backup
# cp /etc/ssh/sshd_config /etc/ssh/00Backup/sshd_config_`date +%Y%m%d%H%M`
# vi /etc/ssh/sshd_config
# diff sshd_config 00Backup/sshd_config_201205301253
14d13
< Port 2022

# /etc/init.d/sshd restart
Stopping sshd: [  OK  ]
Starting sshd: [  OK  ]
○ファイアーウォール設定

# vi ~/iptables-init.sh
# cat ~/iptables-init.sh
#!/bin/sh

iptables -F
iptables -X

iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

iptables -A INPUT -s 10.0.0.0/8 -j DROP
iptables -A INPUT -s 172.16.0.0/12 -j DROP
iptables -A INPUT -s 192.168.0.0/16 -j DROP

# iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

iptables -A INPUT -p tcp --dport 20022 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# sh ~/iptables-init.sh
# iptables -L

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  10.0.0.0/8           anywhere
DROP       all  --  172.16.0.0/12        anywhere
DROP       all  --  192.168.0.0/16       anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:2022
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

# iptables-save > /etc/sysconfig/iptables
# /etc/init.d/ssh   iptables rs estart
iptables: Flushing firewall rules: [  OK  ]
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Unloading modules: [  OK  ]
iptables: Applying firewall rules: [  OK  ]

# chkconfig --list |grep iptagbles
iptables        0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptagblesのランレベル2345がOnになっていることを確認する ※念のため新規接続してから切断する ○日本語環境設定

$ su -
Password: 

# mkdir /etc/sysconfig/00Backup
# cp /etc/sysconfig/i18n /etc/sysconfig/00Backup/i18n_`date +%Y%m%d%H%M`
# vi /etc/sysconfig/i18n 
# cat /etc/sysconfig/i18n 
LANG="ja_JP.UTF-8"
SUPPORTED="ja_JP.UTF-8:ja_JP:ja"
SYSFONT="latarcyrheb-sun16"

# diff /etc/sysconfig/i18n /etc/sysconfig/00Backup/i18n_201205301328
1,2c1
< LANG="ja_JP.UTF-8"
< SUPPORTED="ja_JP.UTF-8:ja_JP:ja"
---
> LANG="C"
4d2
<
# shutdown -r now

再起動して日本語設定を反映させる。 ○yumリポジトリ設定

$ su -
Password: 

# yum update
# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2012-05-30 14:45:07 (20.3 KB/s) - `remi-release-6.rpm' へ保存完了 [5292/5292]

# rpm -Uvh remi-release-6.rpm
警告: remi-release-6.rpm: ヘッダ V3 DSA/SHA1 Signature, key ID 00f97f56: NOKEY

# wget http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-7.noarch.rpm
2012-05-30 14:51:39 (776 KB/s) - `epel-release-6-7.noarch.rpm' へ保存完了 [14496/14496]

[root@www11190ue ~]# perrpm -Uvh epel-release-6-7.noarch.rpm 
 パッケージ epel-release-6-7.noarch は既にインストールされています。
なんと、CentOS6.2ではyumのリポジトリにデフォルトでepelが入っている様子!

# yum install yum-priorities
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-priorities.noarch 0:1.1.30-10.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                     Arch         Version              Repository  Size
================================================================================
Installing:
 yum-plugin-priorities       noarch       1.1.30-10.el6        base        22 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 22 k
Installed size: 28 k
Is this ok [y/N]: y
Downloading Packages:
yum-plugin-priorities-1.1.30-10.el6.noarch.rpm           |  22 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.

Installed:
  yum-plugin-priorities.noarch 0:1.1.30-10.el6                                  

Complete!

# cd /etc/yum.repos.d/
# /etc/yum.repos.d/mkdir 00Backup
# cp /etc/yum.repos.d/remi.repo /etc/yum.repos.d/00Backup/remi.repo_`date +%Y%m%d%H%M `
# vi remi.repo 
恒久的にremiを使用する場合は"enabled=0"→"enabled=1"に変更する。 都度指定する場合は"yum --enablerepo=remi "とオプションを付けて利用する。 以下は恒久的にremiを利用する場合の例

# diff remi.repo 00Backup/remi.repo_201205301458 
5c5
< enabled=1
---
> enabled=0
続く

2012年1月30日月曜日

SVNでコミットエラー


どうも最近コミットがいかの様に失敗する時がある。
どうもファイルサイズが大きいと失敗しているっぽく感じる。
失敗しているときは、

数分待たされてから、こんな感じでTortoiseSVNのエラーが表示される。
Error: コミットに失敗しました (詳しい理由は以下のとおりです):  
Error: PUT (URL:  
Error:  '/kowta/!svn/wrk/229ff0d0-e078-81b9-9b42-484c97fa579a/data/Backup/kowta50020111222.hdf'):  
Error:  Could not read status line: connection was closed by server (http://svn.kowta.co.jp)  

とりあえず、当てずっぽで以下を実施。
・"httpd.conf"の"Timeout"を増やしたが、改善せず

・"httpd.conf"の"KeepAlive"を"On"にしたが、改善せず

サーバーのerror_log見るとこんなのが見つかった
Could not get next bucket brigade  [500, #0]

なんだか、クライアント側の問題っぽい?ということで、またも当てずっぽで以下を実施。

・windowsの"WebClientサービス"を停止したが、改善せず。

・TortoiseSVNの"timeout in seconds to stop the auto-completion parsing"を増やしてみたが、改善せず

・カスペルスキーインターネットセキュリティーのファイアーウォールを切ったが改善せず

・カスペルスキーインターネットセキュリティーのプロテクション(保護機能)を切ると、待ち時間が少なくたり、TortoiseSVNのエラーが以下の様に変わった。
Error: コミットに失敗しました (詳しい理由は以下のとおりです):  
Error: Cannot write to the prototype revision file of transaction '78-2' because a  
Error:  previous representation is currently being written by this process  

・カスペルスキーインターネットセキュリティーのプロテクション(保護機能)とファイアーウォールの両方を切るとコミット成功!!


ということで、カスペルスキーインターネットセキュリティー2012の設定を行う。
  1. [設定]-プロテクションの[アプリケーションコントロール]-[アプリケーション]ボタン押下
  2. "svn"で検索し[TortoiseSVN client]右クリック-[アプリケーションルール]
  3. [除外] タブの、 " アプリケーションの動作を監視しない"と " 子アプリケーションの動作を監視しない"にチェック。
  4. [OK]  [OK]  [適応]
  5. 左フレームの[詳細 ]タブ-[脅威と除外]を押下
  6. 右下の[除外 ]-[設定]を押下-[除外アプリケーション]タブ押下-[追加 ]ボタン押下-"参照 "を選択
  7. "C:\Program Files\TortoiseSVN\bin\TSVNCache.exe"を選択
  8. [除外] タブの、 " アプリケーションの動作を監視しない"と " 子アプリケーションの動作を監視しない"にチェック。
  9. [OK]  [OK]  [適応]

以上で解決と思ったが、こんどは別のサーバーにコミットしたら以下のエラー
[error] Cannot write to the prototype revision file of transaction '80-1' because a previous representation is currently being written by this process  [500, #160012]

コミットのボリュームが大きいと、10MB送信した所で、止まってるっぽい
こっちはサーバーの問題なのかな?


2012年1月26日木曜日

さくらのVPSでzabbix agentインストール



#エージェント側での作業、サーバーの時と似た内容です
[root@examsvr2 ~]# rpm -ivh http://www.zabbix.jp/binaries/relatedpkgs/rhel5/i386/zabbix-jp-release-5-5.noarch.rpm

#zabbix-jp-releaseが示すバージョンを確認
[root@examsvr2 ~]# alternatives --display zabbix-jp-release
zabbix-jp-release -ステータスは自動です。
リンクは現在 /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo を指しています。
/usr/share/zabbix-jp-release/zabbix-jp-1.1.repo - 優先項目 10
/usr/share/zabbix-jp-release/zabbix-jp-1.4.repo - 優先項目 20
/usr/share/zabbix-jp-release/zabbix-jp-1.6.repo - 優先項目 30
/usr/share/zabbix-jp-release/zabbix-jp-1.8.repo - 優先項目 40
現在の「最適」バージョンは /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo です。

#1.8なのでOK


[root@examsvr2 ~]# yum clean all

#念の為確認
[root@examsvr2 ~]# yum search zabbix

#インストール
[root@examsvr2 ~]# yum install zabbix zabbix-agent

Installed:
  zabbix.x86_64 0:1.8.10-1.el5.JP          zabbix-agent.x86_64 0:1.8.10-1.el5.JP

Complete!

#※"yum install zabbix-agent"でも"zabbix"は自動でインストールされる

#設定ファイルの編集
[root@examsvr2 ~]# cd /etc/zabbix/
[root@examsvr2 zabbix]# vi zabbix_agentd.conf

Server=100.10.1.103     <- サーバーのipを指定

Hostname=exam_zabbixagent.com     <- エージェントホストの名前を入力

ListenIP=100.10.1.102     <- "127.0.0.1"だとサーバーから見えない様子、サーバーからアクセスできるIPを指定してあげると成功!!

#※設定ファイル"zabbix_agent.conf"も有るので、間違えないように


#zabbixエージェントサービスを起動
[root@examsvr2 zabbix]# service zabbix-agent start

#iptablesに、zabbixサーバからtcp 10050ポートへの穴を開ける。
#ウチでは"iptables-init.sh"で設定してるので、これを編集する。
[root@examsvr2 ~]# cd ~
[root@examsvr2 ~]# vi iptables-init.sh

exam_zabbixserver='100.10.1.103'
iptables -A INPUT -p tcp --dport 10050 -s $exam_zabbixserver -j ACCEPT

#上記を追加する。直IP指定でも良いが、後で「このIPなんだっけ」ってなるので変数に入れる。


#設定を反映させる
[root@examsvr2 ~]# sh /root/iptables-init.sh

#設定が反映されたか確認
[root@examsvr2 ~]# iptables -L

ACCEPT     tcp  --  exam_zabbixserver.com            anywhere            tcp dpt:10050

#上記設定が入っていれば穴開け成功

#デフォルト設定に保存
[root@examsvr2 ~]# iptables-save > /etc/sysconfig/iptables

#1回再起動してみる
[root@examsvr2 ~]# /etc/init.d/iptables restart



#自動起動設定
#まずは現状確認
[root@examsvr2  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:off   3:off   4:off   5:off   6:off

#自動起動の設定
[root@examsvr2  ~]# chkconfig --level 2345 zabbix-agent on

#念のため確認
[root@examsvr2  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:on    3:on    4:on    5:on    6:off



#以上でエージェントの設定完了







#こっからサーバー側での作業


#次にサーバー側のiptablesに、zabbixエージェントからtcp 10051ポートへの穴を開ける。
#同じく"iptables-init.sh"で設定
[root@examsvr ~]# vi iptables-init.sh

exam_www='100.10.1.101'
exam_zabbixagent='100.10.1.102'

iptables -A INPUT -p tcp --dport 10051 -s $exam_www -j ACCEPT
iptables -A INPUT -p tcp --dport 10051 -s $exam_zabbixagent -j ACCEPT

#上記を追加する。※今回はエージェント2件分追加してる
#複数IPを1行で設定したかったが、iptablesにそんな機能はないらしいので、監視ホスト数分の設定が必要らしい


#設定を反映させる
[root@examsvr ~]# sh /root/iptables-init.sh

#設定が反映されたか確認
[root@examsvr ~]# iptables -L

ACCEPT     tcp  --  exam_zabbixagent.com            anywhere            tcp dpt:10051

#上記設定が入っていれば穴開け成功

#デフォルト設定に保存
[root@examsvr ~]# iptables-save > /etc/sysconfig/iptables

#1回再起動してみる
[root@examsvr ~]# /etc/init.d/iptables restart


#以上でサーバー側の穴開け完了


#サーバーからエージェントへの通信確認
[root@examsvr ~]# telnet exam_zabbixagent.com 10050

Trying 100.10.1.102...
Connected to exam_zabbixagent.com (100.10.1.102).
Escape character is '^]'.
Connection closed by foreign host.

#上記が返って来れば成功!!






#こっからエージェント側での作業

#エージェントからサーバーへの通信確認
[root@examsvr2 ~]# telnet exam_zabbixserver.com 10051
Trying 100.10.1.103...
Connected to exam_zabbixserver.com (100.10.1.103).
Escape character is '^]'.

#こんな感じなら繋がっているらしい。
exit     <- でtelnetを抜ける




あとは、サーバー側のWEB管理画面で、ホストを追加する。

・[設定]タブ-[ホスト]タブ-[ホストの作成]ボタン- 名前、IPなどを設定する。


・[リンクしているテンプレート]-[追加]ボタン押下
・[グループ]リストボックスから"templates"を選択
・[Template_Linux]をチェック-[選択]ボタン押下

・[保存]ボタン押下

とりあえずこれで、サーバー自身の初期設定とおおよそ同じホストになるっぽい。



なんだか、まだ何も設定出来ていないのだが、グラフを眺めてるだけでニヤリとしてしまう!!

2012年1月25日水曜日

さくらのVPSでzabbix サーバーインストール

ちょっと前に不正アクセス疑惑(無実でした(^^ゞ)とサーバートラブルで、コマンドからのログ解析やらバックアップやらで3徹してしまったり、サーバも増えてきたので、ようやく監視サーバーを設置することに

ちょっと調べた結果zabbixに決定、こちらを参考にインストール!!

すでに、apache php mysqlはインストール済です。


まずはインストールするOSのディストリビューションを確認
cat /etc/issue

CentOS release 5.5 (Final)


#と言う事なので、zabbixをyumでインストールする為に以下を実行する。

[root@examsvr ~]# rpm -ivh http://www.zabbix.jp/binaries/relatedpkgs/rhel5/i386/zabbix-jp-release-5-5.noarch.rpm


#yumでどのバージョンのzabbixがインストールされるかを確認する。
[root@examsvr ~]# alternatives --display zabbix-jp-release
zabbix-jp-release - status is auto.
 link currently points to /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo     <- 1.8が選ばれてるって言ってるっぽい
/usr/share/zabbix-jp-release/zabbix-jp-1.1.repo - priority 10
/usr/share/zabbix-jp-release/zabbix-jp-1.4.repo - priority 20
/usr/share/zabbix-jp-release/zabbix-jp-1.6.repo - priority 30
/usr/share/zabbix-jp-release/zabbix-jp-1.8.repo - priority 40     <- プライオリティーが一番大きい
Current `best' version is /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo.

#見た感じ1.8がインストールされるっぽい


#念の為以下を実行して、1.8を指定することも出来る。
[root@examsvr ~]# alternatives --config zabbix-jp-release
   1           /usr/share/zabbix-jp-release/zabbix-jp-1.1.repo
   2           /usr/share/zabbix-jp-release/zabbix-jp-1.4.repo
   3           /usr/share/zabbix-jp-release/zabbix-jp-1.6.repo
*+ 4           /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo     <- 1.8を選択する

#以上でzabbix1.8をyumでインストールする準備が出来たらしいので次に進む


[root@examsvr ~]# yum clean all

#一応確認
[root@examsvr ~]# yum search zabbix

[root@examsvr ~]# yum install zabbix zabbix-agent zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql
#"Complete!"が出れば成功!!

[root@examsvr ~]# vi /etc/my.cnf

default-character-set=utf8     <- 追加
# skip-character-set-client-handshake     <- ホントはこれも追加するが、mysqlがエラーになるのでコメントアウト。

#上の行を"[mysqld_safe]"より前の行に追加する。

#mysqlを再起動
[root@examsvr ~]# /etc/init.d/mysqld restart

#DB作成
[root@examsvr ~]# mysqladmin -uroot -p create zabbix --default-character-set=utf8


#zabbix用mysqlユーザ作成
[root@examsvr ~]# mysql -uroot -p
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'hogehoge';
mysql> flush privileges;
mysql> quit


#zabbix用初期データ入力
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/schema/mysql.sql
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/data/data.sql
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/data/images_mysql.sql

[root@examsvr ~]# cd /etc/zabbix/
[root@examsvr zabbix]# vi zabbix.conf.php

##"http://exam.com/zabbix"などではなく、"http://zabbix.exam.com"でアクセスするためにバーチャルホスト設定
[root@examsvr zabbix]# cd /etc/httpd/conf.d/
[root@examsvr conf.d]# vi zabbix.conf

# Alias /zabbix /usr/share/zabbix

#"Alias /zabbix /usr/share/zabbix"をコメントアウト


[root@examsvr conf.d]# vi virtualhost.conf

<VirtualHost *:80>
    ServerName zabbix.exam.com
    DocumentRoot /usr/share/zabbix
    <IfModule mod_ssl.c>
        SSLEngine off
    </IfModule>
        <Location />
                AuthType Basic
                AuthName "zabbix basic"
                AuthUserFile /etc/httpd/conf/svn_auth_file
                Require valid-user
        </Location>
</VirtualHost>

#上記を追加する。


#zabbixのコンフィつファイルをapacheで更新できるようにする。
[root@examsvr conf.d]# chown apache.apache /usr/share/zabbix/conf/zabbix.conf.php

#apache再起動。
[root@examsvr conf]# /etc/init.d/httpd restart


"http://zabbix.exam.com"にアクセスして見ると順調な様子!!
こちらを参考にながれで初期設定する。


#初期設定で、rootでmysqlにアクセスするように設定してしまったので設定変更。
[root@examsvr conf]# cd /etc/zabbix/
[root@examsvr zabbix]# vi zabbix.conf.php

$DB["USER"]                             = 'zabbix';
$DB["PASSWORD"]                 = 'hogehoge';


[root@examsvr zabbix]# vi zabbix_server.conf

DBUser=zabbix     <- データベースユーザ名を設定
DBPassword=zabbix     <- コメントアウトを外してデータベースパスワードを設定
DBSocket=/var/lib/mysql/mysql.sock     <- コメントアウトを外す

#これでサーバー起動
[root@examsvr zabbix]# service zabbix-server start


[root@examsvr zabbix]# vi zabbix_agentd.conf

Server=127.0.0.1     <- ZABBIXサーバのIPアドレスを設定
Hostname=ZABBIX Server     <- Webインターフェースのホスト設定で登録するホスト名と同じ値を設定
ListenIP=127.0.0.1     <- ListenするIPインターフェースを設定

#これでクライアントが起動するので、自分を監視できる。
[root@examsvr zabbix]# service zabbix-agent start



#自動起動設定
#まずは現状確認
[root@examsvr  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:off   3:off   4:off   5:off   6:off
zabbix-server   0:off   1:off   2:off   3:off   4:off   5:off   6:off

#自動起動の設定
[root@examsvr  ~]# chkconfig --level 2345 zabbix-agent on
[root@examsvr  ~]# chkconfig --level 2345 zabbix-server on

#念のため確認
[root@examsvr  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:on    3:on    4:on    5:on    6:off
zabbix-server   0:off   1:off   2:on    3:on    4:on    5:on    6:off



まずは、自分を監視しながらいじってみるかな。

2012年1月5日木曜日

let'snote cf-y7cw5axsのバックライト交換


以前let'snote cf-y7cw5axs の液晶分解修理で説明したが、
写真入りでもう少し詳しく書いてみる。


○画面部分の構造


  • マグネシウム製の天板裏側
天板にはヒンジのネジ穴と、画面を閉じた時にロックするラッチが有るのみ、非常にシンプル。




天板側に爪のメス側の溝が外周部分にある、この位置を頭に入れて分解作業を進めないと、破損させやすいだろう。





  • プラスチック製の画面枠と液晶パネル


液晶パネルとインバーターは、両面テープで接着されている。




○画面部分の分解
液晶の交換は、本体側の分解の必要はなかった、手順は以下のとおり。

1.ヒンジ部分のネジ4本を外す。
2.マグネシウムの天板を外すのだが、ここは難易度が高い

液晶枠のプラスチックカバーが四方から天板に覆いかぶさるように取り付けられているが、けっこうキツメにはまっている

天板と液晶枠の隙間に間に爪楊枝などを複数滑り込ませながら少しずつ爪を外していく、この時なるべく液晶パネルに力を加えないように慎重に行う。
左右のヒンジ部分から初めて、ラッチ側を最後に外すようにすると良いだろう。


○バックライトの交換
分解して冷陰極管を交換する事も不可能ではないが、難易度が非常に高い。
画面枠と液晶パネルユニットが両面テープなどで強固に固定されていることや、
液晶パネルユニットの分解は、交換後の組み立て時にホコリの侵入など完全に元通りにするのは至難の業、色ムラ、バックライトの明るさムラが出てくる可能性が高いだろう。

ということで、今回は液晶ユニットを分解しないまま冷陰極管を交換する、やり方は以下のとおり。

  • 液晶ユニットベースの白い樹脂部品の、一部(写真青枠)をニッパーなどで、切り取る。

これにより、冷陰極管を横にスライドして取り外せ、ゴムカバーの取り外しも容易になる。

  • 冷陰極管端子の絶縁と固定をしているゴム製のカバーを外す。
  • インバーター と冷陰極管端子との 配線を ハンダコテで外す。
  • 新しい冷陰極管を横にスライドして交換する。※ゴムの輪っかの取り付けも忘れずに!
  • 後は、元通りに組み立て終了






写真は作業後の状態で、青で囲った部分がニッパで切り取った部分です。
冷陰極管端子を絶縁し固定の役割もしているゴム?シリコン? 製のカバー、及びインバーターからの配線も外している状況です。
赤矢印の先が冷陰極管端子です。


  • 今回交換した冷陰極管の寸法


全長:299mm
管長:296mm
管直径:Φ2.0mm




viで文字コード変換

viコマンドモードで以下を実行
:setlocal fileencoding=sjis

後は保存すれば、設定した文字コードで保存される。
:w sjisfile.txt


ちなみに、設定する主な文字コードは、以下の通り。

euc-jp
sjis
utf-8
iso-2022-jp (日本語電子メールで多く使われていた文字コード)

viで日本語表示2


viで日本語表示で設定したが、まだviで文字化けしてる。

以下をviコマンドモードで実行して確認する。
:set encoding

【結果】
encoding=utf-8
"utf-8"なので問題なし。

次にで以下を実行。

:set fileencoding

【結果】
fileencoding=latin1

UTF-8で読み込まれてない様子。

次にで以下を実行。
:set fileencodings


【結果】
fileencodings=ucs-bom,utf-8,default,latin1
後ろの設定から順に読み込みを試みるらしく、"latin1"で成功して読み込まれている様子。

以下で".vimrc"を確認する。
cat ~/.vimrc

"set fileencodings"の記述が無いので以下を実行。
echo "set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8" >> ~/.vimrc


再度viでファイルを開いたら、文字化けしないで開けた(^^)
念のため、以下をviコマンドモードで実行して確認する。
:set encoding
【結果】

fileencoding=utf-8

ちゃんと"utf-8"になってる。

以上で解決!!


ちなみに、以下でも大丈夫っぽい
  • :set enc
  • :set fenc
  • :set fencs