当前位置: 首页 > 工具软件 > redis_admin > 使用案例 >

PostgreSQL+REDIS_FDW详细记录踩坑过程(二)

东方志尚
2023-12-01

为Pg安装redis_fdw插件

安装PG https://blog.csdn.net/qq_36934544/article/details/82854762

1.为redis_fdw创建文件夹contrib :mkdir /monchickey/pgsql/contrib


[root@localhost /]# mkdir /monchickey/pgsql/contrib

2.解压redis_fdw-REL_10_STABLE.zip : unzip  redis_fdw-REL_10_STABLE.zip

[root@localhost admin]# unzip redis_fdw-REL_10_STABLE.zip 
Archive:  redis_fdw-REL_10_STABLE.zip
8839b65ffff2d3f3f1b72297f32299d8d17fa534
   creating: redis_fdw-REL_10_STABLE/
  inflating: redis_fdw-REL_10_STABLE/.dir-locals.el  
  inflating: redis_fdw-REL_10_STABLE/.gitattributes  
  inflating: redis_fdw-REL_10_STABLE/.gitignore  
  inflating: redis_fdw-REL_10_STABLE/META.json  
  inflating: redis_fdw-REL_10_STABLE/Makefile  
  inflating: redis_fdw-REL_10_STABLE/README.md  
  inflating: redis_fdw-REL_10_STABLE/redis_fdw--1.0.sql  
  inflating: redis_fdw-REL_10_STABLE/redis_fdw.c  
  inflating: redis_fdw-REL_10_STABLE/redis_fdw.control  
   creating: redis_fdw-REL_10_STABLE/test/
 extracting: redis_fdw-REL_10_STABLE/test/.gitignore  
   creating: redis_fdw-REL_10_STABLE/test/expected/
  inflating: redis_fdw-REL_10_STABLE/test/expected/redis_fdw.out  
   creating: redis_fdw-REL_10_STABLE/test/sql/
 extracting: redis_fdw-REL_10_STABLE/test/sql/redis_clean  
  inflating: redis_fdw-REL_10_STABLE/test/sql/redis_fdw.sql  
  inflating: redis_fdw-R

3.将解压后的文件移动到contrib : mv /home/admin/redis_fdw-REL_10_STABLE /monchickey/pgsql/contrib/

[root@localhost /]# mv /home/admin/redis_fdw-REL_10_STABLE /monchickey/pgsql/contrib/
[root@localhost /]# 

4.把redis下面的 deps/hiredis 目录拷贝到  deps/hiredis 目录拷贝到redis_fdw-REL_10_STABLE目录下

[root@localhost /]# mv /home/admin/hiredis/  /monchickey/pgsql/contrib/redis_fdw-REL_10_STABLE/
[root@localhost /]# 

5.进入hiredis :cd hiredis   编译 make   进行指定安装

[root@localhost /]# cd /monchickey/pgsql/contrib/redis_fdw-REL_10_STABLE/hiredis/
[root@localhost hiredis]# make
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  hiredis.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  async.c
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  read.c
cc -shared -Wl,-soname,libhiredis.so.0.13 -o libhiredis.so  net.o hiredis.o sds.o async.o read.o
ar rcs libhiredis.a net.o hiredis.o sds.o async.o read.o
cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  test.c
cc -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  -o hiredis-test   test.o libhiredis.a
Generating hiredis.pc for pkgconfig...
[root@localhost hiredis]# make prefix=/monchickey/pgsql/contrib/redis_fdw-REL_10_STABLE/hiredis/ install
mkdir -p /usr/local/include/hiredis /usr/local/lib
cp -a hiredis.h async.h read.h sds.h adapters /usr/local/include/hiredis
cp -a libhiredis.so /usr/local/lib/libhiredis.so.0.13
cd /usr/local/lib && ln -sf libhiredis.so.0.13 libhiredis.so
cp -a libhiredis.a /usr/local/lib
mkdir -p /usr/local/lib/pkgconfig
cp -a hiredis.pc /usr/local/lib/pkgconfig
[root@localhost hiredis]# 

6.这里要进行对hiredis进行操作,不然之后会报错,以下是报错信息。

libhiredis.so.0.13: cannot open shared object file: No such file or director

解决方式:

mkdir /usr/lib/hiredis
cp libhiredis.so /usr/lib/hiredis #将动态连接库libhiredis.so至/usr/lib/hiredis
mkdir /usr/include/hiredis
cp hiredis.h /usr/include/hiredis
echo '/usr/local/lib' >>/etc/ld.so.conf 
ldconfig

---------------------

本文来自 SakuraLJ 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/sakurallj/article/details/79452435?utm_source=copy 


[root@localhost hiredis]# mkdir /usr/lib/hiredis
[root@localhost hiredis]# cp libhiredis.so /usr/lib/hiredis
[root@localhost hiredis]# mkdir /usr/include/hiredis
[root@localhost hiredis]# cp hiredis.h /usr/include/hiredis
[root@localhost hiredis]# echo '/usr/local/lib' >>/etc/ld.so.conf 
[root@localhost hiredis]# ldconfig

7.确认安装之后,进入 redis_fdw-REL_10_STABLE目录

修改MakeFile文件:vi Makefile

[root@localhost redis_fdw-REL_10_STABLE]# vi Makefile 
# 末尾追加

include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif

# we put all the tests in a test subdir, but pgxs expects us not to, darn it
override pg_regress_clean_files = test/results/ test/regression.diffs test/regression.out tmp_check/ log/
LDFLAGS += -L/monchickey/pgsql/contrib/redis_fdw-REL_10_STABLE/hiredis/bin

8.安装redis_fdw

[root@localhost redis_fdw-REL_10_STABLE]# export PATH=/monchickey/pgsql/bin:$PATH
[root@localhost redis_fdw-REL_10_STABLE]# make USE_PGXS=clean
Makefile:42: ../../src/Makefile.global: No such file or directory
Makefile:43: /contrib/contrib-global.mk: No such file or directory
make: *** No rule to make target `/contrib/contrib-global.mk'.  Stop.
[root@localhost redis_fdw-REL_10_STABLE]# make USE_PGXS=1
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O2 -DMAP_HUGETLB=0x40000 -fPIC -I. -I./ -I/monchickey/pgsql/include/postgresql/server -I/monchickey/pgsql/include/postgresql/internal -I/opt/local/Current/include -D_GNU_SOURCE  -I/opt/local/Current/include/libxml2 -I/opt/local/Current/include  -c -o redis_fdw.o redis_fdw.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -g -O2 -DMAP_HUGETLB=0x40000 -fPIC -shared -o redis_fdw.so redis_fdw.o -L/monchickey/pgsql/lib    -L/opt/local/Current/lib -Wl,--as-needed -Wl,-rpath,'/monchickey/pgsql/lib',--enable-new-dtags -L/monchickey/pgsql/contrib/redis_fdw-REL_10_STABLE/hiredis/bin  -lhiredis 
[root@localhost redis_fdw-REL_10_STABLE]# make USE_PGXS=1 install
/bin/mkdir -p '/monchickey/pgsql/lib/postgresql'
/bin/mkdir -p '/monchickey/pgsql/share/postgresql/extension'
/bin/mkdir -p '/monchickey/pgsql/share/postgresql/extension'
/usr/bin/install -c -m 755  redis_fdw.so '/monchickey/pgsql/lib/postgresql/redis_fdw.so'
/usr/bin/install -c -m 644 .//redis_fdw.control '/monchickey/pgsql/share/postgresql/extension/'
/usr/bin/install -c -m 644 .//redis_fdw--1.0.sql  '/monchickey/pgsql/share/postgresql/extension/'
[root@localhost redis_fdw-REL_10_STABLE]# 

假如报错,就用yum list postgres* 查看是否少了安装包,如果少了 这里是9.2的版本,那么就直接运行yum install postgres-devel

如果是9.2及以上版本  就应该先下载对应的包 再进行安装。

以上 就安装完成了。

后面的使用 等我这边完全熟练之后就开始更新。踩了不知道多少坑 才明白原来这么简单。

参考:https://yq.aliyun.com/articles/9035

          https://blog.csdn.net/sakurallj/article/details/79452435?utm_source=copy

          以及德哥的文章https://yq.aliyun.com/articles/14609

 类似资料: