码迷,mamicode.com
首页 > 其他好文 > 详细

编译安装LAMP(两种场景)

时间:2016-08-19 22:35:05      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:blank   虚拟主机   discuz   target   style   

编译安装LAMP

场景一:AP组合以模块方式结合(编译PHP作为httpd的模块);进而完成虚拟主机PMA(phpmyadmin)和discuz论坛

场景二:AP组合以fpm方式,PHP独立守护进程运行;进而完成虚拟主机PMA(phpmyadmin)和discuz论坛

技术分享

==========================场景一============================

拓扑结构:

主机一

网卡1IP为172.20.1.100

网卡2IP为192.168.217.219

在此计算机上编译安装HTTPD 和PHP

主机二IP为192.168.217.128

安装MYSQL

安装顺序HTTPD –> MYSQL –> PHP

HTTPD部分:(192.168.217.129/172.20.1.100)

在172.20.1.100中安装HTTPD:

编译安装httpd2.4 软件包版本是httpd-2.4.20.tar.bz2

安装前,需要检查:

包组:“Development Tools” “Server Platform Development”

软件包:pcre-devel  zlib-devel openssl-devel

yum groupinstall或者yum install之

httpd2.4的安装顺序:apr –> apr-util –> httpd2.4

apr和apr-util安装:

[root@localhost sources]# tar -xf apr-1.5.0.tar.bz2

[root@localhost sources]# tar -xf apr-util-1.5.3.tar.bz2

[root@localhost sources]#cd apr-1.5.0

[root@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr

[root@localhost apr-1.5.0]# make && make install

[root@localhost apr-1.5.0]# cd ../apr-util-1.5.3

[root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

[root@localhost apr-util-1.5.3]# yum install pcre-devel zlib-devel openssl-devel

Httpd2.4安装:

[root@localhost sources]# tar xf httpd-2.4.20.tar.bz2

[root@localhost sources]# cd httpd-2.4.20

[root@localhost httpd-2.4.20]#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-module=most --enable-mpms-shared=all --with-mpm=prefork

[root@localhost httpd-2.4.20]# make && make install

[root@localhost httpd-2.4.20]# vim /etc/profile.d/httpd.sh

[root@localhost httpd-2.4.20]# cat /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

[root@localhost httpd-2.4.20]# source /etc/profile.d/httpd.sh

[root@localhost httpd-2.4.20]# cd /usr/local/apache/

[root@localhost apache]# ln -s include/ /usr/include/httpd  \\导出头文件

[root@localhost apache]# vim /etc/man.config

MANPATH /usr/local/apache/man \\新增;帮助文档

[root@localhost httpd24]# vim /etc/httpd24/httpd.conf

User daemon

Group daemon

改为:

User apache

Group apache    \\当然得确保系统中存在这个用户和组

#cd  /etc/rc.d/init.d/

#cp httpd  httpd24         \\本机有httpd文件就从本机复制,本机没有可以到别的机器复制过来

[root@localhost httpd24]# vim /etc/rc.d/init.d/httpd24

修改httpd24中:

    apachectl=/usr/local/apache/bin/apachectl

    httpd=${HTTPD-/usr/local/apache/bin/httpd}

    pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

[root@localhost httpd24]# chkconfig --add httpd24

[root@localhost httpd24]# chkconfig httpd24 on

[root@localhost sources]# service httpd24 start

技术分享

基本上httpd2.4编译安装完毕

 

MARIADB部分:(192.168.217.128)

192.168.217.128中安装二进制版本的MariaDB:

[root@localhost ~]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz –C /usr/local/mysql  \\解压到/usr/local/mysql或者做软链接都行,但必须要是/usr/local/下

[root@localhost mysql]# mkdir -pv /data/mydata

[root@localhost mysql]# groupadd -r mysql

[root@localhost mysql]# useradd -r -g mysql mysql

[root@localhost mysql]# id mysql

uid=496(mysql) gid=493(mysql) 组=493(mysql)

[root@localhost mysql]# chown root:mysql /usr/local/mysql/*

[root@localhost mysql]# chown -R mysql:mysql /data/mydata/

[root@localhost mysql]# mkdir /etc/mysql

[root@localhost mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mydata/

[root@localhost mysql]# vim /etc/mysql/my.cnf

[mysqld]中修改、添加

thread_concurrency = 4 \\CPU核数*2 修改

datadir = /data/mydata \\添加

innodb_file_per_table = on \\添加

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

[root@localhost mysql]# vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

[root@localhost mysql]# source /etc/profile.d/mysql.sh

[root@localhost mysql]# service mysqld start

技术分享

PHP部分(192.168.217.128/172.20.1.100)

检查所需要的软件包

libxml2-devel libcrypt-devel bzip2-devel

[root@localhost php-5.4.26]# yum install -y libxml2-devel libcrypt-devel bzip2-devel (有些软件可能在epel源中)

[root@localhost htdocs]# cd ~/sources/

[root@localhost sources]# tar xf php-5.4.26.tar.bz2

[root@localhost sources]# cd php-5.4.26

[root@localhost php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php.d/

[root@localhost php-5.4.26]# make && make install

[root@localhost php-5.4.26]# mkdir /etc/php

[root@localhost php-5.4.26]# mkdir /etc/php.d

[root@localhost php-5.4.26]# cp php.ini-production /etc/php/php.ini

修改httpd的配置文件:

[root@localhost php-5.4.26]# vim /etc/httpd24/httpd.conf

技术分享

技术分享

验证php:

[root@localhost php-5.4.26]# cd /usr/local/apache/htdocs/

[root@localhost htdocs]# vim index.php

<?php

phpinfo();

?>

技术分享

在页面中有关于时间报错Warning: phpinfo(): It is not safe to rely on the system‘s timezone settings.

解决方法:

[root@localhost htdocs]# vim /etc/php/php.ini

date.timezone = "Asia/Shanghai"

[root@localhost htdocs]# vim /usr/local/apache/htdocs/index.php

<?php

date_default_timezone_set(‘Asia/Shanghai‘);

phpinfo();

?>

问题得到解决

 

验证php和mysql的结合:

Mysql中创建一个测试账号,也便于登录phpmyadmin和discuz使用

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO ‘testuser‘@‘%‘ IDENTIFIED BY ‘123456‘;

<?php

$link=mysql_connect(‘192.168.217.128‘,‘testuser‘,‘123456‘);

if ($link)

echo "<h1>success...</h1> ";

else

echo "<h1>connect failed</h1>";

mysql_close();

?>

技术分享

安装xcache加速php,因为虚拟机配置差,安装跟没安装区别不大,效果不明显。。。简单说下步骤:

tar xf xcache-3.1.0.tar.bz2 \\解压

cd xcache-3.1.0 \\进入解压目录

/usr/local/php/bin/phpize \\没有configure文件,需要执行此命令configure就会出现

./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config \\安装步骤

make && make install \\安装步骤

cp xcache.ini /etc/php.d/ \\添加到php的配置文件目录中

vim /etc/php.d/xcache.ini \\编辑以下:

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

说明:在make install完成后会有一个提示告诉即 /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so的路径,把此绝对路径复制到配置文件中即可

 

部署虚拟机phpmyadmin和discuz

[root@localhost webroot]# vim /etc/httpd24/httpd.conf

#DocumentRoot "/usr/local/apache/htdocs" \\注释掉

Include /etc/httpd24/extra/httpd-vhosts.conf \\启用

[root@localhost webroot]# vim /etc/httpd24/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin admin@aaa.com

DocumentRoot "/webroot/pma/"

ServerName www.aaa.com

ServerAlias aaa.com

ErrorLog "/var/log/www.aaa.com-error_log"

CustomLog "/var/log/www.aaa.com-access_log" common

<Directory "/webroot/pma/">

options none

AllowOverride none

Require all granted

</Directory>

</VirtualHost>

Phpmyadmin的虚拟主机

<VirtualHost *:80>

ServerAdmin admin@bbb.com

DocumentRoot "/webroot/discuz/"

ServerName www.bbb.com

ErrorLog "/var/log/www.bbb.com-error_log"

CustomLog "/var/log/www.bbb.com-access_log" common

<Directory "/webroot/discuz/">

options none

AllowOverride none

Require all granted

</Directory>

</VirtualHost>

Discus的虚拟主机

在本机C:\Windows\System32\drivers\etc\hosts 修改文件解析

172.20.1.100 www.aaa.com aaa.com

172.20.1.100 www.bbb.com bbb.com

Phpmyadmin要连接mysql,因为不在同一台加上,所以要修改配置文件指明mysql的地址

#vim /webroot/pma/libraries/config.default.php

$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.217.128‘; \\修改mysql的IP

技术分享

Discus的搭建就比较简单

把discuz的包解压后,将upload里的文件放到DocumentRoot中即/webroot/discuz/,然后给于777的权限

技术分享

技术分享

技术分享

技术分享

技术分享

===========================场景二==============================

根据场景一的基础上又添加了一台机器

把php安装到此机器上来,过程比较简单,主要步骤:

1、 停用httpd中PHP模块

2、 Httpd虚拟主机中关闭正向代理,把php的请求转发到php服务器

3、 将httpd的虚拟主机DocumentRoot文件复制到php服务器中

为了记录完整的步骤,决定把所有主机还原,然后重做

规划:

主机1安装httpd,IP 172.20.1.100 192.168.217.129

主机2安装MYSQL IP 192.168.130

主机3安装php和xcache,IP 192.168.217.128

192.168.1.100中安装httpd

安装前准备好”Development Tools” “Server Platform Development”包组

pcre-devel zlib-devel openssl-devel等开发包

安装httpd前,编译安装apr和apr-util

[root@localhost sources]# tar xf apr-1.5.0.tar.bz2

[root@localhost sources]# cd apr-1.5.0

[root@localhost apr-1.5.0]# ./configure --prefix=/usr/local/apr

[root@localhost apr-1.5.0]# make && make install

[root@localhost sources]# tar xf apr-util-1.5.3.tar.bz2

[root@localhost sources]# cd apr-util-1.5.3

[root@localhost apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

[root@localhost apr-util-1.5.3]# make && make install

[root@localhost sources]# tar xf httpd-2.4.20.tar.bz2

[root@localhost sources]# cd httpd-2.4.20

[root@localhost httpd-2.4.20]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-module=most --enable-mpms-shared=all --with-mpm=worker

采用了跟实验一不同的MPM,前者使用了prefork,后者使用了worker模型,这跟编译php有关系(区别),后面会有说明

[root@localhost httpd-2.4.20]# make && make install

安装完最后又告诉我们创建了哪些目录

Installing configuration files

mkdir /etc/httpd24

mkdir /etc/httpd24/extra

mkdir /etc/httpd24/original

mkdir /etc/httpd24/original/extra

Installing HTML documents

mkdir /usr/local/apache/htdocs

Installing error documents

mkdir /usr/local/apache/error

Installing icons

mkdir /usr/local/apache/icons

mkdir /usr/local/apache/logs

Installing CGIs

mkdir /usr/local/apache/cgi-bin

Installing header files

mkdir /usr/local/apache/include

Installing build system files

mkdir /usr/local/apache/build

Installing man pages and online manual

mkdir /usr/local/apache/man

mkdir /usr/local/apache/man/man1

mkdir /usr/local/apache/man/man8

mkdir /usr/local/apache/manual

make[1]: Leaving directory `/root/sources/httpd-2.4.20‘

[root@localhost httpd-2.4.20]# vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

[root@localhost httpd-2.4.20]# source /etc/profile.d/httpd.sh

将启动程序路径加入到PATH中

[root@localhost httpd-2.4.20]# vim /etc/httpd24/httpd.conf

技术分享

默认是daemon,修改为apache

[root@localhost httpd-2.4.20]# ln -sv /usr/local/apache/include/ /usr/include/httpd

\\导出头文件

[root@localhost httpd-2.4.20]# vim /etc/man.config

MANPATH /usr/local/apahce/man \\添加帮助文件到系统搜索路径

启动脚本:

-rwxr-xr-x 1 root root 3371 10月 28 22:04 /etc/rc.d/init.d/httpd24

如果本机有自带httpd的话,在此目录下应该会有一个httpd的启动脚本,复制修改下内容即可,如果本机没有,可以从别处复制来

修改部分:(同上)

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

[root@localhost httpd-2.4.20]# chkconfig --add httpd24

[root@localhost httpd-2.4.20]# chkconfig httpd24 on

[root@localhost httpd-2.4.20]# service httpd24 start

技术分享

 

MYSQL:

[root@localhost sources]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz

[root@localhost sources]# mv mariadb-5.5.40-linux-x86_64 /usr/local/mysql

[root@localhost ~]# cd /usr/local/mysql/

[root@localhost mysql]# groupadd -r mysql

[root@localhost mysql]# useradd -r -g mysql mysql

[root@localhost mysql]# mkdir -pv /data/mydata

[root@localhost mysql]# chown -R root:mysql /usr/local/mysql/*

[root@localhost mysql]# chown -R mysql:mysql /data/mydata/

[root@localhost mysql]# mkdir /etc/mysql

[root@localhost mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

[root@localhost mysql]# vim /etc/mysql/my.cnf

修改[mysqld]中的部分参数:

thread_concurrency = 4 \\修改,一般为CPU核心数*2

datadir = /data/mydata \\添加,数据目录地址

innodb_file_per_table = on \\添加

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mydata/

初始化mysql

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld

[root@localhost mysql]# chkconfig --add mysqld

[root@localhost mysql]# chkconfig mysqld on

[root@localhost mysql]# vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

技术分享

 

PHP、xcache

事先安装好libmcrypt-devl “Development Tools” “Server Platform Development”

[root@localhost sources]# tar xf php-5.4.26.tar.bz2

[root@localhost sources]# cd php-5.4.26

[root@localhost php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php.d/ --enable-maintainer-zts

跟场景一不同的是,--enable-maintainer-zts (如果httpd使用的是prefork则不用此项,如果是worker或者event则使用此项)

去掉--with-apxs2=/usr/local/apache/bin/apxs  \\apxs作用是把php编程成http的模块,而改成—enable-fpm \\作为独立进程监听在套接字上

[root@localhost php-5.4.26]# make && make install

[root@localhost php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

[root@localhost php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm

[root@localhost php-5.4.26]# chkconfig --add php-fpm

[root@localhost php-5.4.26]# chkconfig php-fpm on

[root@localhost php-5.4.26]# mkdir /etc/{php,php.d}

[root@localhost php-5.4.26]# cp php.ini-production /etc/php/php.ini

[root@localhost php-5.4.26]# vim /usr/local/php/etc/php-fpm.conf

根据实际情况修改:

listen = 192.168.217.128:9000 \\监听地址和端口

pm.max_children = 100 \\最大并发数

pm.start_servers = 10 \\启动时启动进程数量

pm.min_spare_servers = 3 \\最少空闲数量

pm.max_spare_servers = 15 \\最大空闲数量

pid = /usr/local/php/var/run/php-fpm.pid

 

[root@localhost sources]# tar xf xcache-3.1.0.tar.bz2

[root@localhost sources]# cd xcache-3.1.0

[root@localhost xcache-3.1.0]# /usr/local/php/bin/ph

phar phar.phar php php-cgi php-config phpize

[root@localhost xcache-3.1.0]# /usr/local/php/bin/phpize

[root@localhost xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[root@localhost xcache-3.1.0]# make && make install

技术分享

[root@localhost xcache-3.1.0]# vim /etc/php.d/xcache.ini

技术分享

技术分享

172.20.1.100中修改httpd的配置文件

[root@localhost httpd-2.4.20]# vim /etc/httpd24/httpd.conf

启用模块

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

DirectoryIndex index.php index.html

Include /etc/httpd24/extra/httpd-vhosts.conf

#DocumentRoot "/usr/local/apache/htdocs"

[root@localhost httpd-2.4.20]# vim /etc/httpd24/extra/httpd-vhosts.conf

技术分享

在PHP服务器中(192.168.217.128)解压pma和discuz的文件,过程省略

[root@localhost www]# chmod -R 777 bbs

修改pma中mysql的地址

[root@localhost pma]# vim libraries/config.default.php

$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.217.130‘;

注意:在PHP中解压出的pma和discuz目录结构要在httpd服务器上创建一模一样的结构,否则只能打开.php的内容,而图片则不显示等问题

[root@localhost ~]# rsync -a /web root@192.168.217.129:/

技术分享

技术分享

技术分享

技术分享

编译安装LAMP(两种场景)

标签:blank   虚拟主机   discuz   target   style   

原文地址:http://wangkunpeng.blog.51cto.com/1538469/1840312

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!