设为首页 收藏本站
查看: 991|回复: 0

LAMP+NFS(编译php-fpm模块与apache2.4结合)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-30 08:46:13 | 显示全部楼层 |阅读模式
搭建环境:Centos 6.6 + apache2.4 + mariadb5.5 + php-fpm5.5 + nfs
wKioL1YKf3OCLpdXAADVZLsZezA562.jpg
准备好3台虚拟机,配置好主机名和IP地址,关闭防火墙和selinux
nfs启动顺序:先启动rpc—>在启动nfs
nfs权限参数
rw:读写
ro:只读
sync:同步模式,内存中数据时时写入磁盘
async:不同步,把内存中数据定期写入磁盘中
no_root_squash:加上这个选项后,root用户就会对共享的目录拥有至高的权限控制,就像是对本机的目录操作一样。不安全,不建议使用
root_squash:把root通过网络访问时,换成nfsnobody用户,即限制了root权限
all_squash:不管使用NFS的用户是谁,他的身份都会被限定成为nfsnobody用户身份
anonuid/anongid:要和root_squash以及 all_squash一同使用,用于指定使用NFS的用户限定后的uid和gid,前提是服务端和客户端/etc/passwd中都存在这个uid和gid
共享文件权限为:服务权限与文件系统权限的交集
安装、配置nfs服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@nfs ~]# mkdir -p /data/{mydata,www} #为web,mysql创建共享目录
[iyunv@nfs ~]# ls /data/
mydata  www
[iyunv@nfs ~]# groupadd -g 110 apache
[iyunv@nfs ~]# useradd -u 110 -M -s /sbin/nologin apache
[iyunv@nfs ~]# chmod 777 /data/www/
[iyunv@nfs ~]# groupadd -g 111 msyql
[iyunv@nfs ~]# useradd -u 111 -M -s /sbin/nologin mysql
[iyunv@nfs ~]# chmod 777 /data/mydata/
[iyunv@nfs ~]# yum groupinstall  -y "NFS file server"
[iyunv@nfs ~]# vi /etc/exports
/data/www 192.168.0.11(rw,root_squash)
/data/mydata 192.168.0.20(rw,no_root_squash)
[iyunv@nfs ~]# service rpcbind restart
Stopping rpcbind:                                          [  OK  ]
Starting rpcbind:                                          [  OK  ]
[iyunv@nfs ~]# service nfs start
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]



安装、配置mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[iyunv@mysql ~]# mkdir -p /data/mydata
[iyunv@mysql ~]# showmount -e 192.168.0.30
Export list for 192.168.0.30:
/data/mydata 192.168.0.20
/data/www    192.168.0.11
[iyunv@mysql ~]# mount -t nfs 192.168.0.30:/data/mydata /data/mydata/
[iyunv@mysql ~]# cd /data/mydata/
[iyunv@mysql mydata]# ll
total 0
[iyunv@mysql mydata]# touch aa
[iyunv@mysql mydata]# ll
total 0
-rw-r--r-- 1 root root 0 Sep 29 22:23 aa
[iyunv@mysql mydata]# cd ~
[iyunv@mysql ~]# groupadd -g 111 msyql
[iyunv@mysql ~]# useradd -u 111 -M -s /sbin/nologin mysql #创建mysql账户
[iyunv@mysql ~]# chown -R mysql:mysql /data/mydata
[iyunv@mysql ~]# tar -xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local/
[iyunv@mysql ~]# cd /usr/local
[iyunv@mysql local]# chown -R mysql:mysql mariadb-5.5.36-linux-x86_64/
[iyunv@mysql local]# ln -sv mariadb-5.5.36-linux-x86_64/ mysql
[iyunv@mysql mysql]# cd mysql
[iyunv@mysql mysql]# scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql
[iyunv@mysql mysql]# mkdir /etc/mysql
[iyunv@mysql mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[iyunv@mysql mysql]# vi /etc/mysql/my.cnf #在mysqld下面添加下面几项
[mysqld]
...
datadir = /data/mydata
innodb_file_per_table =on
skip_name_resolve = on
[iyunv@mysql mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[iyunv@mysql mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
[iyunv@mysql mysql]# echo'/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[iyunv@mysql mysql]# ldconfig
[iyunv@mysql mysql]# chkconfig --add mysqld
[iyunv@mysql mysql]# service mysqld start
[iyunv@mysql mysql]# bin/mysql_secure_installation #数据库安全初始化,设置root密码、权限和删除匿名用户
[iyunv@mysql mysql]# /usr/local/mysql/bin/mysql -uroot -p #验证能否登录
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.36-MariaDB-log MariaDB Server

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)]> show databases;
+--------------------+
| Database         |
+--------------------+
| information_schema|
| mysql          |
| performance_schema|
+--------------------+
3 rows in set (0.03 sec)
MariaDB [(none)]> grant all on *.* to test@"192.168.%.%" identified by 'chinoe-147';
##在nfs服务器上可以看到mysql元数据
[iyunv@nfs ~]# cd /data/mydata/
[iyunv@nfs mydata]# ls
aria_log.00000001  aria_log_control  ibdata1  ib_logfile0  ib_logfile1  mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.000003  mysql-bin.index  mysql.pid  performance_schema



安装、配置apache+php-fpm
apache依赖包 apr-util-1.5.3.tar.bz2 、apr-1.5.0.tar.bz2、pcre-devel  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[iyunv@httpd ~]# groupadd -g 110 apache
[iyunv@httpd ~]# useradd -u 110 -M -s /sbin/nologin apache
[iyunv@httpd ~]# yum install -y pcre-devel
[iyunv@httpd ~]# tar -xf apr-1.5.0.tar.bz2  
[iyunv@httpd ~]# cd apr-1.5.0
[iyunv@httpd apr-1.5.0]# ./configure --prefix=/usr/local/apr
[iyunv@httpd apr-1.5.0]# make && make install
[iyunv@httpd apr-1.5.0]# cd ..
[iyunv@httpd ~]# tar -xf  apr-util-1.5.3.tar.bz2
[iyunv@httpd ~]# cd apr-util-1.5.3
[iyunv@httpd apr-util-1.5.3]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[iyunv@httpd apr-util-1.5.3]# make && makeinstall
[iyunv@httpd apr-util-1.5.3]# cd ..
[iyunv@httpd ~]# tar -xvf httpd-2.4.10.tar.bz2
[iyunv@httpd ~]# cd httpd-2.4.10
[iyunv@httpd httpd-2.4.10]# ./configure
--prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
[iyunv@httpd httpd-2.4.10]# make && make install
###然后需要自己编写httpd服务启动脚本,我这里是直接修改rpm安装httpd的脚本
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid

# 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/local/apache/bin/apachectl #修改为相关路径
httpd=${HTTPD-/usr/local/apache/bin/httpd} #修改为相关路径
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid} #修改为相关路径
lockfile=${LOCKFILE-/var/lock/subsys/httpd} #修改为相关路径
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $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=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac

exit $RETVAL
[iyunv@httpd  ~]# chmod +x /etc/init.d/httpd
[iyunv@httpd  ~]# chkconfig --add httpd
[iyunv@httpd ~]# vi /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
[iyunv@httpd  ~]# ./etc/profile.d/httpd.sh #重读一下配置文件
编译安装apache在服务启动之前必须指定pid文件路径
在/etc/httpd/httpd.conf的全局配置中添加pid文件
ServerRoot "/usr/local/apache"
PidFile "/var/run/httpd.pid" 必须与服务启动脚本httpd中的pidfile路径一样
[iyunv@httpd ~]# service httpd start
[iyunv@httpd ~]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Date: Tue, 29 Sep 2015 12:57:18 GMT
Server: Apache/2.4.10 (Unix)
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text/html
#apache已经安装完毕,测试正常



php-fpm以独立模块与apache结合
依赖包:bzip2-devel libmcrypt-devel libxml2-devel php-mysql
mysql与php不在同一台物理机时,还需要安装mysql-devel包和mysql-libs包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[iyunv@httpd ~]# mkdir /etc/php5{,.d}
[iyunv@httpd ~]# mkdir /usr/local/php5
[iyunv@httpd ~]# yum -y groupinstall "Desktop Platform Development"
[iyunv@httpd ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel php-mysql
[iyunv@httpd ~]# yum install -y mysql-devel mysql-libs
[iyunv@httpd ~]# tar -xf php-5.5.29.tar.xz
[iyunv@httpd ~]# cd php-5.5.29
[iyunv@httpd php-5.5.29]# ./configure --prefix=/usr/local/php5/ --with-mysql --with-openssl --with-mysqli --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc/php5/ --with-config-file-scan-dir=/etc/php5.d --with-bz2
[iyunv@httpd php-5.5.29]# make -j 4 && make install
[iyunv@httpd php-5.5.29]# cp php.ini-production /etc/php5/php.ini
[iyunv@httpd php-5.5.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[iyunv@httpd php-5.5.29]# chmod +x /etc/rc.d/init.d/php-fpm
[iyunv@httpd php-5.5.29]# chkconfig --add php-fpm
[iyunv@httpd php-5.5.29]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
###修改php-fpm参数
[iyunv@httpd php-5.5.29]# vim /usr/local/php5/etc/php-fpm.conf
user = apache
group = apache
listen = 0.0.0.0:9000
在pm = dynamic模块下面修改参数
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
[iyunv@httpd php-5.5.29]# service php-fpm start
[iyunv@httpd php-5.5.29]# ss -tanlp |grep 9000
LISTEN     0      128               127.0.0.1:9000                     *:*      users:(("php-fpm",114598,7),("php-fpm",114599,0),("php-fpm",114600,0),("php-fpm",114601,0),("php-fpm",114602,0),("php-fpm",114603,0))
[iyunv@httpd php-5.5.29]# vi /etc/httpd/httpd.conf
User apache #修改进程用户
Group apache
##注释掉中心主机,使用虚拟主机
#DocumentRoot "/usr/local/apache/htdocs"
#<Directory "/usr/local/apache/htdocs">
#    Options Indexes FollowSymLinks
#    AllowOverride None
#    Require all granted
#</Directory>
在相关的LoadModule下添加
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
在AddType下添加
AddType application/x-httpd-php .php
找到DirectoryIndex index.html 修改为:
DirectoryIndex  index.php index.html
#结尾加上虚拟主机
<virtualhost *:80>
    servername www.test.com
    documentroot /data/www
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/$1
    <directory "/data/www">
        options none
        allowoverride none
        <requireall>
            require all granted
        </requireall>
    </directory>
</virtualhost>
[iyunv@httpd ~]# mkdir -p /data/www
[iyunv@httpd ~]# mount -t nfs 192.168.0.30:/data/www /data/www/
[iyunv@httpd ~]# vi index.php
<?php
    phpinfo()
?>



wKioL1YKpymT8CQvAALcTSmuqRA782.jpg
1
2
3
4
5
6
7
8
9
[iyunv@httpd ~]# vi index.php #测试数据库
<?php
$link = mysql_connect('192.l68.0.20','test','chinoe-147');
    if ($link)
echo "Success...";
else
    echo "Failure...";
mysql_close();
?>



再测试数据库是否能链接上
wKioL1YKq5eCqIDnAADRdhwTqEE348.jpg
已经success


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-120682-1-1.html 上篇帖子: centos7安装lamp并部署应用phpMyadmin和wordpress和Discuz个人论坛 下篇帖子: LAMP编译安装之PHP以fpm的方式结合apache工作
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表