CentOS 7源码安装最新版LNMP环境

由于公司要求需要最新版的ZABBIX2.4.4需要最新版的系统CentOS7和最新版的LNMP环境,所以本人摸索着使用最新版的环境搭建了LNMP系统,环境版本如下:
系统:CentOS 7 x86_64
NGINX:nginx-1.7.12
数据库:mariadb-10.0.13
PHP:php-5.5.23
首先做一些准备工作,先把centos7的防火墙更换成iptables,可以参见如下链接
centos7防火墙改为iptables

修改成iptables之后就可以清空iptables里面的过滤规则了,然后再关闭selinux服务。记得不要忘了先安装gcc gcc-c++ wget net-tools等功能哦。

首先安装mariadb

应为数据库编译需要很长时间,所以我这里下载的是已经编译好了的二进制包,下载版本为 mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1、下载二进制包到/usr/local/src 目录下:
[root@centos74 ~]# cd /usr/local/src/
[root@centos74 src]# wget
2、将压缩包解压到/usr/local 目录下:
[root@centos74 src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz -C /usr/local/
3、创建mariadb 数据初始化目录/data/MySQL:
[root@centos74 src]# mkdir -p /data/mysql
4、添加系统用户mysql,禁止登陆系统,同时,将mariadb 数据初始化目录所属主和组都修改为mysql:
[root@centos74 src]# useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql /data/mysql/
5、重命名解压出来的mariadb 目录:
[root@centos74 src]# mv /usr/local/mariadb-10.0.13-linux-x86_64/ /usr/local/mysql
6、进入重命名后的目录,初始化mariadb:
[root@centos74 src]# cd /usr/local/mysql/
[root@centos74 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
140906  2:03:19 [Note] InnoDB: Using mutexes to ref count buffer pool pages
140906  2:03:19 [Note] InnoDB: The InnoDB memory heap is disabled
140906  2:03:19 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140906  2:03:19 [Note] InnoDB: Compressed tables use zlib 1.2.3
140906  2:03:19 [Note] InnoDB: Using Linux native AIO
140906  2:03:19 [Note] InnoDB: Using CPU crc32 instructions
140906  2:03:19 [Note] InnoDB: Initializing buffer pool, size = 128.0M
........................................................................
The latest information about MariaDB is available at
You can find additional information about the MySQL part at:

Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:

报错:WARNING: The host 'test4' could not be looked up with resolveip.
解决办法:vim /etc/hosts 在最后一行添加192.168.1.242 test4
报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:yum -y install libaio-devel libaio
7、复制配置文件到/etc目录覆盖之前的my.cnf:
[root@centos74 mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
8、复制mysql 启动脚本文件到/etc/init.d 目录下并重命名为mysqld:
[root@centos74 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
同时修改启动脚本的权限为755:
[root@centos74 mysql]# chmod 755 !$
chmod 755 /etc/init.d/mysqld
9、编辑启动脚本,定义datadir 路径:
[root@centos74 mysql]# vim /etc/init.d/mysqld
定义数据存放路径:
datadir=/data/mysql
10、将mariadb自带命令放入$PATH
[root@localhost ~]# PATH=$PATH:/etc/init.d/#当前有效,重启shell就失效
[root@localhost ~]# echo "export PATH=$PATH:/etc/init.d/" >>/etc/profile
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
[root@localhost ~]# source !$


11、启动mariadb:
[root@centos74 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

第二步,开始安装php

这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。同样的,php官方下载地址:
下载php
[rot@localhost src]# cd /usr/local/src
[root@localhost src]# wget
解压php
[root@localhost src]# tar zxf php-5.5.23.tar.gz
创建相关账户
[root@localhost src]# useradd -s /sbin/nologin php-fpm
配置编译参数
[root@localhost src]# cd php-5.5.23
[root@localhost src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
[root@localhost php-5.5.23]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
错误:configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:yum -y install libxml2-devel
错误:configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:yum -y install libcurl-devel
错误:configure: error: jpeglib.h not found.
解决办法:yum -y install libjpeg-turbo-devel
错误:configure: error: png.h not found.
解决办法:um -y install libpng-devel
错误:configure: error: freetype-config not found.
解决办法:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:yum -y install libmcrypt-devel

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8c78f028d8f1ce776d6fe1d1df2262d1.html