centos7.2下源码部署lnmp
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.2下源码部署lnmp相关的知识,希望对你有一定的参考价值。
一、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软件安装
[[email protected] nginx-1.11.10]# yum install -y gcc pcre-devel openssl-devel
[[email protected] ~]# useradd nginx
[[email protected] ~]# mkdir -p /usr/local/nginx/{client,proxy,fastcgi,uwsgi,scgi}
[[email protected] ~]# tar zxf nginx-1.11.10.tar.gz
[[email protected] ~]# cd nginx-1.11.10/
[[email protected] 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 \
[[email protected] nginx-1.11.10]# make && make install
启动nginx
[[email protected] ~]# /usr/local/nginx/sbin/nginx
[[email protected] ~]# ss -antp | grep nginx
LISTEN 0 128 *:80 *:* users:(("nginx",pid=7691,fd=6),("nginx",pid=7690,fd=6))
[[email protected] ~]# 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开机自启动
[[email protected] ~]# tail -1 /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx
[[email protected] ~]# chmod a+x /etc/rc.d/rc.local
二、mysql的安装
卸载系统自带的mariadb软件
[[email protected] ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[[email protected] ~]# rpm -e --nodeps mariadb-libs
修改数据目录的所属
[[email protected] ~]#mkdir -p /mydata/data ----> 做数据目录
[[email protected] ~]# useradd -s /sbin/nologin -M mysql
[[email protected] ~]# chown -R mysql.mysql /mydata/data/
安装依赖
[[email protected] ~]# yum groupinstall -y "Development Tools" "Server Platform Development" "Desktop Platform Development"
[[email protected] ~]# yum install -y ncurses-devel.x86_64
安装cmake编译器
[[email protected] ~]# yum install -y cmake ----> cmake 在本地源里有
[[email protected] ~]# tar zxf mysql-boost-5.7.17.tar.gz
cmake. -L 查看cmake支持的编译选项
[[email protected] ~]# cd mysql-5.7.17/
[[email protected] 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 \
[[email protected] mysql-5.7.17]# make
[[email protected] mysql-5.7.17]# make install
[[email protected] ~]# chown -R root.mysql /usr/local/mysql/
初始化数据库
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
注意:这里会生成初始密码,务必保存一份
复制MySQL配置文件
[[email protected] ~]# cd /usr/local/mysql/support-files/
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf
[[email protected] support-files]# vim /etc/my.cnf
[mysqld]
...
basedir=/usr/local/mysql
datadir=/mydata/data
port=3306
server_id=102
socket=/tmp/mysql.sock
启动mysql服务
[[email protected] data]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[[email protected] data]# ss -antp | grep mysqld
LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=63756,fd=20))
[[email protected] data]#
修改环境变量PATH
[[email protected]] export PATH=$PATH:/usr/local/mysql/bin 临时的
[[email protected]] echo $PATH
[[email protected] data]# cat /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[[email protected] data]# source /etc/profile.d/mysql.sh
[[email protected] 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数据加密认证组件
[[email protected] ~]# 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
[[email protected] ~]# tar zxf php-5.6.27.tar.gz
[[email protected] ~]# cd php-5.6.27/
[[email protected] 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
[[email protected] php-5.6.27]# make && make install
3) 复制PHP的配置文件
[[email protected] php-5.6.27]# cp php.ini-production /etc/php.ini
4) 复制php-fpm的配置文件
[[email protected] php]# cd /usr/local/php/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf.default
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default
5) 复制php-fpm的启动脚本
[[email protected] fpm]# pwd
/root/php-5.6.27/sapi/fpm
[[email protected] fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[[email protected] fpm]# chmod a+x /etc/init.d/php-fpm
[[email protected] fpm]# chkconfig --add php-fpm
[[email protected] fpm]# chkconfig php-fpm on
[[email protected] fpm]# chkconfig --list php-fpm
6) 编辑php-fpm.conf配置文件
[[email protected] ~]# useradd nginx
[[email protected] ~]# 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服务
[[email protected] ~]# /etc/init.d/php-fpm start
[[email protected] ~]# 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) 创建网页目录
[[email protected] ~]# mkdir -p /web/app
4、编辑nginx的配置文件,整合Nginx和PHP
[[email protected] ~]# 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;
}
[[email protected] ~]# mkdir -p /web/app
5、测试
1) 测试nginx与php正常
[[email protected] app]# cat /web/app/a.php
<?php
phpinfo();
?>
http://192.168.122.101/a.php
2) 测试PHP与MySQL
[[email protected] 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
本文出自 “lyw666” 博客,请务必保留此出处http://lyw666.blog.51cto.com/12823216/1957843
以上是关于centos7.2下源码部署lnmp的主要内容,如果未能解决你的问题,请参考以下文章