hyperf利用配置中心使用zookeeper(centos7)

hyperf利用配置中心使用zookeeper(centos7),第1张

hyperf利用配置中心使用zookeeper(centos7)

hyperf版本2.2

swoole版本4.8

系统为centos7

php8.0

一.安装hyperf的配置中心,具体参考官方文档官方文档https://hyperf.wiki/2.2/#/zh-cn/config-centerhttps://hyperf.wiki/2.2/#/zh-cn/config-center

二.安装需要使用的ext-zookeeper

ext-zookeeperhttps://github.com/swoole/ext-zookeeperhttps://github.com/swoole/ext-zookeeper1.安装php-x

需要的扩展:cmake,gcc

安装可参考

wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz 
tar xzvf cmake-3.3.2.tar.gz
#安装gcc
yum install gcc-c++
cd cmake-3.3.2
./bootstrap
gmake
make install

安装phpx

git clone https://github.com/matyhtf/phpx.git
cd phpx
./build.sh
cp bin/phpx /usr/local/bin
cmake .
make -j 4
make install

安装ext-zookeeper

git clone https://github.com/swoole/ext-zookeeper.git
cd ext-zookeeper
phpx build -v -d
phpx install

在 php.ini中添加

extension=swoole_zookeeper.so

此处有可能会报错,执行php -m或者PHP -i后显示:

PHP Warning:  PHP Startup: Unable to load dynamic library 'swoole_zookeeper.so' (tried: /usr/lib64/php/modules/swoole_zookeeper.so (libphpx.so: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/swoole_zookeeper.so.so (/usr/lib64/php/modules/swoole_zookeeper.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

这是环境引起的错误,需要处理一下

cd ext-zookeeper/lib
ldd swoole_zookeeper.so

 处理方案(解决方案参考:PHP-X介绍 - 半山th - 博客园)

echo $LD_LIBRARY_PATH

如果输出值为空

export LD_LIBRARY_PATH=/usr/local/lib/

如果输出值不为空

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/

最后执行

source ~/.bashrc

 现在查看php的模块已经可以使用swoole_zookeeper了

2.hyperf增加配置

安装配置中心

composer require hyperf/config-center

安装zookeeper

composer require hyperf/config-zookeeper
php bin/hyperf.php vendor:publish hyperf/config-center

.env增加配置

CONFIG_CENTER_DRIVER=zookeeper

修改配置(config/autoload/config_center.php)中的server跟path,注释掉其它无用的驱动。

个人理解此处zookeeper的作用类似于web项目中config.php这个文件,只是将配置内容保存再zookeeper中,zookeeper中的格式需要是一个json格式,具体可以参考源码。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5677857.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存