Centos 6.5 配置分离式LAMP平台环境 多服务器编译安装Apache2.4.x PHP5.4.x MariaDB5.5.x

这次LAMP环境才去多服务器方式,apache部署在一台服务器上 PHP部署在一台服务器上 MariaDB部署在一台服务器上。 测试OS:Centos 6.5 x86_64 软件版本:apache 2.4.x php5.4.x MariaDB 5.5.x 网络环境:

[root@LookBack163 ~]# ifconfig eth0 | awk -F‘[ :]+‘ ‘/inet addr/{print$4}‘
172.16.41.163   ###httpd服务器

[root@LookBack164 ~]# ifconfig eth0 | awk -F‘[ :]+‘ ‘/inet addr/{print$4}‘
172.16.41.164   ###php服务器

[root@LookBack165 ~]# ifconfig eth0 | awk -F‘[ :]+‘ ‘/inet addr/{print$4}‘
172.16.41.165   ###mysql服务器

一、部署httpd服务器

1、编译安装apache

[root@LookBack163 ~]# yum groupinstall "Development tools" -y
[root@LookBack163 ~]# yum groupinstall "Server Platform Development" -y
[root@LookBack163 ~]# yum install pcre-devel vim tree screen htop -y
[root@LookBack163 ~]# tar xf apr-1.5.1.tar.gz
[root@LookBack163 ~]# tar xf apr-util-1.5.3.tar.bz2
[root@LookBack163 ~]# cd apr-1.5.1
[root@LookBack163 apr-1.5.1]# ./configure --prefix=/usr/local/apr151
[root@LookBack163 apr-1.5.1]# make -j4 && make install
[root@LookBack163 apr-1.5.1]# cd ../apr-util-1.5.3
[root@LookBack163 apr-util-1.5.3]# ./configure --prefix=/usr/local/aprutil153 --with-apr=/usr/local/apr151/
[root@LookBack163 apr-util-1.5.3]# make -j4 && make install && cd ~
[root@LookBack163 ~]# tar xf httpd-2.4.10.tar.bz2
[root@LookBack163 ~]# cd httpd-2.4.10
[root@LookBack163 httpd-2.4.10]# ./configure --prefix=/usr/local/apache2410 --sysconfdir=/etc/httpd2410 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr151/ --with-apr-util=/usr/local/aprutil153/ --enable-mpms-shared=all --with-mpm=event --enable-modules=most
[root@LookBack163 httpd-2.4.10]# make -j4 && make install && cd ~
[root@LookBack163 ~]# echo "export PATH=/usr/local/apache2410/bin/:\$PATH" > /etc/profile.d/apache2410.sh
[root@LookBack163 ~]# sed -i "$(cat /etc/man.config | grep -nE ‘^MANPATH[[:space:]]+‘ | tail -1 | awk -F: ‘{print$1}‘)a \MANPATH\tMANPATH /usr/local/apache2410/man" /etc/man.config
[root@LookBack163 ~]# ln -s /usr/local/apache2410/include/ /usr/include/apache

2、配置httpd下面是/etc/httpd2410/httpd.conf 配置文件内容

[root@LookBack163 ~]# httpdDir="/etc/httpd2410/httpd.conf"
[root@LookBack163 ~]# sed -ri ‘s@(^[[:space:]]+DirectoryIndex)( index.html)@\1 index.php\2@‘ $httpdDir
##上一行命令是在 DirectoryIndex index.html行中添加一个index.php

[root@LookBack163 ~]# sed -ri "/$(grep -E "^[[:space:]]+AddType" $httpdDir | tail -1 | sed ‘s@/@\\&@‘)/a \\\tAddType application/x-httpd-php .php" !$
##在配置文件中添加 AddType application/x-httpd-php .php

[root@LookBack163 ~]# sed -ri "/$(grep -E "^[[:space:]]+AddType" $httpdDir | tail -1 | sed ‘s@/@\\&@‘)/a \\\tAddType application/x-httpd-php-source .phps" !$
##在配置文件中添加 AddType application/x-httpd-php-source .phps

[root@LookBack163 ~]# sed -i "s@^ServerRoot .*@#&@" !$
##这一条命令视情况是否执行,如果后面创建虚拟机主机就执行吧,作用是取消 ServerRoot行的配置

[root@LookBack163 ~]# sed -i "/^Listen 80/a \#Listen 443" !$
##这条命令可以忽视

[root@LookBack163 ~]# sed -ri "s@^#(Include /etc/httpd2410/extra/httpd-vhosts.conf)@\1@" !$
##这条是启动虚拟机主机并指定虚拟主机配置文件为 /etc/httpd2410/extra/httpd-vhosts.conf(配置文件是编译安装apache默认的位置,不建议修改)

[root@LookBack163 ~]# sed -ri "s@^#(Include /etc/httpd2410/extra/httpd-ssl.conf)@\1@" !$
##启用SSL功能 指定SSL配置文件在/etc/httpd2410/extra/httpd-ssl.conf(配置文件是编译安装apache默认的位置,不建议修改)

[root@LookBack163 ~]# sed -ri "s@^#(LoadModule ssl_module modules/mod_ssl.so)@\1@" !$
##启用SSL模块

[root@LookBack163 ~]# sed -ri "s@^#(LoadModule socache_shmcb_module modules/mod_socache_shmcb.so)@\1@" !$
##启用socache_shmcb模块

[root@LookBack163 ~]# sed -ri "s@^#(LoadModule proxy_module .*)@\1@" !$
##启用proxy_module模块

[root@LookBack163 ~]# sed -ri "s@^#(LoadModule proxy_fcgi_module.*)@\1@" !$
##启用proxy_fcgi_module模块

[root@LookBack163 ~]# sed -ri "s@^#(LoadModule rewrite_module modules/mod_rewrite.so)@\1@" !$
##启用rewrite_module模块

[root@LookBack163 ~]# ####sed -i "/^DocumentRoot.*/a \ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.41.164:9000/home/wwwroot/www.05hd.com\$1" !$
[root@LookBack163 ~]# ####sed -i "/^DocumentRoot.*/a \ProxyRequests Off" !$
####上面两行配置文件修改的命令根据自己的情况看是否执行,
####如果apache不创建虚拟主机那么就必须要执行,如果创建虚拟机主机就根据自己实际情况来确认是否执行

[root@LookBack163 ~]# sed -i "s@^DocumentRoot.*@#&@" !$
##上面这一行命令 视情况是否执行,如果后面需要创建虚拟主机就必须执行,否则必须不执行

[root@LookBack163 ~]# sed -i "s@^PidFile.*@PidFile "/usr/local/apache2410/logs/httpd.pid"@" !$
##修改pid文件路径

[root@LookBack163 ~]# grep ‘^[^#]‘ $httpdDir | grep -vE ‘^[[:space:]]+#‘
PidFile /usr/local/apache2410/logs/httpd.pid
Listen 80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_socache_module modules/mod_authn_socache.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

User daemon
Group daemon

ServerAdmin [email protected]
ServerName LookBack163.05hd.com:80

    AllowOverride none
    Require all denied


    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

    DirectoryIndex index.php index.html

    Require all denied

ErrorLog "logs/error_log"
LogLevel warn

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    
    CustomLog "logs/access_log" common

    ScriptAlias /cgi-bin/ "/usr/local/apache2410/cgi-bin/"

    AllowOverride None
    Options None
    Require all granted

    TypesConfig /etc/httpd2410/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
	AddType application/x-httpd-php .php
	AddType application/x-httpd-php-source .phps

Include /etc/httpd2410/extra/httpd-vhosts.conf
Include /etc/httpd2410/extra/httpd-default.conf

Include /etc/httpd2410/extra/proxy-html.conf

Include /etc/httpd2410/extra/httpd-ssl.conf

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

3、制作httpd启动脚本第一种方法:(推荐)

[root@LookBack163 ~]# for I in $(ps -aux | grep [h]ttp |awk ‘{print$2}‘); do kill -9 $I;done
[root@LookBack163 ~]# for I in $(ps -aux | grep [a]pache |awk ‘{print$2}‘); do kill -9 $I;done
###上2行的命令是强制结束所有httpd的进程
[root@LookBack163 ~]# [ -f /etc/init.d/httpd ] && mv /etc/init.d/httpd /etc/init.d/httpd.bak
[root@LookBack163 ~]# cp /usr/local/apache2410/bin/apachectl /etc/init.d/httpd
[root@LookBack163 ~]# sed -i ‘/#!\/bin\/sh/a \# chkconfig: 35 85 15\n# description: Activates\/Deactivates Apache 2.4.10‘ /etc/init.d/httpd
[root@LookBack163 ~]# chmod +x /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# chkconfig --add httpd
[root@LookBack163 ~]# chkconfig --list httpd
httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@LookBack163 ~]# chkconfig httpd on
[root@LookBack163 ~]# chkconfig --list httpd
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

第二种方法:

[root@LookBack163 ~]# for I in $(ps -aux | grep [h]ttp |awk ‘{print$2}‘); do kill -9 $I;done
[root@LookBack163 ~]# for I in $(ps -aux | grep [a]pache |awk ‘{print$2}‘); do kill -9 $I;done
[root@LookBack163 ~]# [ -f /etc/init.d/httpd ] && mv /etc/init.d/httpd /etc/init.d/httpd.bak
[root@LookBack163 ~]# wget -c4 -O /etc/rc.d/init.d/httpd2410 "http://www.05hd.com/httpd.sh"
[root@LookBack163 ~]# chmod +x /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# sed -ri "s@^# chkconfig.*@# chkconfig: 2345 85 15\n# Default-Start:  2 3 4 5\n# Default-Stop: 0 1 6@" /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# sed -ri "s@^pidfile=.*@pidfile=\${PIDFILE-/usr/local/apache2410/logs/httpd.pid222}@" /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# sed -ri "s@^apachectl=.*@apachectl=/usr/local/apache2410/bin/apachectl111@" /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# sed -ri "s@^httpd=.*@httpd=\${HTTPD-/usr/local/apache2410/bin/httpd}@" /etc/rc.d/init.d/httpd2410
[root@LookBack163 ~]# chkconfig --add httpd
[root@LookBack163 ~]# chkconfig --list httpd
httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@LookBack163 ~]# chkconfig httpd on
[root@LookBack163 ~]# chkconfig --list httpd
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
###下面是启动脚本的源码
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: 2345 85 15
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# description: The Apache HTTP Server is an efficient and extensible  #	       server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /usr/local/apache2410/logs/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
#  implementing the current HTTP standards.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

#if [ -f /etc/sysconfig/httpd ]; then
#        . /etc/sysconfig/httpd
#fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
#apachectl=/usr/sbin/apachectl
apachectl=/usr/local/apache2410/bin/apachectl
httpd=${HTTPD-/usr/local/apache2410/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache2410/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status -p ${pidfile} $httpd
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  condrestart|try-restart)
	if status -p ${pidfile} $httpd >&/dev/null; then
		stop
		start
	fi
	;;
  force-reload|reload)
        reload
	;;
  graceful|help|configtest|fullstatus)
	$apachectl $@
	RETVAL=$?
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
	RETVAL=2
esac

exit $RETVAL

二、配置MariaDB服务器

1、配置一个LV逻辑分区

[root@LookBack165 ~]# fdisk /dev/sda &> /dev/null > /etc/fstab
[root@LookBack165 ~]# mount -a
[root@LookBack165 ~]# mount
/dev/mapper/vg0-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/MYDATA-MYDATAlv on /MYSQLDATA type ext4 (rw)
[root@LookBack165 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/vg0-root          20G  924M   18G   5% /
tmpfs                        935M     0  935M   0% /dev/shm
/dev/sda1                    194M   35M  150M  19% /boot
/dev/mapper/vg0-usr          9.9G  2.4G  7.1G  26% /usr
/dev/mapper/vg0-var           20G  433M   19G   3% /var
/dev/mapper/MYDATA-MYDATAlv   20G  172M   19G   1% /MYSQLDATA

用于MariaDB数据存放的LV分区已经做好了 并且做了开机自动挂载2、配置MariaDB

[root@LookBack165 ~]# groupadd -r mysql
[root@LookBack165 ~]# mkdir /MYSQLDATA/data
[root@LookBack165 ~]# useradd -g mysql -r -s /sbin/nologin -M -d /MYSQLDATA/data mysql
[root@LookBack165 ~]# chown -R mysql:mysql /MYSQLDATA/data/
[root@LookBack165 ~]# wget http://mirrors.hustunique.com/mariadb/mariadb-galera-5.5.38/bintar-centos5-amd64/mariadb-galera-5.5.38-linux-x86_64.tar.gz
[root@LookBack165 ~]# tar xf mariadb-galera-5.5.38-linux-x86_64.tar.gz -C /usr/local
[root@LookBack165 ~]# cd /usr/local/
[root@LookBack165 local]# ls
bin  etc  games  glibc-2.19  include  lib  lib64  libexec  mariadb-galera-5.5.38-linux-x86_64  sbin  share  src
[root@LookBack165 local]# ln -sv mariadb-galera-5.5.38-linux-x86_64/ mariadb
`mariadb‘ -> `mariadb-galera-5.5.38-linux-x86_64/‘   ###`
[root@LookBack165 local]# cd mariadb
[root@LookBack165 mariadb]# chown -R mysql:mysql .

3、初始化MariaDB

[root@LookBack165 mariadb]# pwd
/usr/local/mariadb
[root@LookBack165 mariadb]# scripts/mysql_install_db --user=mysql --datadir=/MYSQLDATA/data/
WARNING: The host ‘LookBack165.05hd.com‘ could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in ‘/MYSQLDATA/data/‘ ...
140813 11:46:44 [Note] WSREP: Read nil XID from storage engines, skipping position init
140813 11:46:44 [Note] WSREP: wsrep_load(): loading provider library ‘none‘
140813 11:46:44 [Note] [Debug] WSREP: dummy_init
140813 11:46:45 [Note] [Debug] WSREP: dummy_disconnect
140813 11:46:45 [Note] WSREP: Service disconnected.
140813 11:46:46 [Note] WSREP: Some threads may fail to exit.
140813 11:46:46 [Note] [Debug] WSREP: dummy_free
OK
Filling help tables...
140813 11:46:46 [Note] WSREP: Read nil XID from storage engines, skipping position init
140813 11:46:46 [Note] WSREP: wsrep_load(): loading provider library ‘none‘
140813 11:46:46 [Note] [Debug] WSREP: dummy_init
140813 11:46:46 [Note] [Debug] WSREP: dummy_disconnect
140813 11:46:46 [Note] WSREP: Service disconnected.
140813 11:46:47 [Note] WSREP: Some threads may fail to exit.
140813 11:46:47 [Note] [Debug] WSREP: dummy_free
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

‘./bin/mysqladmin‘ -u root password ‘new-password‘
‘./bin/mysqladmin‘ -u root -h LookBack165.05hd.com password ‘new-password‘

Alternatively you can run:
‘./bin/mysql_secure_installation‘

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd ‘.‘ ; ./bin/mysqld_safe --datadir=‘/MYSQLDATA/data/‘

You can test the MariaDB daemon with mysql-test-run.pl
cd ‘./mysql-test‘ ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at [email protected]
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

[root@LookBack165 mariadb]# chown -R root  .
[root@LookBack165 mariadb]# ls -l
total 244
drwxr-xr-x  2 root mysql   4096 Jun 25 12:57 bin
-rw-r--r--  1 root mysql  17987 Jun 23 22:14 COPYING
-rw-r--r--  1 root mysql  26545 Jun 23 22:13 COPYING.LESSER
drwxr-xr-x  3 root mysql   4096 Jun 25 12:56 data
drwxr-xr-x  2 root mysql   4096 Jun 25 12:57 docs
-rw-r--r--  1 root mysql   8245 Jun 23 22:13 EXCEPTIONS-CLIENT
drwxr-xr-x  3 root mysql   4096 Jun 25 12:57 include
-rw-r--r--  1 root mysql   8694 Jun 23 22:13 INSTALL-BINARY
drwxr-xr-x  3 root mysql   4096 Jun 25 12:57 lib
drwxr-xr-x  4 root mysql   4096 Jun 25 12:56 man
drwxr-xr-x 11 root mysql   4096 Jun 25 12:57 mysql-test
-rw-r--r--  1 root mysql 110472 Jun 23 22:13 README
-rw-r--r--  1 root mysql  19510 Jun 23 22:13 README-wsrep
drwxr-xr-x  2 root mysql   4096 Jun 25 12:57 scripts
drwxr-xr-x 27 root mysql   4096 Jun 25 12:57 share
drwxr-xr-x  4 root mysql   4096 Jun 25 12:57 sql-bench
drwxr-xr-x  3 root mysql   4096 Jun 25 12:56 support-files

4、编辑MariaDB配置文件

[root@LookBack165 mariadb]# cd /usr/local/mariadb
[root@LookBack165 mariadb]# cp support-files/my-large.cnf  /etc/my.cnf

###并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
###[root@LookBack165 mariadb]# sed -i "@^thread_concurrency.*@thread_concurrency = 2@" /etc/my.cnf###也可以用这个命令直接修改
[root@LookBack165 mariadb]# sed -i "/^thread_concurrency.*/i \datadir = \/MYSQLDATA\/data" /etc/my.cnf

5、配置MariaDB启动脚本等其他配置

[root@LookBack165 mariadb]# cp /usr/local/mariadb/support-files/mysql.server  /etc/rc.d/init.d/mysql
[root@LookBack165 mariadb]# chmod +x /etc/rc.d/init.d/mysql
[root@LookBack165 mariadb]# chkconfig --add mysql
[root@LookBack165 mariadb]# chkconfig --list mysql
mariadb        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@LookBack165 mariadb]# sed -i ‘s@/usr/local/mysql@/usr/local/mariadb@‘ /etc/rc.d/init.d/mysql
[root@LookBack165 mariadb]# service mysql start
Starting MySQL.....                                        [  OK  ]
[root@LookBack165 mariadb]# service mysql stop
Shutting down MySQL.                                       [  OK  ]
[root@LookBack165 mariadb]# sed -i "$(cat /etc/man.config | grep -nE ‘^MANPATH[[:space:]]+‘ | tail -1 | awk -F: ‘{print$1}‘)a MANPATH\t/usr/local/mariadb/man" /etc/man.config
[root@LookBack165 mariadb]# ln -sv /usr/local/mariadb/include  /usr/include/mysql
[root@LookBack165 mariadb]# echo ‘/usr/local/mariadb/lib/‘ > /etc/ld.so.conf.d/mysql.conf
[root@LookBack165 mariadb]# ldconfig
[root@LookBack165 mariadb]# echo "export PATH=/usr/local/mariadb/bin:$PATH" > /etc/profile.d/mariadb5538.sh

三、配置php服务器

1、下载和编译php

[root@LookBack164 ~]# wget http://www.05hd.com/wp-content/uploads/2014/08/php-5.4.31.tar.bz2
[root@LookBack164 ~]# yum groupinstall "Development tools" -y && yum groupinstall "Server Platform Development" -y
[root@LookBack164 ~]# yum install libxml2 libxml2-devel libmcrypt bzip2 bzip2-devel libmcrypt-devel mhash-devel mhash pcre-devel vim tree screen htop -y
[root@LookBack164 ~]# for i in libxml2 bzip2 libmcrypt pcre mhash; do rpm -qa |grep "$i";done
libxml2-2.7.6-14.el6.x86_64
libxml2-python-2.7.6-14.el6.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
bzip2-libs-1.0.5-7.el6_0.x86_64
bzip2-1.0.5-7.el6_0.x86_64
bzip2-devel-1.0.5-7.el6_0.x86_64
libmcrypt-devel-2.5.8-9.el6.x86_64
libmcrypt-2.5.8-9.el6.x86_64
pcre-devel-7.8-6.el6.x86_64
pcre-7.8-6.el6.x86_64
mhash-devel-0.9.9.9-3.el6.x86_64
mhash-0.9.9.9-3.el6.x86_64
[root@LookBack164 ~]# cd php-5.4.31
[root@LookBack164 php-5.4.31]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-mcrypt --enable-fpm  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
[root@LookBack164 php-5.4.31]# make -j4 && make install
###编译参数解释
-prefix=/usr/local/PHP           php 安装目录
--with-apxs2=/usr/local/apache/bin/apxs
--with-config-file-path=/usr/local/PHP/etc   指定php.ini位置
--with-mysql=/usr/local/mysql   mysql安装目录,对mysql的支持
--with-mysqli=/usr/local/mysql/bin/mysql_config    mysql高级访问接口
--with-openssl ;可以支持ssl
--enable-mbstring ;启动多字节字符支持
--with-freetype-dir ;这是让PHP支持GD库的配置选项
--with-jpeg-dir
--with-png-dir
--with-zlib;支持zlib的压缩库
--with-libxml-dir=/usr
--enable-xml ;支持xml格式
--enable-sockets;支持socket方式通信
--with-apxs2=/usr/local/apache/bin/apxs;php针对此接口来编译进apache
--with-mcrypt;支持加密工具
--with-config-file-path=/etc;配置文件文件
--with-config-file-scan-dir=/etc/php.d;找/etc/php.d/下一.ini结尾的文件作为配置文件
--with-bz2
--enable-maintainer-zts;如果MPM为event和worker模型,编译时此处须启用,如果为prefork,它是以mod_php的方式安装的。

2、配置php

[root@LookBack164 php-5.4.31]# cp php.ini-production /etc/php.ini
[root@LookBack164 php-5.4.31]# cp sapi/fpm/init.d.php-fpm.in /etc/rc.d/init.d/php-fpm
[root@LookBack164 php-5.4.31]# chmod +x /etc/rc.d/init.d/php-fpm
[root@LookBack164 php-5.4.31]# chkconfig --add php-fpm
[root@LookBack164 php-5.4.31]# chkconfig --list php-fpm
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@LookBack164 php-5.4.31]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@LookBack164 php-5.4.31]# sed -i ‘s@^pm.max_children.*@pm.max_children = 50@;s@^pm.start_servers.*@pm.start_servers = 5@;s@^pm.min_spare_servers.*@pm.min_spare_servers = 2@;s@^pm.max_spare_servers.*@pm.max_spare_servers = 8@;s@;pid = .*@pid = /usr/local/php/var/run/php-fpm.pid@‘ /usr/local/php/etc/php-fpm.conf
[root@LookBack164 php-5.4.31]# sed -i "s@^listen.*@listen = $(ifconfig eth0 | awk -F‘[ :]+‘ ‘/inet addr/{print$4}‘):9000@" /usr/local/php/etc/php-fpm.conf
[root@LookBack164 php-5.4.31]# cat /usr/local/php/etc/php-fpm.conf | grep -vE ‘^;|^[[:space:]]{0,}$‘
[global]
pid = /usr/local/php/var/run/php-fpm.pid
[www]
user = nobody
group = nobody
listen = 172.16.41.164:9000
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@LookBack164 php-5.4.31]# mkdir -p /home/wwwroot/www.05hd.com
[root@LookBack164 php-5.4.31]# chmod 755 !$
chmod 755 /home/wwwroot/www.05hd.com

下面来启动php-fpm

[root@LookBack164 php-5.4.31]# service php-fpm start
Starting php-fpm  done
[root@LookBack164 php-5.4.31]# ss -tnlp


四、配置具体的web服务

1、配置httpd服务器上虚拟机1.1下面是我的虚拟机配置

[root@LookBack163 ~]# grep ‘^[^#]‘ /etc/httpd2410/extra/httpd-vhosts.conf | grep -vE ‘^[[:space:]]+#‘ServerAdmin [email protected]
    ServerName www1.05hd.com
    DocumentRoot "/web/hosta"
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://172.16.41.164:9000/home/wwwroot/www.05hd.com/$1Require all grantedSetHandler server-status
        Require all grantedErrorLog "logs/www1.05hd.com-error_log"
    CustomLog "logs/www1.05hd.com-access_log" commonServerAdmin [email protected]
    ServerName pam.05hd.com
    DocumentRoot "/web/hosta"
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://172.16.41.164:9000/home/wwwroot/phpmyadmin/$1
    ErrorLog "logs/pam.05hd.com-error_log"
    CustomLog "logs/pam.05hd.com-access_log" commonRequire all granted

1.2我们再去php服务器上弄个测试页面看看效果

[root@LookBack164 php-5.4.31]# cat > /home/wwwroot/www.05hd.com/index.php << EOFIt works! This Is A Test Page
EOF

  再来看看status页面的情况看到这个页面的时候就说明httpd服务器配置OK httpd服务器上虚拟机配置OK php服务器配置OK httpd服务器通过代理的方式让php服务器处理php页面配置OK2、下面我们去MariaDB服务器上做一些配置2.1MariaDB用户创建1、修改root默认空密码为YTJmZjQ5NThiMGNl 2、新建一个可在172.16.41.164连接的root用户 密码为YTJmZjQ5NThiMGNl,且拥有整个MariaDB的全部权限(不推荐使用,这里是在局域网上进行的测试,所以无所谓。)

[root@LookBack165 ~]# service mysql start
Starting MySQL....                                         [  OK  ]
[root@LookBack165 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.38-MariaDB-wsrep-log MariaDB Server, wsrep_25.10.r3997

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> use mysql
Database changed
MariaDB [mysql]> update user set password=password(‘YTJmZjQ5NThiMGNl‘) where user=‘root‘;
Query OK, 4 rows affected (0.07 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON *.* TO ‘root‘@‘172.16.41.164‘ IDENTIFIED BY ‘YTJmZjQ5NThiMGNl‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> \q
Bye
###这里将MariaDB root的密码修改成了YTJmZjQ5NThiMGNl,并且让172.16.41.164服务器有权限连接使用

如果感觉使用root用户不安全可以使用下面的方法 1、修改root默认空密码为YTJmZjQ5NThiMGNl 2、创建一个新用户wpblog 并创建一个与新用户同名的数据库,此用户拥有这个同名数据库的全部权限且设置密码为YTJmZjQ5NThiMGNl,此MariaDB用户只允许来自172.16.41.164的连接

mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.38-MariaDB-wsrep-log MariaDB Server, wsrep_25.10.r3997

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]> use mysql
Database changed
MariaDB [mysql]> update user set password=password(‘YTJmZjQ5NThiMGNl‘) where user=‘root‘;
Query OK, 4 rows affected (0.07 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CREATE USER ‘wpblog‘@‘172.16.41.164‘ IDENTIFIED BY ‘YTJmZjQ5NThiMGNl‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT USAGE ON *.* TO ‘wpblog‘@‘172.16.41.164‘ IDENTIFIED BY ‘***‘ WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;CREATE DATABASE IF NOT EXISTS `wpblog`;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON `wpblog`.* TO ‘wpblog‘@‘172.16.41.164‘;GRANT ALL PRIVILEGES ON `wpblog\_%`.* TO ‘wpblog‘@‘172.16.41.164‘;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> \q
Bye

3、下面我们去httpd服务器上配置用于phpmyadmin的虚拟机3.1配置ca和ssl自签证书

[root@LookBack163 ~]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
............................................................+++
.....+++
e is 65537 (0x10001)

[root@LookBack163 ~]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3650
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:05HD
Organizational Unit Name (eg, section) []:DevOps
Common Name (eg, your name or your server‘s hostname) []:caserver.05hd.com
Email Address []:[email protected]

[root@LookBack163 ~]# touch /etc/pki/CA/{serial,index.txt}
[root@LookBack163 ~]# echo "01" > /etc/pki/CA/serial
[root@LookBack163 ~]# mkdir -p /etc/httpd2410/extra/ssl
[root@LookBack163 ~]# cd /etc/httpd2410/extra/ssl

[root@LookBack163 ssl]# (umask 077; openssl genrsa -out pam.key 1024 )
Generating RSA private key, 1024 bit long modulus
.++++++
.......++++++
e is 65537 (0x10001)

[root@LookBack163 ssl]# ll
total 4
-rw------- 1 root root 887 Aug 13 21:41 pam.key

[root@LookBack163 ssl]# openssl req -new -key pam.key -out pam.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:05HD
Organizational Unit Name (eg, section) []:DevOps
Common Name (eg, your name or your server‘s hostname) []:www.05hd.com
Email Address []:[email protected]

Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

[root@LookBack163 ssl]# openssl ca -in pam.csr -out pam.crt -days 3650
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Aug 13 13:46:38 2014 GMT
            Not After : Aug 10 13:46:38 2024 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = BeiJing
            organizationName          = 05HD
            organizationalUnitName    = DevOps
            commonName                = pam.05hd.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                9D:88:4A:4D:B2:AB:D6:35:53:80:4D:89:D9:4E:C8:01:6B:01:60:50
            X509v3 Authority Key Identifier:
                keyid:9D:BD:DC:D0:CE:0E:EF:C2:9F:E5:CD:DC:F0:97:10:9C:E5:7F:A4:2A

Certificate is to be certified until Aug 10 13:46:38 2024 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

[root@LookBack163 ssl]# pwd
/etc/httpd2410/extra/ssl
[root@LookBack163 ssl]# ls -l
total 12
-rw-r--r-- 1 root root 3843 Aug 13 21:46 pam.crt
-rw-r--r-- 1 root root  688 Aug 13 21:42 pam.csr
-rw------- 1 root root  887 Aug 13 21:41 pam.key

3.2 配置基于ssl的apache虚拟主机下面是我的虚拟主机配置文件内容

[root@LookBack163 ssl]# grep ‘^[^#]‘ /etc/httpd2410/extra/httpd-ssl.conf | grep -vE ‘^[[:space:]]+#‘
Listen 443
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/usr/local/apache2410/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300ServerAdmin [email protected]
    ServerName pam.05hd.com
    DocumentRoot "/web/hosta"
    SSLEngine on
    SSLCertificateFile "/etc/httpd2410/extra/ssl/pam.crt"
    SSLCertificateKeyFile "/etc/httpd2410/extra/ssl/pam.key"
    ProxyRequests Off
    ProxyPassMatch ^/(.*.php)$ fcgi://172.16.41.164:9000/home/wwwroot/phpmyadmin/$1SSLOptions +StdEnvVarsSSLOptions +StdEnvVarsRequire all grantedBrowserMatch "MSIE [2-5]"              nokeepalive ssl-unclean-shutdown              downgrade-1.0 force-response-1.0
    ErrorLog "logs/pam.05hd.com-error_log"
    CustomLog "logs/pam.05hd.com-access_log" common

3.3去php服务器上下载phpmyadmin

[root@LookBack164 wwwroot]# pwd
/home/wwwroot
[root@LookBack164 wwwroot]# wget "http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.7/phpMyAdmin-4.2.7-all-languages.tar.gz/download"
[root@LookBack164 phpmyadmin]# tar xf phpMyAdmin-4.2.7-all-languages.tar.gz
[root@LookBack164 wwwroot]# ln -s /home/wwwroot/phpMyAdmin-4.2.7-all-languages /home/wwwroot/phpmyadmin
[root@LookBack164 wwwroot]# cp /home/wwwroot/phpmyadmin/config.sample.inc.php /home/wwwroot/phpmyadmin/config.inc.php
[root@LookBack164 wwwroot]# sed -i "s@\[‘host‘\] = ‘localhost‘\;@\[‘host‘\] = ‘172.16.41.165‘\;@" /home/wwwroot/phpmyadmin/config.inc.php

3.4去浏览器输入https://pam.05hd.com/index.php来看看效果4、下面我们去php服务器上/home/wwwroot/www.05hd.com/这个目录下弄个wordpress博客程序测试下4.1下载wordpress

[root@LookBack164 php-5.4.31]# cd /home/wwwroot/www.05hd.com/
[root@LookBack164 www.05hd.com]# ls
index.php
[root@LookBack164 www.05hd.com]# rm -rf index.php
[root@LookBack164 www.05hd.com]# wget http://cn.wordpress.org/wordpress-3.9-zh_CN.tar.gz
[root@LookBack164 www.05hd.com]# tar xf wordpress-3.9-zh_CN.tar.gz
[root@LookBack164 www.05hd.com]# ls
wordpress  wordpress-3.9-zh_CN.tar.gz
[root@LookBack164 www.05hd.com]# mv wordpress/* .
[root@LookBack164 www.05hd.com]# ls
index.php    wordpress                   wp-admin              wp-config-sample.php  wp-includes        wp-login.php     wp-signup.php
license.txt  wordpress-3.9-zh_CN.tar.gz  wp-blog-header.php    wp-content            wp-links-opml.php  wp-mail.php      wp-trackback.php
readme.html  wp-activate.php             wp-comments-post.php  wp-cron.php           wp-load.php        wp-settings.php  xmlrpc.php
[root@LookBack164 www.05hd.com]# cp wp-config-sample.php wp-config.php

4.2 配置wordpress的数据库连接选项  来看看worpress页面的情况

Centos 6.5 配置分离式LAMP平台环境 多服务器编译安装Apache2.4.x PHP5.4.x MariaDB5.5.x,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。