#安装apache Ignite
1,下载
wget http://mirrors.tuna.tsinghua.edu.cn/apache//ignite/2.6.0/apache-ignite-fabric-2.6.0-bin.zip
2,解压
unzip apache-ignite-fabric-2.6.0-bin.zip
3,进入目录
cd /opt/tmp/apache-ignite-fabric-2.6.0-bin
4,启动
bin/ignite.sh
这个时候应该报需要java环境,安装jdk8-jdk9目前支持
下载jdk8直接解压到指定目录
5,设置jdk环境变量
vim /etc/profile
最后行加:`
export JAVA_HOME=/opt/tmp/jdk1.8.0_162
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
`6,使环境变量生效
source /etc/profile
启动
bin/ignite.sh
成功启动!
7,下载一个DBeaver随便玩了
使用内存数据库主要解决实际项目瓶颈结合项目语言研究php来操作:
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Enabling ODBC. -->
<property name="odbcConfiguration">
<bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
</property>
<!-- Configuring cache. -->
<property name="cacheConfiguration">
<list>
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="ALIPOS"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Long"/>
<property name="keyFieldName" value="sid"/>
<property name="valueType" value="ALPSHOP"/>
<property name="fields">
<map>
<entry key="sid" value="java.lang.Long"/>
<entry key="sname" value="java.lang.String"/>
</map>
</property>
<property name="indexes">
<list>
<bean class="org.apache.ignite.cache.QueryIndex">
<constructor-arg value="sname"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
吐槽,这csdn占用关键字,不好用
3.根据配置文件启动
./ignite.sh /opt/tmp/apache-ignite-fabric-2.6.0-bin/config/alipos-config.xml
4.安装UNIXODBC
5.构建编译igniteODBC
libtoolize && aclocal && autoheader && automake --add-missing && autoreconf
报错提示需要更高版本
手动安装相关版本
libtoolize && aclocal && autoheader && automake --add-missing && autoreconf
./configure --enable-odbc --disable-node --disable-core
make 提示
g++什么语法错误
升级gcc版本
curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++ -y
升级到4.8.2
make提示
AM_PROG_AR什么鬼报错
编辑/opt/tmp/apache-ignite-fabric-2.6.0-bin/platforms/cpp/configure.ac找到
AM_PROG_AR替换m4_pattern_allow([AM_PROG_AR], [AM_PROG_AR])
make没报错
make install 成功构建
安装igniteODBC到ODBC
编辑$IGNITE_HOME/platforms/cpp/odbc/install/ignite-odbc-install.ini文件,并且确保Apache Ignite段的Driver参数指向libignite-odbc.so所在的正确位置;
要安装Ignite的ODBC驱动,可以使用如下的命令:
odbcinst -i -d -f $IGNITE_HOME/platforms/cpp/odbc/install/ignite-odbc-install.ini
,要执行这条命令,很可能需要root权限。
执行成功查看ODBC配置
odbcinst.ini已经配置
手动配置odbc.ini
[Ignite]
Description = Apache Ignite
Driver = Apache Ignite
测试:isql ignite
什么鬼,又报错undefined symbol: clock_gettime
编辑/opt/tmp/apache-ignite-fabric-2.6.0-bin/platforms/cpp/common/Makefile.am找到
libignite_common_la_LDFLAGS =
-no-undefined
-L/usr/local/lib
-ldl
下加-lrt
重新make clean
libtoolize && aclocal && autoheader && automake --add-missing && autoreconf
./configure --enable-odbc --disable-node --disable-core
make && make install
测试:isql ignite 成功
安装php_odbc扩展
wget http://pecl.php.net/get/PDO_ODBC-1.0.1.tgz
tar -zxvf PDO_ODBC-1.0.1.tgz
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-odbc=unixODBC,/usr
make
该处报错:/web/PDO_ODBC-1.0.1/pdo_odbc.c:34:1: 错误:未知的类型名‘function_entry’ function_entry pdo_odbc_functions[] = { ^/web/PDO_ODBC-1.0.1/pdo_odbc.c:35:2: 警告:标量初始化带花括号 经查,是 function_entry的问题,修改 pdo_odbc.c中的代码,改为static const zend_function_entry
make
make install
在php.ini文件添加下面一行
extension = “pdo_odbc.so”
重启php-fpm
/opt/ngx/php/sbin/php-fpm: error while loading shared libraries: libsybdb.so.5: cannot open shared object file: No such file or directory
什么鬼
yum install freetds
重启php-fpm 正常
从 php.ini 检查 pdo_odbc 是否安装成功。
php代码测试:
try {
// dsn连接串
$dsn="odbc:Driver={Apache Ignite};ADDRESS=127.0.0.1:10800;CACHE=ALIPOS";
$dbh = new PDO($dsn);
// Changing PDO error mode.
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$res = $dbh->query('SELECT * from ALPSHOP');
$dbs =$dbh->prepare('INSERT INTO ALIPOS.ALPSHOP (sid, sname) VALUES (?, ?)');
$sid = 1;
$sName = "Bond";
// Binding parameters.
$dbs->bindParam(1, $sid);
$dbs->bindParam(2, $sName);
// Executing the query.
$dbs->execute();
$ret=$dbh->query("select cast(1 as varbinary(max)) as col",PDO::FETCH_ASSOC);
if ($res == FALSE)
print_r("Exception");
// Printing results.
foreach($res as $row) {
//print_r($row);
}
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "\n";
die();
}
和windows效果一样,增,删,改,没问题,查询内存超出炒蛋。
直接使用odbc
cd /opt/tmp/php-5.5.38/ext/odbc
/usr/local/php/bin/phpize
sed -ri 's@^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$@#&@g' configure
./configure --with-php-config=/opt/ngx/php/bin/php-config --with-unixODBC=/usr/local
make && make install
php代码直接测试
$conn=odbc_connect('Driver={Apache Ignite};ADDRESS=127.0.0.1:10800;CACHE=ALIPOS','','');
if (!$conn)
{
exit("lost " . $conn);
}
$sql="select cast(1 as varbinary(max)) as col";
$rs=odbc_exec($conn,$sql);
print_r($rs);
if (!$rs)
{
exit("SQL error");
}
什么鬼,内存超出还是,
仔细看文档(官网已知bug,5.6以后版本修复?)
查看ODBC源码,明显拿不到字段buf大小产生的错误,ignite原因?没有账号登陆提问,算了!
不活跃的项目慎用,呵呵~
没关系,最主要开源,结合自己项目自己能改就行
下手修改php_odbc.c文件
找到odbc_bindcols方法下
rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), colfieldid,
NULL, 0, NULL, &displaysize);
#if defined(ODBCVER) && (ODBCVER >= 0x0300)
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && colfieldid == SQL_DESC_OCTET_LENGTH) {
/* This is a quirk for ODBC 2.0 compatibility for broken driver implementations.
*/
charextraalloc = 1;
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
NULL, 0, NULL, &displaysize);
}
改为
rc = PHP_ODBC_SQLCOLATTRIBUTE(result->stmt, (SQLUSMALLINT)(i+1), colfieldid,
NULL, 0, NULL, &displaysize);
#if defined(ODBCVER) && (ODBCVER >= 0x0300)
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO && colfieldid == SQL_DESC_OCTET_LENGTH) {
/* This is a quirk for ODBC 2.0 compatibility for broken driver implementations.
*/
charextraalloc = 1;
rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
NULL, 0, NULL, &displaysize);
}else if (displaysize<0) {
displaysize=256;
}
注:字符串字段没有拿到字段最大允许值时用256,意味着你的字符串类型都限制了,可以根据需要修改大小。
重新编译,测试正常
自此,php增删改查ignite完全正常
下一步生产环境数据性能测试