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

时间: 2024-11-05 01:43:47

centos7.2下源码部署lnmp的相关文章

ubuntu16 下 源码配置Lnmp开发环境

最近把系统升级到 ubuntu16长期支持版 ,重新部署了lnmp环境 约定几个目录  源码目录  /usr/local/src mysql     /usr/local/mysql php  /usr/local/php nginx  /usr/local/nginx mysql   版本 5.7.14 必备的包和工具 gcc/g++ :MySQL 5.6开始,需要使用g++进行编译. bison  :MySQL语法解析器需要使用bison进行编译. libncurses5-dev :用于终端

centos7.4下源码安装mariadb

一.卸载旧的mariadb 查询已安装的软件: rpm -qa | grep Maria* 卸载:yum -y remove mari* 删除数据库文件:rm -rf /var/lib/mysql/* 二.安装依赖包且源码安装cmake yum groupinstall "Development Tools" yum install libaio libaio-devel bison bison-devel zlib-devel cmake openssl openssl-devel

CentOS7.X环境下源码包安装部署RabbitMQ3.7.17

本文介绍在CentOS7.X环境下源码包安装部署RabbitMQ3.7.17,使用docker安装很简单,这里我就不往文章中添加.在CentOS7.X环境下使用源码包安装还是有遇到不少坑的(使用yum安装的方式官方网站有介绍,比较简单),通过这篇我的个人实践操作,能够帮助到有需要的人.搭建环境:操作系统:CentOS7.5内存大小:16GB硬盘:100G注:正文中的参数与部署路径等,请根据实际需求修改.1.软件准备:wxWidgets-3.1.2.tar.bz2otp_src_22.0.tar.

lnmp 源码部署------2

安装php扩展软件 #哈稀函数库 [[email protected] ~ ]# tar -zxvf mhash-0.9.9.9.tar.gz [[email protected] mhash-0.9.9.9]# cd mhash-0.9.9.9 [[email protected] mhash-0.9.9.9]# ./configure [[email protected] mhash-0.9.9.9]# make [[email protected] mhash-0.9.9.9]# make

CentOS7 下源码安装MySQL 8.0.11

CentOS7 下源码安装MySQL 8.0.11 系统环境:CentOS7, 内核:Linux 3.10.0-862.el7.x86_64 如果有旧版本的MySQL,先卸载,用下面命令来查询出系统有哪些相关的MySQL包. rpm -qa | grep mysql 如果上述命令查询出有相关的MySQL包,就卸载 rpm -e 包名 卸载MariaDB包 yum remove mariadb-libs.x86_64 从MySQL官网下载源码包,并将该文件拷贝到系统中. https://dev.m

CentOS 7下源码安装MySQL 5.7

网上说linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有几十M左右,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度快,安装步骤简单,缺点是安装包很大,300M左右(5.7版本的是600M左右), 对于第二种方法,我搞了一天,无果,到某个环节实在是无法走通,老大那边也不让搞了,隔了几天老大又吩咐我在生产服务器上安装mysql,这次我就按照第一种方法源码安装方式 下载源码安装包 http://dev.my

CentOS 6.6 下源码编译安装MySQL 5.7.5

版权声明:转自:http://www.linuxidc.com/Linux/2015-08/121667.htm 说明:CentOS 6.6 下源码编译安装MySQL 5.7.5 1. 安装相关工具# yum -y install gcc-c++ ncurses-devel cmake make perl \ gcc autoconf automake zlib libxml libgcrypt libtool bison2. 清理环境检查boost版本: # rpm -qa boost*卸载b

kettle源码部署

一 kettle源码部署概述 1.从git上选择合适的版本,并down下来: 2.创建一个java项目,建立core,dbdialog,engine,ui,plugins文件夹,和一个lib文件夹: 3.将kettle源码中上述五个文件夹中的src下的代码拷贝到我们创建的java项目的五个文件夹下: 4.将发行版kettle工具免安装包的lib,libswt,launcher,simple-jndi 四个文件夹拷贝至java项目根目录,并系统的位数选择libswt.jar  add to bui

CloudStack 4.3 源码部署+eclipse远程调试

CloudStack 4.3 源码部署 系统环境 vmware workstation 下创建一个虚拟机 装有Centos6.5  64bit 安装软件 1.yum install git mysql mysql-server mkisofs gcc python MySQL-python openssh-clients wget 2.下载maven 并解压到 /root/maven 目录 3.下载ant 并解压到 /root/ant 目录 4.下载sun jdk 7 并解压到 /root/jd