Install Gearman on Linux and configure the PHP extended environment using Gearman

Source: Internet
Author: User
Tags install php mysql client server port zend
Install Gearman on Linux and configure the PHP expansion environment using Gearman.


The installation Gearman is introduced first.

1. Install dependent libraries First
# yum install-y boost-devel gperf libevent-devel libuuid-devel

2. Download Gearman
Download:
# wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz
Extract:
# TAR-XZVF Gearmand-1.1.12.tar.gz

3. Configure Gearman
# CD gearmand-1.1.12
# pwd
/data/gearmand-1.1.12
#./configure
...
Checking for boostlib >= 1.39 ... Configure:we could not detect the Boost libraries (version 1.39 or higher). If you are have a staged boost library (still not installed) please specify $BOOST _root in your environment and does not give a  PATH to--with-boost option. If You are sure your have boost installed, then check your version number looking in <boost/version.hpp>. Http://randspringer.de/boost for more documentation.
Configure:error:could not find boost

If the above error occurs, check to see if the currently installed boost version is >= 1.39, and if the version is low, you need to install a higher version of boost.
If boost is already installed, uninstall and install it first, and if the version >= 1.39, the above error also occurs, and then installs.
Install boost:
# Yum Install boost
# yum Install Boost-devel
# yum Install Boost-doc

To perform the configuration again:
#./configure

4. Compile Gearman
# pwd
/data/gearmand-1.1.12
# make
...
CXX UTIL/GEARMAND_HOSTILE_GEARMAND-DAEMON.O
CXX UTIL/GEARMAND_HOSTILE_GEARMAND-PIDFILE.O
CXX LIBTEST/GEARMAND_HOSTILE_GEARMAND-CPU.O
Cxxld Gearmand/hostile_gearmand
/usr/bin/ld:cannot find-lmysqlclient
Collect2:ld returned 1 exit status
MAKE[1]: * * * [Gearmand/hostile_gearmand] Error 1
MAKE[1]: Leaving directory '/data/backup/gearmand-1.1.12 '
Make: * * * [ALL] Error 2

If the above error occurs, look for the directory where the Mysqlclient library files are located:
# Find/-name *mysqlclient*
/usr/lib64/mysql/libmysqlclient.a
/usr/lib64/mysql/libmysqlclient_r.a

If you find the Mysqlclient library file, build two soft links in the/usr/lib/directory:
# ln-s/USR/LIB64/MYSQL/LIBMYSQLCLIENT.A/USR/LIB/LIBMYSQLCLIENT.A
# ln-s/USR/LIB64/MYSQL/LIBMYSQLCLIENT_R.A/USR/LIB/LIBMYSQLCLIENT_R.A

If you do not find the Mysqlclient library file, you will need to install the MySQL Client.

To perform the compilation again:
# make

5. Install Gearman
# pwd
/data/gearmand-1.1.12
# make Install

Random access to other directory execution Gearman, check the installation is successful:
# Gearman

Gearman Error in usage (No functions were provided).
Client Mode:gearman [Options] [<data>]
Worker mode:gearman-w [options] [<command> [<args> ...]]
Common options to both client and worker modes.
-F <function>-function name to use for jobs (can give many)
-H -h-print This Help menu
-v-print Diagnostic information to stdout (false)
-P <port>-JOB server port
-T <timeout>-Timeout in milliseconds
-I <pidfile>-Create a pidfile for the process
-s-enable SSL Connections
Client options:
-b-run jobs in the background (false)
-i-run Jobs as high priority
-l-run Jobs as low priority
-n-run one job per line (false)
-n-same As-n, but strip off the newline (false)
-p-prefix all output lines with functions names
-s-send job without reading from standard input
-U <unique>-unique key to use for job
Worker options:
-C <count>-Number of jobs for worker to run before exiting
-n-send data packet for each line (false)
-n-same As-n, but strip off the newline (false)
-w-run in worker mode (false)
#

The display above shows that the installation Gearman succeeded.

Start and stop the Gearman service:
1. Start Gearman
# gearmand-d--log-file=/data/gearman/logs/gearmand.log
The Log-file parameter specifies the log file.
2. Stop Gearman
# gearadmin--shutdown

Here's how to configure the PHP scale-out environment using Gearman.

1. First install PHP to expand the environment
Download gearman-1.1.2.tgz (Note that this gearman-1.1.2.tgz is different from the previous gearmand-1.1.12.tar.gz):
# wget Http://pecl.php.net/get/gearman-1.1.2.tgz
(Download list address: Http://pecl.php.net/package/gearman)

# TAR-ZXVF Gearman-1.1.2.tgz

Configuration:
# CD gearman-1.1.2
# phpize

If "Phpize:command not Found" appears, install PHP:
# Yum Install php php-devel
And then execute:
# phpize
Configuring for:
PHP Api version:20090626
Zend Module Api no:20090626
Zend Extension Api no:220090626

#./configure

Compile Installation:
# make
# make Install
Installing Shared extensions:/usr/lib64/php/modules/
Appears as a hint, the installation is successful, in the/usr/lib64/php/modules/directory has gearman.so files.

2. Add Gearman configuration to php.ini file
Before the configuration, first write a PHP program test, the program is very simple, that is, print Gearman version.
# Cd/data/test
# VI test.php
<?php
Print gearman_version (). "\ n";
?>

And then execute the program to see what results:
# php test.php
PHP Fatal error:call to undefined function gearman_version () in/data/test/test.php in line 2
The undefined gearman_version function was invoked.

Add the following configuration and then run the program to see.
Find the php.ini file first:
# Find/-name php.ini
/etc/php.ini
# CD/ETC
To add the configuration to the appropriate location, first find the location where the extension word appears in the file:
# more PHP.ini | grep extension
; Directives are variables used to configure PHP or PHP extensions.
; Dynamically loaded extension (either a PHP extension or a Zend extension),
; You would use this constants *after* the line that loads the extension.
; Leading '/'. You must also specify the file extension being used including
; Directory in which the loadable Extensions (modules) reside.
; Http://www.php.net/manual/en/ini.core.php#ini.extension-dir
; Extension_dir = "./"
; If you are wish to have a extension loaded automatically, use the following
; Extension=modulename.extension
; Extension=msql.so
; Extension=/path/to/extension/msql.so
; If you are only provide the name of the extension, PHP'll look for it
; Default extension directory.
; Note:packaged extension modules are now loaded via the. ini files
; Sqlite3.extension_dir =
; Sets the directory name where SOAP extension'll put cache files.
#

Add Configuration:
# VI PHP.ini
Extension=gearman.so
Position:


Re-executing program:
# php test.php
1.1.12

To do this, use the Gearman PHP extended environment configuration to complete.

Reference:

http://blog.csdn.net/clevercode/article/details/45718735

https://my.oschina.net/liucao/blog/755299

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.