6、在LAMP架构中,请分别以php编译成httpd模块形式和php以fpm工作为独立守护进程的方式来支持httpd,列出详细的过程。
# LAMP编译安装 #
LAMP编译安装,目前CentOS7操作系统上可以使用yum进行安装,在CentOS6上需要编译安装
CentOS6 http-2.2主要安装的,编译安装LAMP需要http-2.4进行编译安装
linux上需要准备编译安装的环境:
包组(CentOS 6):
Server Platform Development
Development Tools
http-2.4需要较新版本的apr和apr-util
1,编译安装apr
需要下载:apr-1.5.2 (1).tar.bz2,apr-util-1.5.4.tar.bz2
~]# tar xf apr-1.5.2\ \(1\).tar.bz2
~]# cd apr-1.5.2
]# ./configure --prefix=/usr/local/apr
]# make && make install
编译安装apr-util-1.5.4.tar.bz2
]# tar xf apr-util-1.5.4.tar.bz2
]# cd apr-util-1.5.4
]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr(告知程序依据那个apr进行编译安装)
]# make && make install
好了这里就安装好了apr和apr-util了
安装http-2.4
1,httpd-2.4编译安装需要依赖pcre-devel软件包,使用yum install进行安装
]# tar xf httpd-2.4.23.tar.bz2
]# cd httpd-2.4.23
]# ./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-modules=most --enable-mpms-shared=all --with-mpm=event
]# make && make install
配置服务类脚本
]# cd /etc/rc.d/init.d/
]# cp httpd httpd24
编辑httpd24的配置文件修改文件路径
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
将服务加入
]# chkconfig --add httpd24
]# chkconfig --list httpd24
httpd24 0:off 1:off 2:off 3:off 4:off 5:off 6:off
将httpd命令定义到新的httpd24下
]# . /etc/profile.d/httpd.sh
]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
重读配置文件
]# . /etc/profile.d/httpd.sh
]# hash
hits command
1 /usr/local/apache/bin/httpd
编译安装mariadb
先将下载好的软件包进行解压缩
]# tar xf mariadb-5.5.32-linux-x86_64.tar.gz
]# cp mariadb-5.5.32-linux-x86_64 /usr/local/ -a
创建连接为mysql
]# ln -sv mariadb-5.5.32-linux-x86_64/ mysql
创建属组:]# groupadd -r -g 306 mysql
创建用户:]# useradd -r -g 306 -u 306 mysql
修改此文件中的属主为root,属组为mysql
]# chown root:mysql ./*
新建磁盘分区用于数据库的使用
这里使用的逻辑磁盘分区的方法
使用fdisk /dev/sda 创建一个20G的磁盘空间
使用t将磁盘修改类型为8e
先建立pv
]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
建立vg
]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 3 0 wz--n- 59.99g 0
[root@localhost mysql]# vgcreate myvg /dev/sda3
Volume group "myvg" successfully created
创建lv
]# lvcreate -L 10G -n mydata myvg
Logical volume "mydata" created.
这里使用xfs文件系统
先使用yum install xfsprogs
加载模块文件
]# modprobe xfs
]# modinfo xfs
filename: /lib/modules/2.6.32-642.4.2.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.4.2.el6.x86_64 SMP mod_unload modversions
对磁盘进行格式化
]# mkfs.xfs /dev/myvg/mydata
meta-data=/dev/myvg/mydata isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
编辑/etc/fstab文件是其开启自动挂载文件
/dev/myvg/mydata /mydata xfs defaults 0 0
新建一个目录用户存放mydata数据
查看需要编译安装的配置文件
[root@localhost mysql]# scripts/mysql_install_db --help
]# scripts/mysql_install_db --user=mysql(指定用户) --datadir=/mydata/data/(初始化数据放入到那个文件夹)
启动mysql需要使用一个服务脚本
[root@localhost support-files]# ls
binary-configure magic my-medium.cnf mysql.server
config.huge.ini my-huge.cnf my-small.cnf ndb-config-2-node.ini
config.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.server SELinux
config.small.ini my-large.cnf mysql-log-rotate solaris
]# cp mysql.server /etc/rc.d/init.d/mysqld
将服务加入到chkconfig
[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
配置文件查找次序:
/etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf
这里如果需要将mysql命令加入到bash变量中永久有效有2中方法
在/etc/profile的export下面加入一行
export PATH=/usr/local/mysql/bin:$PATH
使用source /etc/profile
如需要对个人生效
在~/.bash_profile中加入
export PATH=/usr/local/mysql/bin:$PATH
source ~/.bash_profile
这里在mysql第一次运作时需要对用户权限等进行一次修改
mysql_secure_installation:安全初始化
初始化完成之后
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.32-MariaDB-log MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> user mysql
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'user mysql' at line 1
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]>
MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> SELECT User,Host,Password FROM user;
+------+-----------------------+-------------------------------------------+
| User | Host | Password |
+------+-----------------------+-------------------------------------------+
| root | localhost | *17C5214AB2227D33B7976A03E25B9D7AD58913AD |
| root | localhost.localdomain | *17C5214AB2227D33B7976A03E25B9D7AD58913AD |
| root | 127.0.0.1 | *17C5214AB2227D33B7976A03E25B9D7AD58913AD |
| root | ::1 | *17C5214AB2227D33B7976A03E25B9D7AD58913AD |
+------+-----------------------+-------------------------------------------+
4 rows in set (0.00 sec)
编译安装PHP
将下载好的php软件包进行解压缩
]# tar xf php-5.5.38.tar.bz2
]# cd php-5.5.38
解决好软件依赖关系
请配置好yum源(系统安装源及epel源)后执行如下命令:
]# yum -y groupinstall "Desktop Platform Development"
]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
然后进行编译安装
]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs (将php编译为http模块)--with-mcrypt
(加解密库) --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts(支持apache work或event功能)
这里等待编译完成,这里要记住httpd默认是不支持php模块的,需要在httpd的文件中加入
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
查看http配置文件发现模块文件有
LoadModule php5_module modules/libphp5.so
找到AddType加入上诉语句
为php提供配置文件
]# cp php.ini-production /etc/php.ini
我的测试文件为:
]# cat index.php
<?php
$counn=mysql_connect('127.0.0.1','root','Pa$$w0rd01!');
if($counn)
echo "OK";
else
echo "NOT OK";
mysql_close();
phpinfo();
?>
建立数据库:
建立用户名和登录地址与密码
> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.0.44' IDENTIFIED BY 'wppasswd';
建立数据库:
> CREATE DATABASE wpdb;
使用页面安装完成
LAMP的fpm的安装
之前的步骤都是一样的
重新对php进行编译安装
生成配置文件,上面的./config时所指的文件路径需要一致
]# cp php.ini-production /etc/php5/php.ini
cp服务脚本
]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
将php加入到服务当中
chkconfig --add php-fpm
[root@ns1 php-5.5.38]# chkconfig --list php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
为php-fpm提供配置文件:
]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
修改配置文件
注意这里的进程的配置位置一定需要修改
编辑php-fpm的配置文件:
# vim /usr/local/php5/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php5/var/run/php-fpm.pid
配置httpd-2.4.9
1、启用httpd的相关模块
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
同样需要http配置文件支持php格式的文件
ProxyRequests Off --->关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1-->把所有php资源的请求转发给fpm服务器
这样重启php和httpd的服务可以发现完成
原创文章,作者:wostop,如若转载,请注明出处:http://www.178linux.com/51805


评论列表(1条)
可以将以上操作流程,写一个脚本,这样既能锻炼了自己的逻辑能力,还可能在以后的工作用直接使用些架构