您好,欢迎访问代理记账网站
移动应用 微信公众号 联系我们

咨询热线 -

电话 15988168888

联系客服
  • 价格透明
  • 信息保密
  • 进度掌控
  • 售后无忧

PHP扩展安装与使用系列教程(40) --- zookeeper扩展 - 分布式服务

zookeeper扩展 - 分布式服务

依赖 zookeeper 服务器

  • 安装Java8
wget https://download.oracle.com/otn/java/jdk/8u291-b10/d7fc238d0cbf4b0dac67be84580cfb4b/jdk-8u291-linux-x64.rpm?AuthParam=1621916310_96f5bfd652e91e058fbf915df69fb665
rpm -ivh jdk-8u291-linux-x64.rpm
export JAVA_HOME=/usr/java/jdk1.8.0_291-amd64
export PATH=$PATH:$JAVA_HOME/bin
  • 安装maven or ant
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
tar xzf apache-maven-3.8.1-bin.tar.gz
export PATH=$PATH:/root/php/packages/apache-maven-3.8.1/bin
wget https://mirrors.tuna.tsinghua.edu.cn/apache/ant/source/apache-ant-1.10.10-src.tar.gz
tar xzf apache-ant-1.10.10-src.tar.gz && cd apache-ant-1.10.10 && ./build.sh
export ANT_HOME=/root/php/packages/apache-ant-1.10.10
export PATH=$PATH:/root/php/packages/apache-ant-1.10.10/dist/bin/
ant -version
  • 安装zookeeper服务器
cd ~/php/packages
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.9/apache-zookeeper-3.5.9.tar.gz
tar xzf apache-zookeeper-3.5.9.tar.gz && cd apache-zookeeper-3.5.9
yum install -y cppunit-devel.x86_64 cppunit.x86_64
mvn clean install -Dmaven.test.skip=true
cd zookeeper-client/zookeeper-client-c
autoreconf -if && ./configure && make && make install

安装Docker以及镜像

  • 至少3台服务器
  1. 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce --showduplicates | sort -r
yum install -y docker-ce
systemctl start docker
systemctl status docker
  1. 拉取PHP服务器
docker pull mysql
docker pull phpmyadmin/phpmyadmin
docker pull php:7.4.18-apache
docker pull phpswoole/swoole:latest
docker pull zookeeper
docker pull nginx:stable
  • 创建容器
docker run -d --name server_base php:7.4.18-apache

docker cp /usr/local/lib/libzookeeper_mt.so server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_mt.so.2 server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_mt.so.2.0.0 server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_mt.a server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_mt.la server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_st.a server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_st.la server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_st.so server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_st.so.2 server_base:/usr/local/lib/
docker cp /usr/local/lib/libzookeeper_st.so.2.0.0 server_base:/usr/local/lib/
docker cp /usr/local/include/zookeeper server_base:/usr/local/include/zookeeper

php-zookeeper扩展安装

  • 修改zookeeper头文件 : /usr/local/include/zookeeper/zookeeper_version.h
#define ZOO_MAJOR_VERSION 3
#define ZOO_MINOR_VERSION 7
#define ZOO_PATCH_VERSION 0
cd ~/php/packages
wget https://pecl.php.net/get/zookeeper-0.7.2.tgz
docker cp zookeeper-0.7.2.tgz server_base:/usr/local/

docker exec -it server_base /bin/bash
cd /usr/local
tar xzf zookeeper-0.7.2.tgz && cd zookeeper-0.7.2
phpize && ./configure && make && make install
cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
echo -e '\n[zookeeper]\nextension = zookeeper.so' >>  /usr/local/etc/php/php.ini
cd /usr/local && rm  -rf zookeeper-0.7.2 && rm -rf zookeeper-0.7.2.tgz

生成带php-apache-zookeeper的镜像

docker commit server_base mc:php7.4.18-apache-zookeeper
docker save -o mc-php7.4.18-apache-zookeeper.img mc:php7.4.18-apache-zookeeper

测试

  1. 启动容器

docker run -d --name web_server1 -p 18081:80 --add-host=host.docker.internal:host-gateway -v /root/php/src/zookeeper/server1:/var/www/html -v /root/php/src/zookeeper/services:/var/www/services --privileged=true mc:php7.4.18-apache-zookeeper

docker run -d --name web_server2 -p 18082:80 --add-host=host.docker.internal:host-gateway -v /root/php/src/zookeeper/server2:/var/www/html -v /root/php/src/zookeeper/services:/var/www/services --privileged=true mc:php7.4.18-apache-zookeeper

docker run -d --name web_server3 -p 18083:80 --add-host=host.docker.internal:host-gateway -v /root/php/src/zookeeper/server3:/var/www/html -v /root/php/src/zookeeper/services:/var/www/services --privileged=true mc:php7.4.18-apache-zookeeper


docker run -d --name web_server_config -p 8084:80 --add-host=host.docker.internal:host-gateway -v /root/php/src/zookeeper/server_config:/var/www/html -v /root/php/src/zookeeper/services:/var/www/services --privileged=true mc:php7.4.18-apache-zookeeper


docker run --name mysql5.6 -d -p 10086:3306 -e MYSQL_ROOT_PASSWORD=PHP.19src.com mysql:5.6
docker run --name phpmyadmin -d --link mysql5.6 -p 8082:80 -e PMA_HOST="mysql5.6" -e PMA_USER=root -e PMA_PASSWORD=PHP.19src.com phpmyadmin
docker run --name phpmyadmin_local -d -p 8083:80 -e PMA_HOST=172.17.0.3 -e PMA_PORT=3306 -e PMA_USER=root -e PMA_PASSWORD=PHP.19src.com phpmyadmin

docker ps | grepmysql
docker exec -it {$containerId} /bin/bash
mysql -uroot -p
mysql> use mysql;
mysql> update user set host='%' where user='root';
mysql> flush privileges;

docker run -d --name zookeeper -p 2181:2181 zookeeper
  1. 启动zookeeper服务器,测试代码
cp /root/php/packages/apache-zookeeper-3.5.9/conf/zoo_sample.cfg /root/php/packages/apache-zookeeper-3.5.9/conf/zoo.cfg 
zoo.cfg :  dataDir=/root/php/src/zookeeper/data
/root/php/packages/apache-zookeeper-3.5.9/bin/zkServer.sh start
docker exec web_server1 sh  -c "php /var/www/html/my_services.php"
docker exec web_server2 sh  -c "php /var/www/html/my_services.php"
docker exec web_server3 sh  -c "php /var/www/html/my_services.php"
docker exec web_server_config sh  -c "php /var/www/html/my_services.php"
docker exec -it web_server1 sh -c "pkill php"

文档

视频:zookeeper扩展 - 分布式服务

上一节:yac扩展-用户数据缓存插件
下一节:openal - 音频处理


分享:

低价透明

统一报价,无隐形消费

金牌服务

一对一专属顾问7*24小时金牌服务

信息保密

个人信息安全有保障

售后无忧

服务出问题客服经理全程跟进