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/jvmwget 到 Oracle 站点的 URLmv mv jdk-8u77-linux-x64.tar.gz?... jdk-8u77-linux-x64.tar.gztar xzf jdk-8u77-linux-x64.tar.gzrm jdk-8u77-linux-x64.tar.gzupdate-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1update-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/tmpwget http://dist.libuv.org/dist/v1.7.5/libuv-v1.7.5.tar.gztar xzf libuv-v1.7.5.tar.gzrm libuv-v1.9.0.tar.gzcd libuv-v1.7.5sh autogen.sh./配置制作进行安装配置文件
安装 Cassandra Datatrax
echo "deb http://debian.datastax.com/community stable main" |sudo tee -a/etc/apt/sources.list.d/cassandra.sources.listcurl -L http://debian.datastax.com/debian/repo_key |sudo apt-key 添加 -安装 cassandra dsc30
检查服务
服务卡桑德拉状态
<块引用>
cassandra.service - LSB:结构化的分布式存储系统数据加载:加载(/etc/init.d/cassandra)活动:活动(运行)自 2016 年 4 月 11 日星期一 01:11:04 CEST 起;19 分钟前 进程:506ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS)CGroup:/system.slice/cassandra.service
nodetool 状态
<块引用>
数据中心:datacenter1=======================状态=上/下|/状态=正常/离开/加入/移动-- 地址加载令牌拥有(有效)主机 ID 机架 UN 127.0.0.1 139.06 KB 256 100.0%
1ab0e99a-41a5-4007-b9ca-de58dc88e318 机架1
cqlsh
<块引用>
在 127.0.0.1:9042 连接到测试集群.[cqlsh 5.0.1 |卡桑德拉3.0.4 |CQL 规范 3.4.0 |本机协议 v4]使用 HELP 寻求帮助.
安装php-driver(PECL 安装不起作用.我认为这是因为只有 php7 设置)
git clone https://github.com/datastax/php-driver.gitcd php 驱动程序git子模块更新--init光盘分机./install.sh进行测试->所有测试通过
将驱动程序添加到 PHP 扩展
echo -e ";DataStax PHP 驱动
extension=cassandra.so" >>/etc/php/7.0/cli/php.ini//更新 - 为 fpm/php.ini 文件添加了扩展名.echo -e "; DataStax PHP 驱动
extension=cassandra.so" >>/etc/php/7.0/fpm/php.ini
重启nginx和php7.0-fpm
服务 nginx 重启服务 php7.0-fpm 重启
问题:
如果我想使用下面的代码,它会说我找不到类 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 驱动
extension=cassandra.so" >>/etc/php/7.0/fpm/php.ini
为确保通过 CLI 正确加载驱动程序,您可以执行以下操作:
php -m |grep 卡桑德拉
或
php -i |grep -A 10 "^cassandra$"
php -m
将打印出 PHP 能够加载的所有扩展/模块,而 php -i
将显示有关您的 PHP 安装配置的更详细信息.
I've done the installation process as following:
System
PHP 7.0.5-1~dotdeb+8.1 (cli) ( NTS )
Debian 8
Nginx 1.8.1
Laravel 5.2
Java Installation
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
Install needed packages
apt install cmake automake libtool git php7.0-dev libgmp-dev libssl-dev
Libuv Installation
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
Installation 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
Check services
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.
Installation php-driver (PECL Installation isn't working. I think it's because of only php7 setup)
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
Add Driver to PHP Extensions
echo -e "; DataStax PHP Driver
extension=cassandra.so" >> /etc/php/7.0/cli/php.ini
// UPDATE - added extension to fpm/php.ini file.
echo -e "; DataStax PHP Driver
extension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
Restart nginx and php7.0-fpm
service nginx restart
service php7.0-fpm restart
Question:
If I wanna use the following code it says me class Cassandra not found. Webpage: https://github.com/datastax/php-driver#datastax-php-driver-for-apache-cassandra
$cluster = Cassandra::cluster()->build();
Thank you for helping.
Since you are trying to execute your PHP script using nginx+fpm you will need to update the appropriate php.ini file (e.g. /etc/php7/fpm/php.ini
).
Add the driver module to your nginx+fpm installation
echo -e "; DataStax PHP Driver
extension=cassandra.so" >> /etc/php/7.0/fpm/php.ini
To ensure the the driver is being properly loaded via CLI you can execute the following:
php -m | grep cassandra
or
php -i | grep -A 10 "^cassandra$"
php -m
will print out all the extension/modules that PHP was able to load whereas php -i
will display more verbose information about your PHP installation configuration.
这篇关于PHP-Driver DataStax Cassandra DB - 如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!