一、lnmp平台的部署(跨服务器):
mysql软件包 https://dev.mysql.com/downloads/mysql/
Nginx软件包 http://nginx.org/en/download.html
PHP软件包(php-fpm) http://php.net/downloads.php
依赖包 libmcrypt-2.5.8-13.el7.x86_64.rpm libmcrypt-devel-2.5.8-13.el7.x86_64.rpm mcrypt-2.6.8-11.el7.x86_64.rpm mhash-0.9.9.9-10.el7.x86_64.rpm mhash-devel-0.9.9.9-10.el7.x86_64.rpm
地址:http://search.rpmseek.com/search.html?hl=com
以下例子用到的包的版本:
php-5.6.27.tar.gz mysql-boost-5.7.17.tar.gz nginx-1.11.10.tar.gz
环境准备:
192.168.122.101 nginx.linux.com
192.168.122.102 mysql.linux.com
192.168.122.103 php01.linux.com
一、Nginx软件安装
[root@nginx nginx-1.11.10]# yum install -y gcc pcre-devel openssl-devel
[root@nginx ~]# useradd nginx
[root@nginx ~]# mkdir -p /usr/local/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[root@nginx ~]# tar zxf nginx-1.11.10.tar.gz
[root@nginx ~]# cd nginx-1.11.10/
[root@nginx nginx-1.11.4]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/usr/local/nginx/client \
--http-proxy-temp-path=/usr/local/nginx/proxy \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi \
--with-pcre \
--with-file-aio \
--with-http_secure_link_module \
[root@nginx nginx-1.11.10]# make && make install
启动nginx
[root@nginx ~]# /usr/local/nginx/sbin/nginx
[root@nginx ~]# ss -antp | grep nginx
LISTEN 0 128 *:80 *:* users:(("nginx",pid=7691,fd=6),("nginx",pid=7690,fd=6))
[root@nginx ~]# ps aux | grep nginx
root 7690 0.0 0.1 47552 1116 ? Ss 11:20 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 7691 0.0 0.2 50076 2220 ? S 11:20 0:00 nginx: worker process
root 7708 0.0 0.0 112660 932 pts/0 S+ 11:21 0:00 grep --color=auto nginx
设置nginx开机自启动
[root@nginx ~]# tail -1 /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx
[root@nginx ~]# chmod a+x /etc/rc.d/rc.local
二、mysql的安装
卸载系统自带的mariadb软件
[root@mysql ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@mysql ~]# rpm -e --nodeps mariadb-libs
修改数据目录的所属
[root@mysql ~]#mkdir -p /mydata/data ----> 做数据目录
[root@mysql ~]# useradd -s /sbin/nologin -M mysql
[root@mysql ~]# chown -R mysql.mysql /mydata/data/
安装依赖
[root@mysql ~]# yum groupinstall -y "Development Tools" "Server Platform Development" "Desktop Platform Development"
[root@mysql ~]# yum install -y ncurses-devel.x86_64
安装cmake编译器
[root@mysql ~]# yum install -y cmake ----> cmake 在本地源里有
[root@mysql ~]# tar zxf mysql-boost-5.7.17.tar.gz
cmake. -L 查看cmake支持的编译选项
[root@mysql ~]# cd mysql-5.7.17/
[root@mysql mysql-5.7.17]# cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_DATADIR=/mydata/data \
-DMYSQL_TCP_PORT=3306 \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
[root@mysql mysql-5.7.17]# make
[root@mysql mysql-5.7.17]# make install
[root@mysql ~]# chown -R root.mysql /usr/local/mysql/
初始化数据库
[root@mysql ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
注意:这里会生成初始密码,务必保存一份
复制MySQL配置文件
[root@mysql ~]# cd /usr/local/mysql/support-files/
[root@mysql support-files]# cp my-default.cnf /etc/my.cnf
[root@mysql support-files]# vim /etc/my.cnf
[mysqld]
...
basedir=/usr/local/mysql
datadir=/mydata/data
port=3306
server_id=102
socket=/tmp/mysql.sock
启动mysql服务
[root@mysql data]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@mysql data]# ss -antp | grep mysqld
LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=63756,fd=20))
[root@mysql data]#
修改环境变量PATH
[root@mysql] export PATH=$PATH:/usr/local/mysql/bin 临时的
[root@mysql] echo $PATH
[root@mysql data]# cat /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@mysql data]# source /etc/profile.d/mysql.sh
[root@mysql data]# mysql -u root -p { ----->这里会用到初始密码 }
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Www.1.com';
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
设置源码mysql服务开机自启动
# vim /etc/rc.d/rc.local
/usr/local/mysql/bin/mysqld_safe --user=mysql &
三、安装php
1) 安装mcrypt, mhash数据加密认证组件
[root@php01 ~]# yum install -y libmcrypt-2.5.8-13.el7.x86_64.rpm libmcrypt-devel-2.5.8-13.el7.x86_64.rpm mcrypt-2.6.8-11.el7.x86_64.rpm mhash-0.9.9.9-10.el7.x86_64.rpm mhash-devel-0.9.9.9-10.el7.x86_64.rpm
2) 编译安装PHP
[root@php01 ~]# tar zxf php-5.6.27.tar.gz
[root@php01 ~]# cd php-5.6.27/
[root@php01 php-5.6.27]# ./configure --prefix=/usr/local/php
--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
--with-config-file-scan-dir=/etc/php.d --with-bz2
[root@php01 php-5.6.27]# make && make install
3) 复制PHP的配置文件
[root@php01 php-5.6.27]# cp php.ini-production /etc/php.ini
4) 复制php-fpm的配置文件
[root@php01 php]# cd /usr/local/php/etc/
[root@php01 etc]# ls
pear.conf php-fpm.conf.default
[root@php01 etc]# cp php-fpm.conf.default php-fpm.conf
[root@php01 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default
5) 复制php-fpm的启动脚本
[root@php01 fpm]# pwd
/root/php-5.6.27/sapi/fpm
[root@php01 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@php01 fpm]# chmod a+x /etc/init.d/php-fpm
[root@php01 fpm]# chkconfig --add php-fpm
[root@php01 fpm]# chkconfig php-fpm on
[root@php01 fpm]# chkconfig --list php-fpm
6) 编辑php-fpm.conf配置文件
[root@php01 ~]# useradd nginx
[root@php01 ~]# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 8
pm.max_spare_servers = 10
pid=/usr/local/php/var/run/php-fpm.pid
listen = 192.168.122.103:9000
user = nginx
group = nginx
7) 启动php-fpm服务
[root@php01 ~]# /etc/init.d/php-fpm start
[root@php01 ~]# ss -antp | grep :9000
LISTEN 0 128 192.168.122.103:9000 *:* users:(("php-fpm",pid=22906,fd=0),("php-fpm",pid=22905,fd=0),("php-fpm",pid=22904,fd=0),("php-fpm",pid=22903,fd=0),("php-fpm",pid=22902,fd=0),("php-fpm",pid=22901,fd=0),("php-fpm",pid=22900,fd=0),("php-fpm",pid=22899,fd=0),("php-fpm",pid=22898,fd=7))
8) 创建网页目录
[root@php01 ~]# mkdir -p /web/app
4、编辑nginx的配置文件,整合Nginx和PHP
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root /web/app;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /web/app;
fastcgi_pass 192.168.122.103:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@nginx ~]# mkdir -p /web/app
5、测试
1) 测试nginx与php正常
[root@php01 app]# cat /web/app/a.php
<?php
phpinfo();
?>
http://192.168.122.101/a.php
2) 测试PHP与MySQL
[root@php01 app]# cat /web/app/b.php
<?php
$link=mysql_connect("192.168.122.102","phpuser","redhat");
if($link)
echo "Successfully";
else
echo "Failure";
?>
在MySQL服务器上创建phpuser用户
mysql> GRANT all ON *.* TO "phpuser"@"192.168.122.103" IDENTIFIED BY "redhat";
mysql> FLUSH PRIVILEGES;
http://192.168.122.101/b.php