{ Pattern }

Pattern Ref —自分用覚書

phpライブラリmemcache

11 月 4th, 2009
Posted by yref
未分類
Comments Off

[root@localhost memcached]# pecl install memcache

[root@localhost memcached]# ls /usr/lib/php/modules/

[root@localhost memcached]# ls /etc/php.d/

[root@localhost memcached]# vi /etc/php.d/memcache.ini
; Enable memcache extension module
extension=memcache.so

[root@localhost memcached]# /etc/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]

★テストphp

<?php

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");

echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
?>

キャッシュサーバmemcached

11 月 1st, 2009
Posted by yref
未分類

memcachedは高性能な分散メモリキャッシュサーバです。

参考:

参考:クライアントライブラリ

監視ツール

[root@localhost ~]# /usr/local/src/memcached-1.4.2/scripts/memcached-tool

■アーカイブをget
[root@localhost src]# wget http://memcached.googlecode.com/files/memcached-1.4.2.tar.gz

[root@localhost src]# tar zxvf memcached-1.4.2.tar.gz
[root@localhost src]# cd memcached-1.4.2
[root@localhost memcached-1.4.2]# ./configure
If it's already installed, specify its path using --with-libevent=/dir/

★libeventのパスを指定しろと言われる。

[root@localhost memcached-1.4.2]# rpm -qa libevent
libevent-1.1a-3.2.1

★libeventはインストールされているのに。。。

■libevent-develをインストール
[root@localhost memcached-1.4.2]# yum install -y libevent-devel.i386
Installing : libevent-devel [1/1]


Installed: libevent-devel.i386 0:1.1a-3.2.1
Complete!

■改めてconfigure・インストール
[root@localhost memcached-1.4.2]# ./configure
[root@localhost memcached-1.4.2]# make
[root@localhost memcached-1.4.2]# make install


■起動
[root@localhost memcached-1.4.2]# memcached -d -m 1024 -l 127.0.0.1 -p 11211 -u nobody
※rootでは起動できないので、-u nobody で起動。
あるいは、専用ユーザ作る?

■接続
[root@localhost memcached-1.4.2]# telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
stats
STAT pid 7926
STAT uptime 209
STAT time 1256799888
STAT version 1.4.2
STAT pointer_size 32
STAT rusage_user 0.000000
STAT rusage_system 0.005999
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 1073741824
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
END


試しに
★試しに、「123」を格納してみる
<コマンド> <キー> <圧縮フラグ(1 or 0)> <有効期間(単位:秒)> <サイズ(単位:Bytes)>
例) 「foo」というキーに「123」という3バイトのデータを非圧縮(0)/無期限(0)で格納する
・・・引用参考:Life with IT

set foo 0 0 3
123
STORED

★読み込んでみる
get foo
VALUE foo 0 3
123
END


quit
Connection closed by foreign host.

■起動スクリプトを作成
★/etc/sysconfig/memcached 確認
★なれけば作る。

[root@localhost ~]# ls -l /etc/sysconfig/memcached
-rw-r--r-- 1 root root 68 9月 11 2008 /etc/sysconfig/memcached

[root@localhost ~]# vi /etc/sysconfig/memcached

####[root@localhost ~]# cat /etc/sysconfig/memcached
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="128"
OPTIONS=""

■inid確認
★あれば上書き
[root@localhost ~]# ls -l /etc/rc.d/init.d/memcached
-rwxr-xr-x 1 root root 1334 9月 11 2008 /etc/rc.d/init.d/memcached

[root@localhost ~]# vi /etc/rc.d/init.d/memcached
#!/bin/bash
#
# Init file for memcached
#
# Written by Dag Wieers
#
# chkconfig: - 80 12
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached
# config: /etc/memcached.conf

source /etc/rc.d/init.d/functions

### Default variables
PORT="11211"
USER="nobody"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
SYSCONFIG="/etc/sysconfig/memcached"
DST_BIN="/usr/local/bin/memcached"

### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="memcached"
desc="Distributed memory caching"

start() {
echo -n $"Starting $desc ($prog): "
daemon $DST_BIN -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}

stop() {
echo -n $"Shutting down $desc ($prog): "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}

restart() {
stop
start
}

reload() {
echo -n $"Reloading $desc ($prog): "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
reload)
reload
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac

exit $RETVAL
[root@localhost ~]#

■chkconfigに登録

[root@localhost ~]# chkconfig --add memcached
[root@localhost ~]# chkconfig --list memcached
[root@localhost ~]# chkconfig memcached on

サーバ監視ツール nagios

11 月 1st, 2009
Posted by yref
未分類

参考

■gdのインストール

[root@localhost src]# yum -y install gd gd-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
* addons: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
Setting up Install Process
Parsing package install arguments
Package gd-2.0.33-9.4.el5_1.1.i386 already installed and latest version
Package gd-devel-2.0.33-9.4.el5_1.1.i386 already installed and latest version
Nothing to do


■ユーザー作成 nagios:******
[root@localhost src]# useradd -m nagios
[root@localhost src]# passwd nagios
Changing password for user nagios.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.


■グループ作成
[root@localhost src]# groupadd nagcmd

■グループにユーザ追加
[root@localhost src]# usermod -a -G nagcmd nagios
[root@localhost src]# usermod -a -G nagcmd apache
[root@localhost src]# usermod -a -G nagcmd vivi


■ベーシック認証用のパスワードファイルを作成
[root@localhost src]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
(パスワードを聞かれるので入力をする。)


■nagios本体とプラグインをダウンロード
[root@localhost src]# wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz/d
ownload


[root@localhost src]# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.t
ar.gz/download

[root@localhost src]# tar zxvf nagios-3.2.0.tar.gz

[root@localhost src]# cd nagios-3.2.0

■日本語化
[root@localhost nagios-3.2.0]# wget http://sourceforge.jp/projects/nagios-jp/downloads/38828/nagios-3.1.0-ja-utf8.pat
ch.gz/
★getできなかったので/tmpにローカルからコピー
[root@localhost nagios-3.2.0]# cp /tmp/nagios-3.1.0-ja-utf8.patch.gz .
★パッチを当てる
[root@localhost nagios-3.2.0]# gzip -dc nagios-3.1.0-ja-utf8.patch.gz |patch -p0


■インストール

[root@localhost nagios-3.2.0]# ./configure --with-command-group=nagcmd


[root@localhost nagios-3.2.0]# make all
・・・・・
make install
- This installs the main program, CGIs, and HTML files

make install-init
- This installs the init script in /etc/rc.d/init.d

make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file

make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!

make install-webconf
- This installs the Apache config file for the Nagios
web interface

[root@localhost nagios-3.2.0]# make install
[root@localhost nagios-3.2.0]# make install-init
[root@localhost nagios-3.2.0]# make install-commandmode
[root@localhost nagios-3.2.0]# make install-config
[root@localhost nagios-3.2.0]# make install-webconf

■さざなみフォント(日本語化に必要)
[root@localhost nagios-3.2.0]# tar jxvf /tmp/sazanami-20040629.tar.bz2
★FONTディレクトリを作成
[root@localhost nagios-3.2.0]# mkdir /usr/local/nagios/etc/font
★フォントをコピー
[root@localhost nagios-3.2.0]# cp sazanami-20040629/sazanami-gothic.ttf /usr/local/nagios/etc/font/font.ttf


■プラグインのインストール

[root@localhost nagios-3.2.0]# cd ../
[root@localhost src]# tar zxvf nagios-plugins-1.4.14.tar.gz
[root@localhost src]# cd nagios-plugins-1.4.14
[root@localhost nagios-plugins-1.4.14]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@localhost nagios-plugins-1.4.14]# make
・・・
dynamic -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -lmygcc -lpthread -ldl
gcc -I/usr/include/mysql -g -pipe -m32 -DNP_VERSION=\"1.4.14\" -g -O2 -o check_mysql check_mysql-check_mysql.o netutils.o utils.o -rdynamic -L/usr/local/src/nagios-plugins-1.4.14/plugins ../lib/libnagiosplug.a ../gl/libgnu.a -lresolv -L/usr/lib/mysql /usr/lib/mysql/libmysqlclient.so /usr/lib/mysql/libz.a -lcrypt -lnsl -lm -lmygcc -lpthread -ldl -Wl,--rpath -Wl,/usr/lib/mysql -Wl,--rpath -Wl,/usr/lib/mysql
gcc: /usr/lib/mysql/libmysqlclient.so: No such file or directory
make[2]: *** [check_mysql] エラー 1
make[2]: ディレクトリ `/usr/local/src/nagios-plugins-1.4.14/plugins' から出ます
make[1]: *** [all-recursive] エラー 1
make[1]: ディレクトリ `/usr/local/src/nagios-plugins-1.4.14' から出ます
make: *** [all] エラー 2

★mysqlのlibmysqlclient.soがないと怒られる。
⇒参考 http://plaza.rakuten.co.jp/gontata/diary/200904130000/

はまったことその3
現象:tritonn(MySQL)をrpmからインストールした場合に、PHPのmakeが失敗する。
「/usr/lib64/mysql/libmysqlclient.so」が見つからないというエラー。

解決方法:シンボリックリンクを張る
ln -s /usr/lib64/libmysqlclient.so.15.0.0 /usr/lib64/mysql/libmysqlclient.so
ln -s /usr/lib64/libmysqlclient_r.so.15.0.0 /usr/lib64/mysql/libmysqlclient_r.so

★tritonのせいらしい。
■参考にしてリンクをはる。
[root@localhost nagios-plugins-1.4.14]# ln -s /usr/lib/libmysqlclient.so.15.0.0 /usr/lib/mysql/libmysqlclient.so
[root@localhost nagios-plugins-1.4.14]# ln -s /usr/lib/libmysqlclient_r.so.15.0.0 /usr/lib/mysql/libmysqlclient_r.so


■再度make

[root@localhost nagios-plugins-1.4.14]# make
[root@localhost nagios-plugins-1.4.14]# make install


■確認
[root@localhost nagios-plugins-1.4.14]# ls /usr/local/nagios/libexec/
check_apt check_dummy check_ircd check_mysql_query check_overcr check_spop negate
check_breeze check_file_age check_jabber check_nagios check_pgsql check_ssh urlize
check_by_ssh check_flexlm check_ldap check_nntp check_ping check_ssmtp utils.pm
check_clamd check_ftp check_ldaps check_nntps check_pop check_swap utils.sh
check_cluster check_http check_load check_nt check_procs check_tcp
check_dhcp check_icmp check_log check_ntp check_real check_time
check_dig check_ide_smart check_mailq check_ntp_peer check_rpc check_udp
check_disk check_ifoperstatus check_mrtg check_ntp_time check_sensors check_ups
check_disk_smb check_ifstatus check_mrtgtraf check_nwstat check_simap check_users
check_dns check_imap check_mysql check_oracle check_smtp check_wave


■メモリチェックプラグインインストール http://centossrv.com/nagios.shtml
[root@localhost nagios-plugins-1.4.14]# vi /usr/local/nagios/etc/nagios.cfg

cfg_dir=/usr/local/nagios/etc/servers ★コメントアウト
date_format=iso8601

■設定ファイル編集 http://centossrv.com/nagios.shtml
cfg_dir=/usr/local/nagios/etc/servers ★コメントアウト
date_format=iso8601


■cgi.cfg編集 http://centossrv.com/nagios.shtml
[root@localhost nagios-plugins-1.4.14]# vi /usr/local/nagios/etc/cgi.cfg
ttf_file=/usr/local/nagios/etc/font/font.ttf ★コメントアウト


■ サーバー監視設定ファイル格納ディレクトリ作成 http://centossrv.com/nagios.shtml
[root@localhost nagios-plugins-1.4.14]# mkdir /usr/local/nagios/etc/servers


■contacts.cfg編集
email ****@gmail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******


■commands.cfg編集 http://centossrv.com/nagios.shtml

★| /usr/bin/nkf -j を追記
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOS
TNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/nkf
-j
| /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService:
$SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAddi
tional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/nkf -j | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$
SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$


■apache設定
★とくになし
★会社では、 http://centossrv.com/nagios.shtmlを参考がよいかも


■構文チェック

[root@localhost nagios-plugins-1.4.14]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check



■apache再起動

■起動設定
[root@localhost nagios-plugins-1.4.14]# /etc/init.d/nagios start
Starting nagios: done.
[root@localhost nagios-plugins-1.4.14]# chkconfig --add nagios
[root@localhost nagios-plugins-1.4.14]# chkconfig nagios on


■アクセス

http://アドレス/nagios/

ユーザ:nagiosadmin
パス:■ベーシック認証用のパスワードで設定したもの(limixweb)

パーツ開発Memo: 【EXT JS】TabPanelの内容をAJAXで表示

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

パーツ開発Memo: 【EXT JS】TabPanelの内容をAJAXで表示

2008年4月8日【EXT JS】TabPanelの内容をAJAXで表示TabPanelのタブをクリックすると、処理が実行させることを考える。 これもsampleがあるのでそのまま使えばよいが、再確認の意味でほんの少しだけ変えてテストする。 タブを切り替えるとその部分のテキストをサーバーから取ってくるというアプリはあまり思いつかないが、いろいろテストしておけばいつか使えるだろう。 [DEMO]...

【EXT JS】TabPanelの内容をAJAXで表示 はてなブックマークに追加

yref yref

【Template-Toolkit】で[FOREACH]の繰り返し回数を取得する|Perlプログラムメモ|プログラムメモ

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

【Template-Toolkit】で[FOREACH]の繰り返し回数を取得する|Perlプログラムメモ|プログラムメモ

Template-Toolkit(以下TT)での 一般的なループのさせ方は ======================================== [%FOREACH value=loop%]  名前は:[%value.name%]です。 [%END%] ======================================== このループのループ回数を利用して何か処理をしたい場合...

はてなブックマーク - 【Template-Toolkit】で[FOREACH]の繰り返し回数を取得する|Perlプログラムメモ|プログラムメモ はてなブックマークに追加

yref yref ,

PDOの各種FETCHパラメータ - PHP::PEAR - dozo PukiWiki

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

PDOの各種FETCHパラメータ - PHP::PEAR - dozo PukiWiki

PDOの各種FETCHパラメータ †PDORowオブジェクトを使用 FETCH_LAZY ハッシュを使用 FETCH_ASSOC 重複カラム回避 FETCH_NAMED 配列を使用 FETCH_NUM ハッシュ及び配列を使用 FETCH_BOTH stdClassを使用 FETCH_OBJ 使用クラス指定 FETCH_CLASS↑概要 †PDOはPEAR::DBのC言語化(PEC...

PEAR - dozo PukiWiki はてなブックマークに追加

yref yref ,

code:x - Ext 3.0 - API Documentation 日本語版 公開

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

code:x - Ext 3.0 - API Documentation 日本語版 公開

PHP/JavaScript/Ext JS/ActionScript Code Memoども、小堤です。やっと、公開できました。お知らせします。コミュニティは、Ext JS Forumを使用します。ご活用ください。Ext 3.0 - API Documentation 日本語版http://extdocs.xenophy.com/ Ext JS Forumhttp://www.extj...

x - Ext 3.0 - API Documentation 日本語版 公開 はてなブックマークに追加

yref yref

2008-02-16 - zorioの日記

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

2008-02-16 - zorioの日記

詳しくは、公式のチュートリアルを参照。http://extjs.com/learn/Tutorial:Extending_Ext_Classhttp://extjs.com/learn/Tutorial:Extending_Ext2_Class 実例こんな風に書く。//親クラスのコンストラクタvar SuperClass = function(){Ext.log('SuperClass is...

はてなブックマーク - 2008-02-16 - zorioの日記 はてなブックマークに追加

yref yref

[perl]変数名に変数を使う « @猫目

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

[perl]変数名に変数を使う « @猫目

for($I = 0; $I で $test0 = 0; $test1 = 1; $test2 = 2; $test3 = 3; $test4 = 4; と同じになるまた $txt = “答えは”; print “${txt}0″; で出力結果が 「答えは0」となる。 print “$txt0″ では $txtではなく$txt0という名前の変数が参照されてしまう 明...

はてなブックマーク - [perl]変数名に変数を使う « @猫目 はてなブックマークに追加

yref yref ,

漢(オトコ)のコンピュータ道: なぜMySQLのサブクエリは遅いのか。

10 月 19th, 2009
Posted by yref
BookMarks
Comments Off

漢(オトコ)のコンピュータ道: なぜMySQLのサブクエリは遅いのか。

2009-03-25なぜMySQLのサブクエリは遅いのか。よくMySQLはサブクエリが弱いと言われるが、これは本当だろうか?半分は本当で半分は嘘である。MySQLのサブクエリだってなんでもかんでも遅いわけではない。落とし穴をしっかり避け、使いどころを間違えなければサブクエリも高速に実行できるのである。今日はMySQLがどんな風にサブクエリを実行し、どのような場合に遅いのかということについて説明...

なぜMySQLのサブクエリは遅いのか。 はてなブックマークに追加

yref yref

Next Page »

Your Own Photos Or Artwork

This is just a sample.....260 X 100

  • sample1
  • sample1
  • sample1
ホットワード 自分 備忘録 分類 httpd
割引クーポンまとめ情報 - クー割