PHP-Driver DataStax Cassandra DB - 如何使用?
PHP-Driver DataStax Cassandra DB - How to use?
我完成的安装过程如下:
系统
PHP 7.0.5-1~dotdeb+8.1 (cli) ( NTS )
Debian 8
Nginx 1.8.1
Laravel 5.2
Java 安装
mkdir -p /usr/lib/jvm
wget URL to Oraclesite
mv mv jdk-8u77-linux-x64.tar.gz\?... jdk-8u77-linux-x64.tar.gz
tar xzf jdk-8u77-linux-x64.tar.gz
rm jdk-8u77-linux-x64.tar.gz
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1
update-alternatives --set java /usr/lib/jvm/jdk1.8.0_version/bin/java
安装需要的包
apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev
Libuv 安装
cd /tmp
wget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gz
tar xzf libuv-v1.7.5.tar.gz
rm libuv-v1.9.0.tar.gz
cd libuv-v1.7.5
sh autogen.sh
./configure
make
make install
ldconfig
安装 Cassandra Datatrax
echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt install cassandra dsc30
检查服务
service cassandra status
cassandra.service - LSB: distributed storage system for structured
data Loaded: loaded (/etc/init.d/cassandra) Active: active
(running) since Mon 2016-04-11 01:11:04 CEST; 19min ago Process: 506
ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/cassandra.service
nodetool status
Datacenter: datacenter1
======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca-de58dc88e318 rack1
cqlsh
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra
3.0.4 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
安装php-驱动
(PECL 安装不工作。我认为这是因为只有 php7 个设置)
git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
cd ext
./install.sh
make test -> all tests passed
将驱动程序添加到 PHP 扩展程序
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/cli/php.ini
// UPDATE - added extension to fpm/php.ini file.
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
重启nginx和php7.0-fpm
service nginx restart
service php7.0-fpm restart
问题:
如果我想使用下面的代码,它会提示我 class 找不到 Cassandra。
网页:https://github.com/datastax/php-driver#datastax-php-driver-for-apache-cassandra
$cluster = Cassandra::cluster()->build();
感谢您的帮助。
由于您正在尝试使用 nginx+fpm 执行 PHP 脚本,因此您需要更新相应的 php.ini 文件(例如 /etc/php7/fpm/php.ini
)。
将驱动模块添加到您的 nginx+fpm 安装中
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
为确保通过 CLI 正确加载驱动程序,您可以执行以下操作:
php -m | grep cassandra
或
php -i | grep -A 10 "^cassandra$"
php -m
将打印出 PHP 能够加载的所有 extension/modules 而 php -i
将显示有关 PHP 安装配置的更多详细信息.
更新 1
当我执行以下2条命令时,我得到了以下两个结果,看起来很成功。
php-m | grep 卡桑德拉
cassandra
php-i | grep -A 10 "^cassandra$"
cassandra
Cassandra support => enabled C/C++ driver version => 2.2.2 Persistent
Clusters => 0 Persistent Sessions => 0
Directive => Local Value => Master Value cassandra.log =>
cassandra.log => cassandra.log cassandra.log_level => ERROR => ERROR
但还是报错class Cassandra.
更新 2
一切正常。
php > $cluster = Cassandra::cluster()->build();
php > var_dump($cluster);
object(Cassandra\DefaultCluster)#2 (0) { }
php >
我完成的安装过程如下:
系统
PHP 7.0.5-1~dotdeb+8.1 (cli) ( NTS )
Debian 8
Nginx 1.8.1
Laravel 5.2
Java 安装
mkdir -p /usr/lib/jvm
wget URL to Oraclesite
mv mv jdk-8u77-linux-x64.tar.gz\?... jdk-8u77-linux-x64.tar.gz
tar xzf jdk-8u77-linux-x64.tar.gz
rm jdk-8u77-linux-x64.tar.gz
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1
update-alternatives --set java /usr/lib/jvm/jdk1.8.0_version/bin/java
安装需要的包
apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev
Libuv 安装
cd /tmp
wget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gz
tar xzf libuv-v1.7.5.tar.gz
rm libuv-v1.9.0.tar.gz
cd libuv-v1.7.5
sh autogen.sh
./configure
make
make install
ldconfig
安装 Cassandra Datatrax
echo "deb http://debian.datastax.com/community stable main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -
apt install cassandra dsc30
检查服务
service cassandra status
cassandra.service - LSB: distributed storage system for structured data Loaded: loaded (/etc/init.d/cassandra) Active: active (running) since Mon 2016-04-11 01:11:04 CEST; 19min ago Process: 506 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS) CGroup: /system.slice/cassandra.service
nodetool status
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca-de58dc88e318 rack1
cqlsh
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.0.4 | CQL spec 3.4.0 | Native protocol v4] Use HELP for help.
安装php-驱动 (PECL 安装不工作。我认为这是因为只有 php7 个设置)
git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
cd ext
./install.sh
make test -> all tests passed
将驱动程序添加到 PHP 扩展程序
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/cli/php.ini
// UPDATE - added extension to fpm/php.ini file.
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
重启nginx和php7.0-fpm
service nginx restart
service php7.0-fpm restart
问题:
如果我想使用下面的代码,它会提示我 class 找不到 Cassandra。 网页:https://github.com/datastax/php-driver#datastax-php-driver-for-apache-cassandra
$cluster = Cassandra::cluster()->build();
感谢您的帮助。
由于您正在尝试使用 nginx+fpm 执行 PHP 脚本,因此您需要更新相应的 php.ini 文件(例如 /etc/php7/fpm/php.ini
)。
将驱动模块添加到您的 nginx+fpm 安装中
echo -e "; DataStax PHP Driver\nextension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
为确保通过 CLI 正确加载驱动程序,您可以执行以下操作:
php -m | grep cassandra
或
php -i | grep -A 10 "^cassandra$"
php -m
将打印出 PHP 能够加载的所有 extension/modules 而 php -i
将显示有关 PHP 安装配置的更多详细信息.
更新 1
当我执行以下2条命令时,我得到了以下两个结果,看起来很成功。
php-m | grep 卡桑德拉
cassandra
php-i | grep -A 10 "^cassandra$"
cassandra
Cassandra support => enabled C/C++ driver version => 2.2.2 Persistent Clusters => 0 Persistent Sessions => 0
Directive => Local Value => Master Value cassandra.log => cassandra.log => cassandra.log cassandra.log_level => ERROR => ERROR
但还是报错class Cassandra.
更新 2
一切正常。
php > $cluster = Cassandra::cluster()->build();
php > var_dump($cluster);
object(Cassandra\DefaultCluster)#2 (0) { }
php >