Lab Environment:
Centos7_64
Experimental objective: To implement the source code installation under Centos7 nginx+mariadb+memcache+php are the latest version--2015.10.10
First, to resolve the dependency relationship
Yum install-y openssl-devel pcre-devel cmake
Second, install Nginx
Groupadd-r Nginx
Useradd-r-G Nginx
TAR-ZXVF nginx-1.9.5.tar.gz
CD nginx-1.9.5
./configure--prefix=/usr--sbin-path=/usr/sbin/nginx--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/ Nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx/nginx.pid--lock-path=/var/ Locak/nginx.lock--user=nginx--group=nginx--with-http_ssl_module--with-http_flv_module--with-http_gzip_static_ Module--http-client-body-temp-path=/var/tmp/nginx/client--http-proxy-temp-path=/var/tmp/nginx/proxy-- http-fastcgi-temp-path=/var/tmp/nginx/fcgi--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi--http-scgi-temp-path=/ var/tmp/nginx/scgi
Make && make install
To add a startup script
Vim/etc/rc.d/init.d/nginx
#!/bin/sh
#
# Nginx-this script starts and stops the Nginx daemon
#
# Chkconfig:-85 15
# Description:nginx is an HTTP (s) server, HTTP (s) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname:nginx
# config:/etc/nginx/nginx.conf
# config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source Networking configuration.
. /etc/sysconfig/network
# Check that networking are up.
["$NETWORKING" = "no"] && exit 0
nginx= "/usr/sbin/nginx"
prog=$ (basename $nginx)
Nginx_conf_file= "/etc/nginx/nginx.conf"
[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx
Lockfile=/var/lock/subsys/nginx
Make_dirs () {
# Make required Directories
User= ' Nginx-v 2>&1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-'
Options= ' $nginx-v 2>&1 | grep ' Configure arguments: '
for opt in $options; Do
If [' Echo $opt | grep '. *-temp-path ']; Then
Value= ' echo $opt | Cut-d "="-F 2 '
if [!-D "$value"]; Then
# echo "Creating" $value
Mkdir-p $value && chown-r $user $value
Fi
Fi
Done
}
Start () {
[-X $nginx] | | Exit 5
[-F $NGINX _conf_file] | | Exit 6
Make_dirs
Echo-n $ "Starting $prog:"
Daemon $nginx-C $NGINX _conf_file
Retval=$?
Echo
[$retval-eq 0] && Touch $lockfile
Return $retval
}
Stop () {
Echo-n $ "Stopping $prog:"
Killproc $prog-quit
Retval=$?
Echo
[$retval-eq 0] && rm-f $lockfile
Return $retval
}
Restart () {
Configtest | | Return $?
Stop
Sleep 1
Start
}
Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
Killproc $nginx-hup
Retval=$?
Echo
}
Force_reload () {
Restart
}
Configtest () {
$nginx-T-C $NGINX _conf_file
}
Rh_status () {
Status $prog
}
Rh_status_q () {
Rh_status >/dev/null 2>&1
}
Case "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
Esac
Add Execute Permissions chmod +x/etc/init.d/nginx
Chkconfig--add nginx && chkconfig nginx on
1. Compile and install MARIADB
Yum-y Install Ncurses-devel
Mkdir-p/mydata/data
Groupadd-r MySQL
Useradd-r-G MySQL mysql-s/sbin/nologin-m-d/mydata/data
TAR-ZXVF mariadb-10.1.7.tar.gz
CD mariadb-10.1.7
CMake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/mydata/data-dsysconfdir=/etc-dwith_innobase_storage_ Engine=1-dwith_archive_storage_engine=1-dwith_blackhole_storage_engine=1-dwith_readline=1-dwith_ssl=system- dwith_zlib=system-dwith_libwrap=0-dmysql_unix_addr=/tmp/mysql.sock-ddefault_charset=utf8-ddefault_collation= Utf8_general_ci
Make && make install
2. Change directory Permissions
Cd/usr/local/mysql
Chown-r mysql.mysql./*
3. Add service startup script
CP Support-files/mysql.server/etc/rc.d/init.d/mysqld
chmod +x/etc/rc.d/init.d/mysqld
Chkconfig--add mysqld && chkconfig mysqld on
4. Modify the configuration file
CP SUPPORT-FILES/MY-LARGE.CNF/ETC/MY.CNF
5. Add Database storage Path
# VIM/ETC/MY.CNF
DataDir =/mydata/data
6. Initialize the database
# scripts/mysql_install_db--user=mysql--datadir=/mydata/data/
7. Change environment variables, help manuals, library files
# echo "Export path= $PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.sh
# echo "Manpath/usr/local/mysql/man" >>/etc/man.config
# Ln-sv/usr/local/mysql/lib/usr/include/mysql
# source/etc/profile.d/mysql.sh
# Ldconfig
Third, installation Php+xcache
Yum-y Install Libxml2-devel bzip2-devel libcurl-devel
Installation dependencies
TAR-ZXVF libmcrypt-2.5.7.tar.gz
CD libmcrypt-2.5.7
./configure
Make && make install
TAR-JXVF php-5.6.14.tar.bz2
CD php-5.6.14
./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-opensll--enable-fpm--enable-sockets-- ENABLE-SYSVSHM--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-mbstring--with-freetype-dir-- With-jpeg-dir--with-png-dir--with-zlib-dir--with-libxml-dir=/usr--enable-xml--with-mhash--with-mcrypt-- With-config-file-path=/etc--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--with-curl
Make && make install
Provide a configuration file for PHP:
# CP Php.ini-production/etc/php.ini
provides SYSV init script for PHP-FPM and adds it to the list of services:
# CP sapi/fpm/ INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM
# chmod +x/etc/rc.d/init.d/php-fpm
# chkconfig--add php-fpm
# Chkconfig PHP-FPM on
provides configuration file for php-fpm:
# cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/ php-fpm.conf
Edit php-fpm configuration file:
# vim/usr/local/php/etc/php-fpm.conf
Configure the relevant options for FPM to the value you need and enable the PID file (the last line below):
Pm.max_children = pm.start_servers
= 8
Pm.min_spare_servers = 5
Pm.max_spare_servers = ten
pid =/usr /local/php/var/run/php-fpm.pid
The next step is to start php-fpm:
Install XCache for PHP acceleration:
# Tar XF xcache-2.0.0.tar.gz
# CD xcache-2.0.0
#/usr/local/php/bin/phpize
#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config
# Make && make install
At the end of the installation, a line similar to the following appears:
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
Edit PHP.ini, integrate PHP and XCache:
The sample configuration provided by XCache is first imported into the php.ini
# MKDIR/ETC/PHP.D
# CP XCACHE.INI/ETC/PHP.D
Description: The Xcache.ini file is in the XCache source directory.
Next edit/etc/php.d/xcache.ini, locate the line that begins with zend_extension, and modify it to the following line:
Zend_extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
Note: If you have more than one zend_extension line in the php.ini file, make sure that this new row is ranked first.
Restart PHP-FPM
Integrating Nginx and PHP5
To edit/etc/nginx/nginx.conf, enable the following options:
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/scripts$fastcgi_script_name;
Include Fastcgi_params;
}
Edit/etc/nginx/fastcgi_params to change its contents to the following:
Fastcgi_param gateway_interface cgi/1.1;
Fastcgi_param Server_software Nginx;
Fastcgi_param query_string $query _string;
Fastcgi_param request_method $request _method;
Fastcgi_param content_type $content _type;
Fastcgi_param content_length $content _length;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Fastcgi_param script_name $fastcgi _script_name;
Fastcgi_param Request_uri $request _uri;
Fastcgi_param Document_uri $document _uri;
Fastcgi_param document_root $document _root;
Fastcgi_param server_protocol $server _protocol;
Fastcgi_param remote_addr $remote _addr;
Fastcgi_param remote_port $remote _port;
Fastcgi_param server_addr $server _addr;
Fastcgi_param server_port $server _port;
Fastcgi_param server_name $server _name;
and add a PHP-formatted home page in the supported master page format, similar to the following:
Location/{
root HTML;
Index index.php index.html index.htm;
}
Then re-load the Nginx configuration
/etc/init.d/nginx Reload or
Systemctl Reload Nginx
Test the connection to the database
<?php
$link = mysql_connect (' 192.168.2.136 ', ' weyner ', ' CentOS ');
if (! $link) {
Die (' Could not connect: '. Mysql_error ());
}
Else
echo "Success ...";
Mysql_close ();
Phpinfo ();
?>
Installing memcached
1. Compile and install
# TAR-ZXVF Memcached-1.4.22.tar.gz
# CD memcached-1.4.22
#./configure--prefix=/usr/local/memcached
# Make && make install
2. Update binaries, help documents, library files
# echo "Export path= $PATH:/usr/local/memcached/bin" >/etc/profile.d/memcached
# echo "Manpath/usr/local/memcached/share/man" >>/etc/man.config
# Ln-sv/usr/local/memcached/include/memcached/usr/include/memcache
3. Provide service script for memcached
#!/bin/bash
#
# Init file for memcached
#
# Chkconfig:-86 14
# description:distributed Memory Caching daemon
#
# processname:memcached
# config:/etc/sysconfig/memcached
. /etc/rc.d/init.d/functions
# # Default Variables
Port= "11211"
User= "Nobody"
maxconn= "1024"
Cachesize= "64"
Options= ""
Retval=0
Prog= "/usr/local/memcached/bin/memcached"
desc= "Distributed Memory Caching"
Lockfile= "/var/lock/subsys/memcached"
Start () {
Echo-n $ "Starting $desc (memcached):"
Daemon $prog-D-P $PORT-U $USER-C $MAXCONN-M $CACHESIZE
Retval=$?
[$RETVAL-eq 0] && success && Touch $lockfile | | Failure
Echo
Return $RETVAL
}
Stop () {
Echo-n $ "Shutting down $desc (memcached):"
Killproc $prog
Retval=$?
[$RETVAL-eq 0] && success && Rm-f $lockfile | | Failure
Echo
Return $RETVAL
}
Restart () {
Stop
Start
}
Reload () {
Echo-n $ "Reloading $desc ($prog):"
Killproc $prog-hup
Retval=$?
[$RETVAL-eq 0] && Success | | Failure
Echo
Return $RETVAL
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
Condrestart)
[-e $lockfile] && restart
Retval=$?
;;
Reload
Reload
;;
Status
Status $prog
Retval=$?
;;
*)
echo $ "Usage: $ {Start|stop|restart|condrestart|status}"
Retval=1
Esac
Exit $RETVAL
4. Add to boot from boot
# chmod +x/etc/init.d/memcached
# chkconfig--add memcached
#/etc/init.d/memcached Start
Installing PHP's Memcache extension
# wget Http://pecl.php.net/get/memcache-2.2.7.tgz
# TAR-ZXVF Memcache-2.2.7.tgz
# CD memcache-2.2.7
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config--enable-memcache
# Make && make install
Edit/etc/php.ini, add the following line to load the memcache extension in the location associated with the dynamic module
Extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so
Provide a test page
#vim/usr/html/test.php
<?php
$mem = new Memcache;
$mem->connect ("192.168.2.136", 11211) or Die ("Could not Connect");
$version = $mem->getversion ();
echo "Server ' s version:". $version. " <br/>\n ";
$mem->set (' Hellokey ', ' Hello World ', 0, +) or Die ("Failed-to-save data at the memcached server");
echo "Store data in the cache (data would expire in seconds) <br/>\n";
$get _result = $mem->get (' Hellokey ');
echo "$get _result is from memcached server.";
?>
~
Performance monitoring
# wget http://www.junopen.com/memadmin/memadmin-1.0.12.tar.gz
# TAR-ZXVF Memadmin-1.0.12.tar.gz-c/usr/html/
can open try Http://192.168.2.136/memadmin
Nginx Index Directory Configuration
# vim/etc/nginx/nginx.conf
Location ~ ^/iso (/.*)
{
AutoIndex on;
Autoindex_localtime on;
}
LNMMP Environment Construction under CENTOS7