2014年1月17日 星期五

Cassandra +PHP Using Thrift

直接下載 Cassandra-PHP-Client-Library
解壓縮至Apache的網頁路徑即可使用
http://cassandra-php-client-library.com/download
Git

下面是自己 Build 的


$ cd ~/thrift //移動到Thrift 路徑
$ sudo apt-get install libboost-dev automake libtool flex bison pkg-config g++
$ ./configure

之後他會對系統安裝的程式做確認

checking for a Python interpreter with version >= 2.4... python
checking for python... /usr/bin/python
checking for python version... 2.7
....etc
如果沒有請依照顯示的錯誤訊息去找需要的安裝
如果想要省略C++可以使用如下方法
$ ./configure -with-cpp=no
$ make
$ ./compiler/cpp/thrift -gen php ~/cassandra/interface/cassandra.thrift
$ sudo mkdir -p /usr/share/php/Thrift
$ sudo cp -R gen-php/ /usr/share/php/Thrift/packages/
$ sudo cp -R lib/php/src/* /usr/share/php/Thrift/

$ cd ~/thrift/lib/php/src/ext/thrift_protocol
$ sudo apt-get install php5-dev
$ phpize
$ ./configure --enabke-thrift_protocol
$ make

如果編譯錯誤少了config.m4
複製下面文字並新增config.m4檔案到 ~/thrift/lib/php/src/ext/thrift_protocol 目錄底下
dnl Copyright (C) 2009 Facebook
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty provided the copyright
dnl notice and this notice are preserved.

PHP_ARG_ENABLE(thrift_protocol, whether to enable the thrift_protocol extension,
[ --enable-thrift_protocol Enable the fbthrift_protocol extension])

if test "$PHP_THRIFT_PROTOCOL" != "no"; then
PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY_WITH_PATH(stdc++, "", THRIFT_PROTOCOL_SHARED_LIBADD)
PHP_SUBST(THRIFT_PROTOCOL_SHARED_LIBADD)
PHP_NEW_EXTENSION(thrift_protocol, php_thrift_protocol.cpp, $ext_shared)
fi
Reference

Ubuntu 12.04 Cassandra install

Step 0: 相關軟體
作業系統:ubuntu 12.04
JVM:JDK7 (新版 Cassandra 要求需要 Java 7 以上)

Step 1: 下載解壓縮包裝

$ cd ~/temp/
$ wget http://www.us.apache.org/dist/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz(修改需求版本)
$ tar -xvzf apache-cassandra-2.0.4-bin.tar.gz (解壓縮)
$ mv apache-cassandra-2.0.4-bin.tar.gz ~/cassandra (移動到需要的路徑 )

Step 2: 相關設置

以下為Cassandra 預設的 log 寫檔位置 請注意是否能允許寫入

$ sudo mkdir /var/log/cassandra
$ sudo mkdir /var/lib/cassandra

$ sudo chown -R $USER:$GROUP  /var/log/cassandra
$ sudo chown -R $USER:$GROUP  /var/lib/cassandra

如果要修改寫入位置
$  vi ~/cassandra/conf/log4j-server.properies
修改成需要的路徑
log4j.appender.R.File=/Custom Path/system.log

Step 3: 啟動 Cassandra

$  cd ~/cassandra
$ ./bin/cassandra -f (注意看是否有錯誤訊息)

Step 4: CQL使用

$ ./bin/cqlsh

成功連接會看到下面訊息

Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.0 | Cassandra 2.0.4 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>







2014年1月13日 星期一

Apache httpd Piped Logs

Piped Logs Apache httpd is capable of writing error and access log files through a pipe to another process, rather than directly to a file. This capability dramatically increases the flexibility of logging, without adding code to the main server. In order to write logs to a pipe, simply replace the filename with the pipe character "|", followed by the name of the executable which should accept log entries on its standard input. Apache will start the piped-log process when the server starts, and will restart it if it crashes while the server is running. (This last feature is why we can refer to this technique as "reliable piped logging".) Piped log processes are spawned by the parent Apache httpd process, and inherit the userid of that process. This means that piped log programs usually run as root. It is therefore very important to keep the programs simple and secure. One important use of piped logs is to allow log rotation without having to restart the server. The Apache HTTP Server includes a simple program called rotatelogs for this purpose. For example, to rotate the logs every 24 hours, you can use: CustomLog "|/usr/local/apache/bin/rotatelogs /var/log/access_log 86400" common A similar, but much more flexible log rotation program called cronolog is available at an external site. As with conditional logging, piped logs are a very powerful tool, but they should not be used where a simpler solution like off-line post-processing is available.

搜尋此網誌