Zookeeper extension tags: phpzookeeperlinuxext is installed in linuxphp. zookeeper provides sharp naming services and cluster operations are atomic. Therefore, it is used in multiple projects. In the original project, the status of the server cluster is uniformly reported to the zookeeper cluster, and then the zookeeper is accessed through the client, real-time observation
In linux php, zookeeper extension tags is installed. phpzookeeperlinux ext: zookeeper provides sharp naming services and cluster operations are atomic. Therefore, zookeeper is used in multiple projects. In the original project, the status of the server cluster is uniformly reported to the zookeeper cluster, and then the zookeeper is accessed through the client, real-time observation
Install zookeeper extension in linux php
Preface:
Zookeeper provides sharp naming services and cluster operations are atomic. Therefore, it is used in multiple projects.
In the original project, the status of the server cluster is uniformly reported to the zookeeper cluster, and then the zookeeper is accessed through the client to observe the status of the cluster in real time (of course, you can also configure synchronization ). However, the cross-platform client is not convenient. It is too egg pain to develop a mobile client. Therefore, we plan to use PHP to read zookeeper.
Environment:
1 2 3 4 5 |
centos : 6.4
zookeeper : 3.4 . 5
php : 5.5 . 10
nginx : 1.5
Php zookeeper extension: 0.2 . 2
|
1. If nginx is not installed, install nginx first, you can refer to: http://hi.baidu.com/solohac/item/081e97e54868403f86d9deff
Make sure that nginx is configured first, and then proceed to the next step.
2. If php is not installed, install php first (configure nginx php support before installing zookeeper extension)
Download
Wget http://hk2.php.net/distributions/php-5.5.10.tar.gz
Extract
Tar zxvf php-5.5.10.tar.gz
Generation and Installation
Cd php-5.5.10
1 |
./configure --prefix=/usr/local/php5.5.10 --with-config-file-path=/usr/local/php5.5.10/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64
|
Make & make install
Configure php
1 2 |
cp php.ini-production /usr/local/php5. 5.10 /etc/php.ini
cp /usr/local/php5. 5.10 /etc/php-fpm.conf. default /usr/local/php5. 5.10 /etc/php-fpm.conf
|
Start
1 |
/usr/local/php5. 5.10 /sbin/php-fpm
|
Check whether the port is listening
Netstat-lnt | grep 9000
Edit nginx configuration file
1 2 3 4 5 6 7 8 9 10 11 |
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri = 404 ;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0 . 0.1 : 9000 ;
}
|
Nginx reload Configuration
Nginx-s reload
Test php access
Cd/usr/local/nginx/html/
Vim aa. php
Write content
If php can be accessed normally, continue with the following installation. If not, check the php support.
2. Install zookeeper
Download
Wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
Decompress the package (whatever directory you want, just remember)
Tar zxfv zookeeper-3.4.5.tar.gz.
Start the zookeeper Server
1 2 3 4 |
cd zookeeper- 3.4 . 5 /conf
cp zoo_sample.cfg zoo.cfg
cd ../bin
./zkServer.sh start
|
It is best to confirm whether the request is expected to be successful,./zkServer. sh status
The result is as follows:
1 2 3 4 |
[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /root/zookeeper- 3.4 . 5 /bin/../conf/zoo.cfg
Mode: standalone
|
Compile the zookeeper library for php
1 2 3 |
cd ../src/c
./configure --prefix=/usr/local/zookeeperlib
make && make install
|
3. Install zookeeper extension of php
Download
Wget http://pecl.php.net/get/zookeeper-0.2.2.tgz
Decompress the package. xml file)
Tar zxvf zookeeper-0.2.2.tgz
Put him in/root/php-5.5.10/ext
Mv zookeeper-0.2.2/root/php-5.5.10/ext/
CDS/root/php-5.5.10/ext/
Change directory name
Music zookeeper-0.2.2 zookeeper
Back to php-5.5.10 directory
Cd ..
./Buildconf -- force
./Configure-h | grep zookeeper
Check whether configure supports zookeeper.
1 2 3 |
--enable-zookeeper Enable zookeeper support
--disable-zookeeper-session Disable zookeeper session handler support
-- with -libzookeeper-dir=DIR Set the path to libzookeeper install prefix.
|
If it is shown above, it indicates it is supported. continue to the next step.
Cd ext/zookeeper
Generate configure
/Usr/local/php5.5.10/bin/phpize
Generate makefile
1 2 3 4 |
./configure -- with -php-config=/usr/local/php5. 5.10 /bin/php-config -- with -libzookeeper-dir=/usr/local/zookeeperlib
Note the preceding path:
-- with -Php-config is the php installation path.
-- with -Libzookeeper-dir is the path for installing the zookeeper library in step 1.
|
Compile and install
Make & make install
The result is as follows:
Installing shared extensions:/usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/
Add ext path and file name
1 2 3 4 |
vim /usr/local/php5. 5.10 /etc/php.ini
extension_dir= "/usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/"
extension=zookeeper.so
|
4. recompile php
Go to the Php source code folder and do not enter an error. My source code folder is/root/php-5.5.10, the installation directory is/usr/local/php5.5.10
Cd/root/php-5.5.10
Rm-rf autom4te. cache/configure
./Buildconf -- force
./Configure-h | grep zookeeper
Check whether configure supports zookeeper.
If yes, continue.
. /Configure -- prefix =/usr/local/php5.5.10 -- with-config-file-path =/usr/local/php5.5.10/etc -- with-bz2 -- with-curl -- enable-ftp -- enable -sockets -- disable-ipv6 -- with-gd -- with-jpeg-dir =/usr/local -- with-png-dir =/usr/local -- with-freetype-dir =/usr/ local -- enable-gd-native-ttf -- with-iconv-dir =/usr/local -- enable-mbstring -- enable-calendar -- with-gettext -- with-libxml-dir =/ usr/local -- with-zlib -- with-pdo-mysql = mysqlnd -- with-mysqli = mysqlnd -- with-mysql = mysqlnd -- enable-dom -- enable-xml -- enable-fpm -- with-libdir = lib64 -- enable-zookeeper -- with-libzookeeper-dir =/usr/local/zookeeperlib -- enable-sockets
Make & make install
Now, the support has been installed to test whether it is normal.
There are examples/Zookeeper_Example.php files in the zookeeper-0.2.2.tgz (that is, the zookeeper extension of Php) that can be used to test
1 2 |
cp /root/php- 5.5 . 10 /ext/zookeeper/examples/Zookeeper_Example.php /usr/local/nginx/html/
/usr/local/php5. 5.10 /bin/php /usr/local/nginx/html/Zookeeper_Example.php
|
Check whether the following results can be printed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
string( 0 ) ""
array( 1 ) {
[ 0 ]=>
string( 9 ) "zookeeper"
}
NULL
string( 3 ) "abc"
array( 2 ) {
[ 0 ]=>
string( 7 ) "test123"
[ 1 ]=>
string( 9 ) "zookeeper"
}
NULL
NULL
array( 2 ) {
[ 0 ]=>
string( 3 ) "001"
[ 1 ]=>
string( 3 ) "002"
}
|
Restart php-fpm
Killall php-fpm
/Usr/local/php5.5.10/sbin/php-fpm
Now you can access php that supports zookeeper extension through a browser.
If you have other questions, check:
1. iptables
2. selinux