构建一个分布的LAMP系统

 系统鸟瞰如下图:

构建一个分布的LAMP系统_第1张图片
  整个系统位于LAN:192.168.31.0/24之中,两台httpd服务器通过DNS系统共同分担客户请求,他们使用相同的配置,其DocumentRoot相同且均位于局域网内的另一台NFS服务器上,网页php脚本通过php-fcgi的方式解释执行,必要时,php将会访问局域网中的数据库服务器为网站提供数据库服务。 

  http服务器与php、Xcache将采用源码方式安装,NFS使用RPM方式安装,mysql使用官方发布的X86-64二进制包方式安装,事先,我们已经在admin主机192.168.31.98上架起了一个公共的http服务器,并将系统安装所需各压缩文件均放置在http://192.168.31.98/tarball/之下。

  安装、配置两台HTTP服务器:

  安装脚本如下:

install_http.sh
 1 declare tempDir=`mktemp -d` 
 2 declare aprDir=/usr/local/apr
 3 declare aprutilDir=/usr/local/apr-util
 4 declare apacheDir=/usr/local/apache249
 5 declare apacheConfDir=/etc/httpd249
 6 
 7 hwclock -s
 8 
 9 chmod 700 $tempDir ; chown root:root $tempDir ; cd $tempDir 
10 
11 #pcre-devel
12 yum install -y gcc*
13 yum groupinstall -y 'Desktop Platform Development'
14 #yum groupinstall -y 'Additional Development'
15 yum groupinstall -y 'Development tools'
16 yum groupinstall -y 'Server Platform Development'
17 yum install -y pcre
18 yum install -y pcre-devel
19 
20 wget http://192.168.31.98/tarball/apr-1.5.0.tar.bz2
21 wget http://192.168.31.98/tarball/apr-util-1.5.3.tar.bz2
22 wget http://192.168.31.98/tarball/httpd-2.4.9.tar.bz2
23 
24 tar xf apr-1.5.0.tar.bz2
25 cd apr-1.5.0
26 ./configure --prefix=${aprDir}
27 make
28 make install 
29 cd ..
30 rm -fr apr-1.5.0
31 
32 tar xf apr-util-1.5.3.tar.bz2
33 cd apr-util-1.5.3
34 ./configure --prefix=${aprutilDir} --with-apr=${aprDir}
35 make 
36 make install
37 cd ..
38 rm -fr apr-util-1.5.3
39 
40 yum install -y openssl openssl-devel
41 
42 tar xf httpd-2.4.9.tar.bz2
43 cd httpd-2.4.9
44 ./configure --prefix=$apacheDir --sysconfdir=$apacheConfDir --enable-so  --enable-ssl \
45    --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=$aprDir \
46    --with-apr-util=$aprutilDir --enable-modules=most --enable-mpms-shared=all \
47    --with-mpm=event --enable-proxy-fcgi
48 make
49 make install
50 cd ..
51 rm -fr httpd-2.4.9
52 
53 cd
54 rm -fr $tempDir 
55 
56 # mamange the /etc/init.d/httpd249 scripts   
57 # chkconfig --add httpd249

  分别在192.168.31.2与192.168.31.3上用bash解释执行install_http.sh脚本。然后将httpd添加入系统服务。

/etc/rc.d/init.d/httpd249     #这里直接修改自原httpd的service脚本
  1 #!/bin/bash
  2 #
  3 # httpd        Startup script for the Apache HTTP Server
  4 #
  5 # chkconfig: - 85 15
  6 # description: The Apache HTTP Server is an efficient and extensible  \
  7 #           server implementing the current HTTP standards.
  8 # processname: httpd
  9 # config: /etc/httpd/conf/httpd.conf
 10 # config: /etc/sysconfig/httpd
 11 # pidfile: /var/run/httpd/httpd.pid
 12 #
 13 ### BEGIN INIT INFO
 14 # Provides: httpd
 15 # Required-Start: $local_fs $remote_fs $network $named
 16 # Required-Stop: $local_fs $remote_fs $network
 17 # Should-Start: distcache
 18 # Short-Description: start and stop Apache HTTP Server
 19 # Description: The Apache HTTP Server is an extensible server 
 20 #  implementing the current HTTP standards.
 21 ### END INIT INFO
 22 
 23 # Source function library.
 24 . /etc/rc.d/init.d/functions
 25 
 26 if [ -f /etc/sysconfig/httpd ]; then
 27         . /etc/sysconfig/httpd
 28 fi
 29 
 30 # Start httpd in the C locale by default.
 31 HTTPD_LANG=${HTTPD_LANG-"C"}
 32 
 33 # This will prevent initlog from swallowing up a pass-phrase prompt if
 34 # mod_ssl needs a pass-phrase from the user.
 35 INITLOG_ARGS=""
 36 
 37 # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
 38 # with the thread-based "worker" MPM; BE WARNED that some modules may not
 39 # work correctly with a thread-based MPM; notably PHP will refuse to start.
 40 
 41 # Path to the apachectl script, server binary, and short-form for messages.
 42 apachectl=/usr/local/apache249/bin/apachectl
 43 httpd=${HTTPD-/usr/local/apache249/bin/httpd}
 44 prog=httpd
 45 pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
 46 lockfile=${LOCKFILE-/var/lock/subsys/httpd}
 47 RETVAL=0
 48 STOP_TIMEOUT=${STOP_TIMEOUT-10}
 49 
 50 # The semantics of these two functions differ from the way apachectl does
 51 # things -- attempting to start while running is a failure, and shutdown
 52 # when not running is also a failure.  So we just do it the way init scripts
 53 # are expected to behave here.
 54 start() {
 55         echo -n $"Starting $prog: "
 56         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
 57         RETVAL=$?
 58         echo
 59         [ $RETVAL = 0 ] && touch ${lockfile}
 60         return $RETVAL
 61 }
 62 
 63 # When stopping httpd, a delay (of default 10 second) is required
 64 # before SIGKILLing the httpd parent; this gives enough time for the
 65 # httpd parent to SIGKILL any errant children.
 66 stop() {
 67     echo -n $"Stopping $prog: "
 68     killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
 69     RETVAL=$?
 70     echo
 71     [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
 72 }
 73 reload() {
 74     echo -n $"Reloading $prog: "
 75     if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
 76         RETVAL=6
 77         echo $"not reloading due to configuration syntax error"
 78         failure $"not reloading $httpd due to configuration syntax error"
 79     else
 80         # Force LSB behaviour from killproc
 81         LSB=1 killproc -p ${pidfile} $httpd -HUP
 82         RETVAL=$?
 83         if [ $RETVAL -eq 7 ]; then
 84             failure $"httpd shutdown"
 85         fi
 86     fi
 87     echo
 88 }
 89 
 90 # See how we were called.
 91 case "$1" in
 92   start)
 93     start
 94     ;;
 95   stop)
 96     stop
 97     ;;
 98   status)
 99         status -p ${pidfile} $httpd
100     RETVAL=$?
101     ;;
102   restart)
103     stop
104     start
105     ;;
106   condrestart|try-restart)
107     if status -p ${pidfile} $httpd >&/dev/null; then
108         stop
109         start
110     fi
111     ;;
112   force-reload|reload)
113         reload
114     ;;
115   graceful|help|configtest|fullstatus)
116     $apachectl $@
117     RETVAL=$?
118     ;;
119   *)
120     echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
121     RETVAL=2
122 esac
123 
124 exit $RETVAL
View Code
/etc/httpd249/httpd.conf

#####主要修改部分如下
#PidFile /var/run/httpd/httpd.pid
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#DocumentRoot "/www/nfs"
#ProxyRequests Off
#ProxyPassMatch ^/(.*\.php)$ #fcgi://192.168.31.5:9000/www/nfs/$1
#AddType application/x-httpd-php  .php
#AddType application/x-httpd-php-source  .phps
#<Directory "/www/nfs">
#    Options none
#    AllowOverride None
#    Require all granted
#</Directory>
#<IfModule dir_module>
#    DirectoryIndex index.php index.html
#</IfModule>
  1 # This is the main Apache HTTP server configuration file.  It contains the
  2 # configuration directives that give the server its instructions.
  3 # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
  4 # In particular, see 
  5 # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
  6 # for a discussion of each configuration directive.
  7 #
  8 # Do NOT simply read the instructions in here without understanding
  9 # what they do.  They're here only as hints or reminders.  If you are unsure
 10 # consult the online docs. You have been warned.  
 11 #
 12 # Configuration and logfile names: If the filenames you specify for many
 13 # of the server's control files begin with "/" (or "drive:/" for Win32), the
 14 # server will use that explicit path.  If the filenames do *not* begin
 15 # with "/", the value of ServerRoot is prepended -- so "logs/access_log"
 16 # with ServerRoot set to "/usr/local/apache2" will be interpreted by the
 17 # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" 
 18 # will be interpreted as '/logs/access_log'.
 19 
 20 #
 21 # ServerRoot: The top of the directory tree under which the server's
 22 # configuration, error, and log files are kept.
 23 #
 24 # Do not add a slash at the end of the directory path.  If you point
 25 # ServerRoot at a non-local disk, be sure to specify a local disk on the
 26 # Mutex directive, if file-based mutexes are used.  If you wish to share the
 27 # same ServerRoot for multiple httpd daemons, you will need to change at
 28 # least PidFile.
 29 #
 30 ServerRoot "/usr/local/apache249"
 31 PidFile /var/run/httpd/httpd.pid
 32 #
 33 # Mutex: Allows you to set the mutex mechanism and mutex file directory
 34 # for individual mutexes, or change the global defaults
 35 #
 36 # Uncomment and change the directory if mutexes are file-based and the default
 37 # mutex file directory is not on a local disk or is not appropriate for some
 38 # other reason.
 39 #
 40 # Mutex default:logs
 41 
 42 #
 43 # Listen: Allows you to bind Apache to specific IP addresses and/or
 44 # ports, instead of the default. See also the <VirtualHost>
 45 # directive.
 46 #
 47 # Change this to Listen on specific IP addresses as shown below to 
 48 # prevent Apache from glomming onto all bound IP addresses.
 49 #
 50 #Listen 12.34.56.78:80
 51 Listen 80
 52 
 53 #
 54 # Dynamic Shared Object (DSO) Support
 55 #
 56 # To be able to use the functionality of a module which was built as a DSO you
 57 # have to place corresponding `LoadModule' lines at this location so the
 58 # directives contained in it are actually available _before_ they are used.
 59 # Statically compiled modules (those listed by `httpd -l') do not need
 60 # to be loaded here.
 61 #
 62 # Example:
 63 # LoadModule foo_module modules/mod_foo.so
 64 #
 65 LoadModule authn_file_module modules/mod_authn_file.so
 66 #LoadModule authn_dbm_module modules/mod_authn_dbm.so
 67 #LoadModule authn_anon_module modules/mod_authn_anon.so
 68 #LoadModule authn_dbd_module modules/mod_authn_dbd.so
 69 #LoadModule authn_socache_module modules/mod_authn_socache.so
 70 LoadModule authn_core_module modules/mod_authn_core.so
 71 LoadModule authz_host_module modules/mod_authz_host.so
 72 LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
 73 LoadModule authz_user_module modules/mod_authz_user.so
 74 #LoadModule authz_dbm_module modules/mod_authz_dbm.so
 75 #LoadModule authz_owner_module modules/mod_authz_owner.so
 76 #LoadModule authz_dbd_module modules/mod_authz_dbd.so
 77 LoadModule authz_core_module modules/mod_authz_core.so
 78 LoadModule access_compat_module modules/mod_access_compat.so
 79 LoadModule auth_basic_module modules/mod_auth_basic.so
 80 #LoadModule auth_form_module modules/mod_auth_form.so
 81 #LoadModule auth_digest_module modules/mod_auth_digest.so
 82 #LoadModule allowmethods_module modules/mod_allowmethods.so
 83 #LoadModule file_cache_module modules/mod_file_cache.so
 84 #LoadModule cache_module modules/mod_cache.so
 85 #LoadModule cache_disk_module modules/mod_cache_disk.so
 86 #LoadModule cache_socache_module modules/mod_cache_socache.so
 87 #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
 88 #LoadModule socache_dbm_module modules/mod_socache_dbm.so
 89 #LoadModule socache_memcache_module modules/mod_socache_memcache.so
 90 #LoadModule macro_module modules/mod_macro.so
 91 #LoadModule dbd_module modules/mod_dbd.so
 92 #LoadModule dumpio_module modules/mod_dumpio.so
 93 #LoadModule buffer_module modules/mod_buffer.so
 94 #LoadModule ratelimit_module modules/mod_ratelimit.so
 95 LoadModule reqtimeout_module modules/mod_reqtimeout.so
 96 #LoadModule ext_filter_module modules/mod_ext_filter.so
 97 #LoadModule request_module modules/mod_request.so
 98 #LoadModule include_module modules/mod_include.so
 99 LoadModule filter_module modules/mod_filter.so
100 #LoadModule substitute_module modules/mod_substitute.so
101 #LoadModule sed_module modules/mod_sed.so
102 #LoadModule deflate_module modules/mod_deflate.so
103 LoadModule mime_module modules/mod_mime.so
104 LoadModule log_config_module modules/mod_log_config.so
105 #LoadModule log_debug_module modules/mod_log_debug.so
106 #LoadModule logio_module modules/mod_logio.so
107 LoadModule env_module modules/mod_env.so
108 #LoadModule expires_module modules/mod_expires.so
109 LoadModule headers_module modules/mod_headers.so
110 #LoadModule unique_id_module modules/mod_unique_id.so
111 LoadModule setenvif_module modules/mod_setenvif.so
112 LoadModule version_module modules/mod_version.so
113 #LoadModule remoteip_module modules/mod_remoteip.so
114 LoadModule proxy_module modules/mod_proxy.so
115 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
116 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
117 #LoadModule proxy_http_module modules/mod_proxy_http.so
118 LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
119 #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
120 #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
121 #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
122 #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
123 #LoadModule proxy_express_module modules/mod_proxy_express.so
124 #LoadModule session_module modules/mod_session.so
125 #LoadModule session_cookie_module modules/mod_session_cookie.so
126 #LoadModule session_dbd_module modules/mod_session_dbd.so
127 #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
128 #LoadModule ssl_module modules/mod_ssl.so
129 #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
130 #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
131 #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
132 #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
133 LoadModule mpm_event_module modules/mod_mpm_event.so
134 LoadModule unixd_module modules/mod_unixd.so
135 #LoadModule dav_module modules/mod_dav.so
136 LoadModule status_module modules/mod_status.so
137 LoadModule autoindex_module modules/mod_autoindex.so
138 #LoadModule info_module modules/mod_info.so
139 #LoadModule cgid_module modules/mod_cgid.so
140 #LoadModule cgi_module modules/mod_cgi.so
141 #LoadModule dav_fs_module modules/mod_dav_fs.so
142 #LoadModule vhost_alias_module modules/mod_vhost_alias.so
143 #LoadModule negotiation_module modules/mod_negotiation.so
144 LoadModule dir_module modules/mod_dir.so
145 #LoadModule actions_module modules/mod_actions.so
146 #LoadModule speling_module modules/mod_speling.so
147 #LoadModule userdir_module modules/mod_userdir.so
148 LoadModule alias_module modules/mod_alias.so
149 #LoadModule rewrite_module modules/mod_rewrite.so
150 
151 <IfModule unixd_module>
152 #
153 # If you wish httpd to run as a different user or group, you must run
154 # httpd as root initially and it will switch.  
155 #
156 # User/Group: The name (or #number) of the user/group to run httpd as.
157 # It is usually good practice to create a dedicated user and group for
158 # running httpd, as with most system services.
159 #
160 User daemon
161 Group daemon
162 
163 </IfModule>
164 
165 # 'Main' server configuration
166 #
167 # The directives in this section set up the values used by the 'main'
168 # server, which responds to any requests that aren't handled by a
169 # <VirtualHost> definition.  These values also provide defaults for
170 # any <VirtualHost> containers you may define later in the file.
171 #
172 # All of these directives may appear inside <VirtualHost> containers,
173 # in which case these default settings will be overridden for the
174 # virtual host being defined.
175 #
176 
177 #
178 # ServerAdmin: Your address, where problems with the server should be
179 # e-mailed.  This address appears on some server-generated pages, such
180 # as error documents.  e.g. admin@your-domain.com
181 #
182 ServerAdmin [email protected]
183 
184 #
185 # ServerName gives the name and port that the server uses to identify itself.
186 # This can often be determined automatically, but we recommend you specify
187 # it explicitly to prevent problems during startup.
188 #
189 # If your host doesn't have a registered DNS name, enter its IP address here.
190 #
191 #ServerName www.example.com:80
192 
193 #
194 # Deny access to the entirety of your server's filesystem. You must
195 # explicitly permit access to web content directories in other 
196 # <Directory> blocks below.
197 #
198 <Directory />
199     AllowOverride none
200     Require all denied
201 </Directory>
202 
203 #
204 # Note that from this point forward you must specifically allow
205 # particular features to be enabled - so if something's not working as
206 # you might expect, make sure that you have specifically enabled it
207 # below.
208 #
209 
210 #
211 # DocumentRoot: The directory out of which you will serve your
212 # documents. By default, all requests are taken from this directory, but
213 # symbolic links and aliases may be used to point to other locations.
214 #
215 DocumentRoot "/www/nfs"
216 ProxyRequests Off
217 ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.31.5:9000/www/nfs/$1
218 AddType application/x-httpd-php  .php
219 AddType application/x-httpd-php-source  .phps
220 <Directory "/www/nfs">
221     #
222     # Possible values for the Options directive are "None", "All",
223     # or any combination of:
224     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
225     #
226     # Note that "MultiViews" must be named *explicitly* --- "Options All"
227     # doesn't give it to you.
228     #
229     # The Options directive is both complicated and important.  Please see
230     # http://httpd.apache.org/docs/2.4/mod/core.html#options
231     # for more information.
232     #
233     Options none
234     #
235     # AllowOverride controls what directives may be placed in .htaccess files.
236     # It can be "All", "None", or any combination of the keywords:
237     #   AllowOverride FileInfo AuthConfig Limit
238     #
239     AllowOverride None
240 
241     #
242     # Controls who can get stuff from this server.
243     #
244     Require all granted
245 </Directory>
246 
247 <Directory "/usr/local/apache249/htdocs">
248     #
249     # Possible values for the Options directive are "None", "All",
250     # or any combination of:
251     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
252     #
253     # Note that "MultiViews" must be named *explicitly* --- "Options All"
254     # doesn't give it to you.
255     #
256     # The Options directive is both complicated and important.  Please see
257     # http://httpd.apache.org/docs/2.4/mod/core.html#options
258     # for more information.
259     #
260     Options Indexes FollowSymLinks
261 
262     #
263     # AllowOverride controls what directives may be placed in .htaccess files.
264     # It can be "All", "None", or any combination of the keywords:
265     #   AllowOverride FileInfo AuthConfig Limit
266     #
267     AllowOverride None
268 
269     #
270     # Controls who can get stuff from this server.
271     #
272     Require all granted
273 </Directory>
274 
275 #
276 # DirectoryIndex: sets the file that Apache will serve if a directory
277 # is requested.
278 #
279 <IfModule dir_module>
280     DirectoryIndex index.php index.html
281 </IfModule>
282 
283 #
284 # The following lines prevent .htaccess and .htpasswd files from being 
285 # viewed by Web clients. 
286 #
287 <Files ".ht*">
288     Require all denied
289 </Files>
290 
291 #
292 # ErrorLog: The location of the error log file.
293 # If you do not specify an ErrorLog directive within a <VirtualHost>
294 # container, error messages relating to that virtual host will be
295 # logged here.  If you *do* define an error logfile for a <VirtualHost>
296 # container, that host's errors will be logged there and not here.
297 #
298 ErrorLog "logs/error_log"
299 
300 #
301 # LogLevel: Control the number of messages logged to the error_log.
302 # Possible values include: debug, info, notice, warn, error, crit,
303 # alert, emerg.
304 #
305 LogLevel warn
306 
307 <IfModule log_config_module>
308     #
309     # The following directives define some format nicknames for use with
310     # a CustomLog directive (see below).
311     #
312     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
313     LogFormat "%h %l %u %t \"%r\" %>s %b" common
314 
315     <IfModule logio_module>
316       # You need to enable mod_logio.c to use %I and %O
317       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
318     </IfModule>
319 
320     #
321     # The location and format of the access logfile (Common Logfile Format).
322     # If you do not define any access logfiles within a <VirtualHost>
323     # container, they will be logged here.  Contrariwise, if you *do*
324     # define per-<VirtualHost> access logfiles, transactions will be
325     # logged therein and *not* in this file.
326     #
327     CustomLog "logs/access_log" common
328 
329     #
330     # If you prefer a logfile with access, agent, and referer information
331     # (Combined Logfile Format) you can use the following directive.
332     #
333     #CustomLog "logs/access_log" combined
334 </IfModule>
335 
336 <IfModule alias_module>
337     #
338     # Redirect: Allows you to tell clients about documents that used to 
339     # exist in your server's namespace, but do not anymore. The client 
340     # will make a new request for the document at its new location.
341     # Example:
342     # Redirect permanent /foo http://www.example.com/bar
343 
344     #
345     # Alias: Maps web paths into filesystem paths and is used to
346     # access content that does not live under the DocumentRoot.
347     # Example:
348     # Alias /webpath /full/filesystem/path
349     #
350     # If you include a trailing / on /webpath then the server will
351     # require it to be present in the URL.  You will also likely
352     # need to provide a <Directory> section to allow access to
353     # the filesystem path.
354 
355     #
356     # ScriptAlias: This controls which directories contain server scripts. 
357     # ScriptAliases are essentially the same as Aliases, except that
358     # documents in the target directory are treated as applications and
359     # run by the server when requested rather than as documents sent to the
360     # client.  The same rules about trailing "/" apply to ScriptAlias
361     # directives as to Alias.
362     #
363     ScriptAlias /cgi-bin/ "/usr/local/apache249/cgi-bin/"
364 
365 </IfModule>
366 
367 <IfModule cgid_module>
368     #
369     # ScriptSock: On threaded servers, designate the path to the UNIX
370     # socket used to communicate with the CGI daemon of mod_cgid.
371     #
372     #Scriptsock cgisock
373 </IfModule>
374 
375 #
376 # "/usr/local/apache249/cgi-bin" should be changed to whatever your ScriptAliased
377 # CGI directory exists, if you have that configured.
378 #
379 <Directory "/usr/local/apache249/cgi-bin">
380     AllowOverride None
381     Options None
382     Require all granted
383 </Directory>
384 
385 <IfModule mime_module>
386     #
387     # TypesConfig points to the file containing the list of mappings from
388     # filename extension to MIME-type.
389     #
390     TypesConfig /etc/httpd249/mime.types
391 
392     #
393     # AddType allows you to add to or override the MIME configuration
394     # file specified in TypesConfig for specific file types.
395     #
396     #AddType application/x-gzip .tgz
397     #
398     # AddEncoding allows you to have certain browsers uncompress
399     # information on the fly. Note: Not all browsers support this.
400     #
401     #AddEncoding x-compress .Z
402     #AddEncoding x-gzip .gz .tgz
403     #
404     # If the AddEncoding directives above are commented-out, then you
405     # probably should define those extensions to indicate media types:
406     #
407     AddType application/x-compress .Z
408     AddType application/x-gzip .gz .tgz
409 
410     #
411     # AddHandler allows you to map certain file extensions to "handlers":
412     # actions unrelated to filetype. These can be either built into the server
413     # or added with the Action directive (see below)
414     #
415     # To use CGI scripts outside of ScriptAliased directories:
416     # (You will also need to add "ExecCGI" to the "Options" directive.)
417     #
418     #AddHandler cgi-script .cgi
419 
420     # For type maps (negotiated resources):
421     #AddHandler type-map var
422 
423     #
424     # Filters allow you to process content before it is sent to the client.
425     #
426     # To parse .shtml files for server-side includes (SSI):
427     # (You will also need to add "Includes" to the "Options" directive.)
428     #
429     #AddType text/html .shtml
430     #AddOutputFilter INCLUDES .shtml
431 </IfModule>
432 
433 #
434 # The mod_mime_magic module allows the server to use various hints from the
435 # contents of the file itself to determine its type.  The MIMEMagicFile
436 # directive tells the module where the hint definitions are located.
437 #
438 #MIMEMagicFile /etc/httpd249/magic
439 
440 #
441 # Customizable error responses come in three flavors:
442 # 1) plain text 2) local redirects 3) external redirects
443 #
444 # Some examples:
445 #ErrorDocument 500 "The server made a boo boo."
446 #ErrorDocument 404 /missing.html
447 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
448 #ErrorDocument 402 http://www.example.com/subscription_info.html
449 #
450 
451 #
452 # MaxRanges: Maximum number of Ranges in a request before
453 # returning the entire resource, or one of the special
454 # values 'default', 'none' or 'unlimited'.
455 # Default setting is to accept 200 Ranges.
456 #MaxRanges unlimited
457 
458 #
459 # EnableMMAP and EnableSendfile: On systems that support it, 
460 # memory-mapping or the sendfile syscall may be used to deliver
461 # files.  This usually improves server performance, but must
462 # be turned off when serving from networked-mounted 
463 # filesystems or if support for these functions is otherwise
464 # broken on your system.
465 # Defaults: EnableMMAP On, EnableSendfile Off
466 #
467 #EnableMMAP off
468 #EnableSendfile on
469 
470 # Supplemental configuration
471 #
472 # The configuration files in the /etc/httpd249/extra/ directory can be 
473 # included to add extra features or to modify the default configuration of 
474 # the server, or you may simply copy their contents here and change as 
475 # necessary.
476 
477 # Server-pool management (MPM specific)
478 #Include /etc/httpd249/extra/httpd-mpm.conf
479 
480 # Multi-language error messages
481 #Include /etc/httpd249/extra/httpd-multilang-errordoc.conf
482 
483 # Fancy directory listings
484 #Include /etc/httpd249/extra/httpd-autoindex.conf
485 
486 # Language settings
487 #Include /etc/httpd249/extra/httpd-languages.conf
488 
489 # User home directories
490 #Include /etc/httpd249/extra/httpd-userdir.conf
491 
492 # Real-time info on requests and configuration
493 #Include /etc/httpd249/extra/httpd-info.conf
494 
495 # Virtual hosts
496 #Include /etc/httpd249/extra/httpd-vhosts.conf
497 
498 # Local access to the Apache HTTP Server Manual
499 #Include /etc/httpd249/extra/httpd-manual.conf
500 
501 # Distributed authoring and versioning (WebDAV)
502 #Include /etc/httpd249/extra/httpd-dav.conf
503 
504 # Various default settings
505 #Include /etc/httpd249/extra/httpd-default.conf
506 
507 # Configure mod_proxy_html to understand HTML4/XHTML1
508 <IfModule proxy_html_module>
509 Include /etc/httpd249/extra/proxy-html.conf
510 </IfModule>
511 
512 # Secure (SSL/TLS) connections
513 #Include /etc/httpd249/extra/httpd-ssl.conf
514 #
515 # Note: The following must must be present to support
516 #       starting without SSL on platforms with no /dev/random equivalent
517 #       but a statically compiled-in mod_ssl.
518 #
519 <IfModule ssl_module>
520 SSLRandomSeed startup builtin
521 SSLRandomSeed connect builtin
522 </IfModule>
523 #
524 # uncomment out the below to deal with user agents that deliberately
525 # violate open standards by misusing DNT (DNT *must* be a specific
526 # end-user choice)
527 #
528 #<IfModule setenvif_module>
529 #BrowserMatch "MSIE 10.0;" bad_DNT
530 #</IfModule>
531 #<IfModule headers_module>
532 #RequestHeader unset DNT env=bad_DNT
533 #</IfModule>
View Code

  使用ssh同步两台主机上的系统服务脚本与主配置文件

scp httpd249 root@192.168.31.2:/etc/init.d/httpd249
scp httpd249 root@192.168.31.3:/etc/init.d/httpd249
scp httpd.conf root@192.168.31.2:/etc/httpd249/httpd.conf
scp httpd.conf root@192.168.31.3:/etc/httpd249/httpd.conf

  安装、配置NFS服务器:

yum install -y nfs-utils portmap
mkdir -pv /www/nfs
echo '/www/nfs 192.168.31.0/24(rw,all_squash,anonuid=501,anongid=501)' > /etc/exports
service rpcbind start
service nfs start

  安装、配置php-fcgi与Xcache服务器:

install_php.sh
 1 declare phpDir=/usr/local/php
 2 declare tempDir=`mktemp -d` 
 3 
 4 chmod 700 $tempDir ; chown root:root $tempDir ; cd $tempDir 
 5 
 6 hwclock -s
 7 yum repolist all;echo $?
 8 if ! yum grouplist
 9 then
10   echo "yum repo error:disabled :("
11   exit 1
12 fi
13 #pcre-devel
14 yum install -y gcc*
15 yum groupinstall -y 'Desktop Platform Development'
16 #yum groupinstall -y 'Additional Development'
17 yum groupinstall -y 'Development tools'
18 yum groupinstall -y 'Server Platform Development'
19 yum install -y openssl*
20 yum install -y bzip2-devel
21 
22 wget http://192.168.31.98/tarball/php-5.4.19.tar.bz2
23 wget http://192.168.31.98/tarball/xcache-3.0.3.tar.bz2
24 
25 tar xf php-5.4.19.tar.bz2
26 tar xf xcache-3.0.3.tar.bz2
27 
28 cd php-5.4.19
29 
30 ./configure --prefix=$phpDir --with-openssl --with-mysql=mysqlnd --enable-mbstring \
31         --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir \
32         --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets \
33         --enable-fpm   --with-config-file-path=/etc/php.ini \
34         --with-config-file-scan-dir=/etc/php.d --with-bz2
35         ##--with-mcrypt
36 make 
37 make install
38 /bin/cp -f php.ini-production /etc/php.ini
39 /bin/cp -f sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
40 chmod +x /etc/rc.d/init.d/php-fpm
41 chkconfig --add php-fpm
42 #chkconfig php-fpm on
43 /bin/cp -f $phpDir/etc/php-fpm.conf.default $phpDir/etc/php-fpm.conf
44 
45 cd ../xcache-3.0.3
46 $phpDir/bin/phpize
47 ./configure --enable-xcache --with-php-config=$phpDir/bin/php-config
48 make && make install
49 
50 
51 mkdir /etc/php.d
52 cp xcache.ini /etc/php.d
53 
54 cd
55 
56 rm -fr $tempDir 

  在192.168.31.5机器上执行php-fcgi与Xcache的安装脚本 

  配置php fpm(即fcgi服务的参数):

vim /usr/local/php/etc/php-fpm.conf
######
listen = 9000
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid 
######
:wq

  启动面向整个网络的php-fcgi服务:  

service php-fpm start
ss -tlnp | grep php-fpm

  安装、配置MySQL数据库服务器:

mkdir -pv /mysql/data1
###new LVM
pvcreate -y /dev/sdc
vgcreate -s 16M mysqlvg /dev/sdc
vgchange -a y mysqlvg
lvcreate -L 8192M -n lv1 mysqlvg
mkfs -t ext4 /dev/mysqlvg/lv1
mount /dev/mysqlvg/lv1 /mysql/data1
vi /etc/fstab     
#/dev/mysqlvg/lv1        /mysql/data1/           ext4    defaults        1 2
:wq
df -TH
###mysql user
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin -M -d /mysql/data1 mysql
chown -R mysql:mysql /mysql/data1
###
cd /usr/local
wget http://192.168.31.98/tarball/mysql-5.5.33-linux2.6-x86_64.tar.gz
tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz
ln -sv mysql-5.5.33-linux2.6-x86_64 mysql
rm -f mysql-5.5.33-linux2.6-x86_64.tar.gz cd mysql
chown -R mysql:mysql . scripts/mysql_install_db --user=mysql --datadir=/mysql/data1 chown -R root . cp support-files/my-large.cnf /etc/my.cnf vim /etc/my.cnf #thread_concurrency = 2 #CPUs*2 #datadir = /mydata/data #:wq cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld cd
#配置PATH...
#配置ldconfig...
#配置man...
#配置头文件... service mysqld start mysql

  本地登入MySQL,新建一数据库供WEB服务使用,并授权给php-fcgi服务器。

###快速新建、授权
USE mysql;
SELECT user,host,password from user;
UPDATE user SET password=PASSWORD('yunfeng') WHERE user='root';
CREATE DATABASE IF NOT EXISTS web_db1;
GRANT ALL PRIVILEGES ON web_db1.* TO 'web'@'192.168.31.5' IDENTIFIED BY 'yunfeng';
FLUSH PRIVILEGES;

 全局配置、启动:

  在主机192.168.31.98上,我们将使用文章《使用ssh client与bash scripts轻松管理多台主机》中所开发的工具,对所有主机进行管理。

vim SlaveServer.conf
#glServerList="192.168.31.2 \
#              192.168.31.3  \
#               192.168.31.4  \
#               192.168.31.5  \
#               192.168.31.6  \
#               192.168.31.98"        
#:wq
bash RSAPublicKeyBroadCast.sh 3198 #建立公钥认证环境
bash CommandBroadCast.sh 3198 'mkdir -pv /www/nfs'
bash CommandBroadCast.sh 3198 'yum install -y nfs-utils portmap'
bash CommandBroadCast.sh 3198 'mount 192.168.31.4:/www/nfs /www/nfs'
###这里如果我们使用并行的方式效果会更好 以后我们会更新这个工具的功能
echo "nice to meet you :)" > /www/nfs/index.html
vim /www/nfs/index.php
<html>
                        <head>
                                <title>Php Test Page</title>
                        </head>
                        <body>
                                <h1> modular php </h1>
                                <?php
                                        phpinfo();
                                ?>
                        </body>
</html>
#:wq
ssh -p 3198 root@192.168.31.2 "/etc/init.d/httpd249 start"
ssh -p 3198 root@192.168.31.3 "/etc/init.d/httpd249 start"

  现在我们的系统已经运行起来,接下来更进一步。

  配置、安装WordPress:

cd /www/nfs
mkdir wdp
wget http://192.168.31.98/tarball/wordpress-3.3.1-zh_CN.zip
unzip wordpress-3.3.1-zh_CN.zip
mv wordpress-3.3.1-zh_CN.zip/* wdp/
rm -fr wordpress*
cd wdp
cp wp-config-sample.php wp-config.php
vim wp-config.php 
###
define('DB_NAME', 'web_db1');
define('DB_USER', 'web');
define('DB_PASSWORD', 'yunfeng');
define('DB_HOST', '192.168.31.6');
###
:wq

  现在使用浏览器访问http://192.168.31.2/wdp/或者http://192.168.31.3/wdp/进行初始化WordPress吧!

附录:

  我们的系统:

构建一个分布的LAMP系统_第2张图片  放在192.168.31.98服务器上的公开程序包数据:

构建一个分布的LAMP系统_第3张图片  浏览器访问结果:

构建一个分布的LAMP系统_第4张图片

 

构建一个分布的LAMP系统_第5张图片

  WordPress:

构建一个分布的LAMP系统_第6张图片   

   由于时间仓促,文章有几分凌乱。如有不清晰或者错误的地方,欢迎讨论!

 

 

 

你可能感兴趣的:(lamp)