centos6.9编译安装lnmp环境2

zhufuzhong zhufuzhong     2022-12-24     169

关键词:

 

CentOS6.9编译安装LNMP环境

今天尝试一下用编译的方式来搭建lnmp运行环境。所有软件都采用当前最新版本,除了CentOS。这是由于目前企业大多数应该都还在使用CentOS6的缘故,并且CentOS7目前还在迭代中。虽说不会有大的改动,但也算不上完全稳定下来吧。

那么开始吧,这次也是边装边写的方式。

运行环境和软件版本

CentOS是运行在Virtual Box虚拟机上的 CentOS 6.9 x86_64 minimal 版本。宿主机是Windows10家庭普通版64位,这一点关系不大,姑且说明一下。在安装好系统后依次运行了 yum update  yum groupinstall "development tools"  yum install vim  yum install wget 来更新系统、安装开发者环境包、安装vim和wget。

Nginx、PHP、MySQL使用当前最新版本的 nginx-1.12.0  php-7.1.4  mysql-5.7.18 。

安装步骤

1.下载要安装的软件包

我这里是直接在虚拟机上用wget工具下载,命令如下:

1 wget http://nginx.org/download/nginx-1.12.0.tar.gz -O /usr/local/src/nginx-1.12.0.tar.gz

1 wget http://am1.php.net/distributions/php-7.1.4.tar.gz -O /usr/local/src/php-7.1.4.tar.gz

1 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz -O /usr/local/src/mysql-boost-5.7.18.tar.gz

当然你也可以在其它地方下载好再传到虚拟机上,随意。

注意文件访问权限,有些文件夹非root用户是不能访问的。还有,之所以选择mysql-boost-5.7.18.tar.gz这个安装包是因为mysql5.7编译安装需要用到boost,所以干脆选择了带boost的版本。虽然我也不太明白boost是个啥,好像是编译器的一种?

下载完毕:

 

接下来就开始编译安装了。

2.编译安装Nginx

就先从nginx开始吧。首先解压:

1 tar -zxv -f /usr/local/src/nginx-1.12.0.tar.gz -C /usr/local/src/

解压完成:

 

然后进入解压目录:

1 cd /usr/local/src/nginx-1.12.0

通过 ls 命令可以查看解压结果里包含了哪些文件。通过 ./configure --help | less 命令查看编译选项,按 q 退出。 

不过我这里只会安装 --with-http_ssl_module 、 --with-http_stub_status_module 、 --with-http_auth_request_module 、 --with-http_perl_module 、 --with-mail 、 --with-stream 、 --with-pcre 这几个模块。

安装模块需要环境的支持,考虑到我之前已经安装了development tools,应该没问题的。如果缺的话,报错了再补。

然后,需要创建nginx运行账号和nginx安装目录,命令如下:

1 useradd nginx -s /sbin/nologin -M

2 mkdir /usr/local/nginx-1.12.0

可以通过 cat /etc/passwd 和 ls /usr/local 查看创建的账号和目录。

接下来执行预编译脚本,如下:

 

 1 ./configure

 2 --prefix=/usr/local/nginx-1.12.0

 3 --user=nginx

 4 --group=nginx

 5 --with-select_module

 6 --with-poll_module

 7 --with-http_ssl_module

 8 --with-http_stub_status_module

 9 --with-http_auth_request_module

10 --with-http_perl_module

11 --with-mail

12 --with-stream

13 --with-pcre

 

然后报错了:

1 ./configure: error: the HTTP rewrite module requires the PCRE library.

2 You can either disable the module by using --without-http_rewrite_module

3 option, or install the PCRE library into the system, or build the PCRE library

4 statically from the source with nginx by using --with-pcre=<path> option.

看来是缺少pcre支持,那么补上: yum install pcre-devel pcre-static ,然后再执行一次。

这次是缺少openssl:

1 ./configure: error: SSL modules require the OpenSSL library.

2 You can either do not enable the modules, or install the OpenSSL library

3 into the system, or build the OpenSSL library statically from the source

4 with nginx by using --with-openssl=<path> option.

执行 yum install openssl-devel openssl-perl openssl-static ,然后再执行一次。

又又报错了:

 

1 checking for perl

2  + perl version: v5.10.1 (*) built for x86_64-linux-thread-multi

3 Can‘t locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).

4 BEGIN failed--compilation aborted.

5

6 ./configure: error: perl module ExtUtils::Embed is required

 

好像又是少了什么东西,搜索了一下,大概是要装这个: yum install perl-ExtUtils-Embed 。那么,再再执行一次吧。

这次没报错,执行预编译脚本成功。

 

可以编译安装了,分别执行 make 和 make install 吧。

等执行完毕,用 ls /usr/local/nginx-1.12.0 命令可以看到安装目录下有文件生成,接下来执行nginx命令查看是否成功安装。

执行 /usr/local/nginx-1.12.0/sbin/nginx -t ,结果如下:

 

说明安装成功。接着执行 /usr/local/nginx-1.12.0/sbin/nginx 就可以启动nginx服务。

执行 curl http://localhost 可以看到如下结果:

 

默认的主页html文件内容被获取了,说明服务确实成功启动。

为了不影响接下来的操作,执行 /usr/local/nginx-1.12.0/sbin/nginx -s quit 关闭nginx服务。

接下来安装PHP。

3.编译安装PHP

先解压: tar -zxv -f /usr/local/src/php-7.1.4.tar.gz -C /usr/local/src/ 。

创建安装目录: mkdir /usr/local/php-7.1.4 。

进入安装包目录: cd /usr/local/src/php-7.1.4 ,可以通过执行预编译脚本 ./configure --help | less 来查看有哪些安装选项。

可以看到php的安装选项众多,扩展数量多也是php的强大之处。

考虑到常用的功能和特性,还有php可以在安装后安装扩展,现在还是尽可能少的选择安装选项吧。

 

 1 ./configure

 2 --prefix=/usr/local/php-7.1.4

 3 --enable-fpm

 4 --with-fpm-user=nginx

 5 --with-fpm-group=nginx

 6 --with-mysqli

 7 --with-pdo-mysql

 8 --with-zlib

 9 --with-gd

10 --with-curl

11 --with-mcrypt

12 --enable-mbstring

13 --enable-soap

14 --enable-zip

15 --enable-ftp

16 --with-openssl

 

稍微查了一下,暂且按上述选项编译吧。

报错了:

1 configure: error: xml2-config not found. Please check your libxml2 installation.

望文生义貌似是libxmls的缺少造成的。那么执行 yum install libxml2 libxml2-devel libxml2-static 补上我猜可能必要的开发环境。然后接着执行上述的预编译脚本。

又报错了:

1 configure: error: Please reinstall the libcurl distribution -

2     easy.h should be in <curl-dir>/include/curl/

这次是libcurl,补上 yum install libcurl libcurl-devel ,再来。

又又报错了:

 

 1 checking for GD support... yes

 2 checking for the location of libwebp... no

 3 checking for the location of libjpeg... no

 4 checking for the location of libpng... no

 5 checking for the location of libXpm... no

 6 checking for FreeType 2... no

 7 checking whether to enable truetype string function in GD... no

 8 checking whether to enable JIS-mapped Japanese font support in GD... no

 9 If configure fails try --with-webp-dir=<DIR>

10 If configure fails try --with-jpeg-dir=<DIR>

11 configure: error: png.h not found.

 

这次是和GD库又关,因为是和图像处理有关的扩展,所以jpeg、png、gif等图像开发环境是必要的。

但是我想尽可能少安装,所以先试试 yum install gd gd-devel 。然后执行预编译脚本。

gd库的检测通过了,但是出现了新的错误:

1 configure: error: mcrypt.h not found. Please reinstall libmcrypt.

这次是mcrypt库的问题,问题是CentOS6.9的yum库已经不支持mcrypt的安装,改用gcrypt了。没办法,自己下载吧。

根据php的官方文档:

需求

这些函数需要使用 ? mcrypt 库。 请从 ? http://mcrypt.sourceforge.net/ 下载 libmcrypt-x.x.tar.gz, 并按以下指导完成安装。

从 PHP 5.0.0 开始,你需要使用 libcrypt 2.5.6 或更高版本。

PHP 5.2 的 Windows 二进制发行版中已经包含了本库。 PHP 5.3 的 Windows 二进制发行版中开始使用 MCrypt 静态库, 所以不再需要 DLL。

如果使用 libmcrypt 2.4.x 或更高版本链接编译 PHP,支持以下附加的分组加密算法: CAST,LOKI97,RIJNDAEL,SAFERPLUS,SERPENT, 以及以下流密码:ENIGMA(加密), PANAMA,RC4 和 WAKE。 如果使用 libmcrypt 2.4.x 或更高版本,那么还支持 nOFB 密码模式。

可以知道php所需要的mcrypt库的下载地址和安装方法,照做就可以了。

先下载 wget https://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz -O /usr/local/src/libmcrypt-2.5.8.tar.gz ,然后解压 tar -zxv -f /usr/local/src/libmcrypt-2.5.8.tar.gz -C /usr/local/src/ ,创建安装目录 mkdir/usr/local/libmcrypt-2.5.8 ,进入解压生成的目录 cd /usr/local/src/libmcrypt-2.5.8 ,执行预编译脚本 ./configure --prefix=/usr/local/libmcrypt-2.5.8 ,编译和安装 make && make install 。到此,libmcrypt的安装就完成了。接着进入php安装包解压生成的目录执行php的预编译脚本。

执行后发现还是报和之前一样的错误,可能是安装libmcrypt时自定义了安装路径的原因。这里需要修改一下php的预编译脚本的编译选项:

 

 1 ./configure

 2 --prefix=/usr/local/php-7.1.4

 3 --enable-fpm

 4 --with-fpm-user=nginx

 5 --with-fpm-group=nginx

 6 --with-mysqli

 7 --with-pdo-mysql

 8 --with-zlib

 9 --with-gd

10 --with-curl

11 --with-mcrypt=/usr/local/libmcrypt-2.5.8

12 --enable-mbstring

13 --enable-soap

14 --enable-zip

15 --enable-ftp

16 --with-openssl

 

注意第11行, --with-mcrypt 选项指明了安装路径。再次执行php的预编译脚本,这次没有报错,执行成功。

 

接着只要依次执行 make 和 make install 就可以了,当然也可以放在一起执行 make && make install 。

一般在编译和安装的过程中是不会出什么问题,我也从来没在这出过问题,所以也没有解决的经验。

然后就是简单配置一下看看能不能用。

根据预编译选项 --prefix 和帮助信息,得知php.ini文件应该放在[PREFIX]/lib目录下。那么我们就在该目录下生成一个配置文件吧: cp/usr/local/src/php-7.1.4/php.ini-development /usr/local/php-7.1.4/lib/php.ini 。我记得不用改什么吧。

然后是php-fpm。首先 cp /usr/local/php-7.1.4/etc/php-fpm.conf.default /usr/local/php-7.1.4/etc/php-fpm.conf ,大概看了一下,还需要 cp/usr/local/php-7.1.4/etc/php-fpm.d/www.conf.default /usr/local/php-7.1.4/etc/php-fpm.d/www.conf 。内容不用改,反正是试运行。

还需要配置一下nginx并启动,执行 vim /usr/local/nginx-1.12.0/conf/nginx.conf :

 

将65行至71行的注释去掉,并将69行的内容按上图改动,接着保存退出。

生成一个测试用的php脚本 vim /usr/local/nginx-1.12.0/html/index.php :

 

注意文件位置。

启动nginx服务: /usr/local/nginx-1.12.0/sbin/nginx 。或者在启动前检查一下配置文件是否出错: /usr/local/nginx-1.12.0/sbin/nginx -t 。

启动php-fpm: /usr/local/php-7.1.4/sbin/php-fpm 。

关闭iptables: service iptables stop 。

然后在宿主机的浏览器内输入 http://192.168.31.222/index.php 。前面的ip地址因人而异,可以通过 ifconfig 命令查看。显示如下页面说明成功了:

 

可以通过 ps -aux | grep "php-fpm" 命令查看php-fpm的主进程号,然后通过 kill -quit 2505 来关闭服务。注意这个2505是我的虚拟机上运行的php-fpm的主进程号,这个号码一般都是不同的。

4.编译安装MySQL

5.7版本的MySQL编译和初始化都挺麻烦的,尤其是要自定义安装路径和选项。走到这一步我也不确定能否顺利安装好,姑且按照文档走一步算一步吧。

通过文档的2.9 Installing MySQL from Source这一章节可以知道,cmake工具在编译时是必要的。此外,还需要安装boost。如果安装的是development source tree这一版本,还需要安装git和bison。

那么先准备安装环境吧。执行 yum install cmake 来安装cmake。虽然不知道development source tree是什么,但是为了以防万一还是把git和bison也装上吧: yum install bison git 。

解压安装包: tar -zxv -f /usr/local/src/mysql-boost-5.7.18.tar.gz -C /usr/local/src/ 。通过 ls /usr/local/src/mysql-5.7.18/ 命令可以看到解压生成的目录中附带了boost。

 

一层层的看进去发现并不是安装文件,更像是已经安装好的文件,那我们就不用再安装boost了。反正根据文档,boost只是在编译的时候用到。

那么现在查看文档看看安装的步骤吧。

首先要创建MySQL服务运行时的账户 useradd mysql -s /sbin/nologin -M 。然后创建安装目录 mkdir /usr/local/mysql-5.7.18 。

接着进入解压生成的目录 cd /usr/local/src/mysql-5.7.18/ 。可以通过 ls 命令查看目录下的文件。还可以通过 cmake . -LAH | less 来查看帮助和安装选项。

发现通过上述命令获取的帮助信息不好懂且没有调理,还是得看文档2.9.4 MySQL Source-Configuration Options。研究了一下,编译选项如下:

1 cmake .

2 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18

3 -DWITH_BOOST=/usr/local/src/mysql-5.7.18/boost

打算偷个懒,就这样预编译试试看吧。 

啊,报错了:

 

 1 -- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

 2 CMake Error at cmake/readline.cmake:64 (MESSAGE):

 3   Curses library not found.  Please install appropriate package,

 4

 5       remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

 6 Call Stack (most recent call first):

 7   cmake/readline.cmake:107 (FIND_CURSES)

 8   cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)

 9   CMakeLists.txt:488 (MYSQL_CHECK_EDITLINE)

10

11

12 -- Configuring incomplete, errors occurred!

13 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeOutput.log".

14 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeError.log".

 

查了一下,好像是缺ncurses组件。那就补上吧: yum install ncurses ncurses-devel ncurses-libs ncurses-static 。之后再次执行预编译。

再次执行却以更快的速度报一样的错,仔细一看原来少执行了一步操作: remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. 。好吧,删掉目录下的CMakeCache.txt文件 rm CMakeCache.txt ,然后再次执行。

这次顺利预编译完了:

 

接下来依次执行 make 和 make install 就行了。

编译的过程相当之慢,我去做其他事情好了。

 

编译过程中报了这个错误,不知道有什么影响没有。话说这和boost有关吧?难道是我的boost没好好安装的原因?

 

阿西吧,终于编译完了,中间我洗了个澡还看了集动漫。接着执行 make install 。

我擦,报错了:

 

 

1 CMake Error at libmysqld/examples/cmake_install.cmake:44 (FILE):

2   file INSTALL cannot copy file

3   "/usr/local/src/mysql-5.7.18/libmysqld/examples/CMakeFiles/CMakeRelink.dir/mysql_client_test_embedded"

4   to "/usr/local/mysql-5.7.18/bin/mysql_client_test_embedded".

5 Call Stack (most recent call first):

6   cmake_install.cmake:122 (INCLUDE)

7

8

9 make: *** [install] Error 1

 

算了算了,时间不早了。先睡觉,明天再说吧。

我回来了。

查了一下,上述错误是由缺少gcc和gcc-c++引起的,那就干脆补上所有有关的: yum install gcc gcc-c++ gcc-java gcc-gnat libgcc compat-gcc-34compat-gcc-34-c++ compat-gcc-34-g77 gcc-objc gcc-objc++ 。

我勒个擦,虚拟机的硬盘满了:

 

 1 Running rpm_check_debug

 2 Running Transaction Test

 3

 4

 5 Transaction Check Error:

 6   installing package gcc-objc-4.4.7-18.el6.x86_64 needs 11MB on the /usr filesystem

 7   installing package ecj-1:4.5.2-3.el6.x86_64 needs 21MB on the /usr filesystem

 8   installing package libgnat-devel-4.4.7-18.el6.x86_64 needs 46MB on the /usr filesystem

 9   installing package libgnat-4.4.7-18.el6.x86_64 needs 50MB on the /usr filesystem

10   installing package gcc-gnat-4.4.7-18.el6.x86_64 needs 73MB on the /usr filesystem

11   installing package jpackage-utils-0:1.7.5-3.16.el6.noarch needs 73MB on the /usr filesystem

12   installing package compat-gcc-34-c++-3.4.6-19.el6.x86_64 needs 162MB on the /usr filesystem

13   installing package gcc-java-4.4.7-18.el6.x86_64 needs 172MB on the /usr filesystem

14   installing package compat-gcc-34-3.4.6-19.el6.x86_64 needs 185MB on the /usr filesystem

15   installing package compat-libf2c-34-3.4.6-19.el6.x86_64 needs 185MB on the /usr filesystem

16   installing package libgcj-devel-4.4.7-18.el6.x86_64 needs 203MB on the /usr filesystem

17   installing package gcc-objc++-4.4.7-18.el6.x86_64 needs 213MB on the /usr filesystem

18   installing package java_cup-1:0.10k-5.el6.x86_64 needs 214MB on the /usr filesystem

19   installing package compat-gcc-34-g77-3.4.6-19.el6.x86_64 needs 220MB on the /usr filesystem

20   installing package sinjdoc-0.5-9.1.el6.x86_64 needs 223MB on the /usr filesystem

21   installing package libobjc-4.4.7-18.el6.x86_64 needs 223MB on the /usr filesystem

22   installing package java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64 needs 223MB on the /usr filesystem

23

24 Error Summary

25 -------------

26 Disk Requirements:

27   At least 223MB more space needed on the /usr filesystem.

 

这叫老夫如何是好,网上查查怎么加硬盘或者重新分区之类的吧。实在不行只能重装了。

网上看了看,可能要用到fdisk和Virtual Box Manager。我都不太熟而且好麻烦QAQ,算了算了,重装一个虚拟机吧orz

这次分30G给/usr/local,总没问题了吧。

等等等等,仔细看了一下,发现容量都是被下载的软件包和解压包给占据了,只要把它们删掉就好。

 

总之,删掉就好了。

 

啊~不用重装了,被救赎。

继续吧,运行 yum install gcc gcc-c++ gcc-java gcc-gnat libgcc compat-gcc-34 compat-gcc-34-c++ compat-gcc-34-g77 gcc-objc gcc-objc++ 。

考虑到之前编译MySQL的过程中好像报了boost相关的warning,决定还是老老实实的安装boost吧。

首先下载安装包:

1 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18.tar.gz -O /usr/local/src/mysql-5.7.18.tar.gz

1 wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz -O /usr/local/src/boost_1_59_0.tar.gz

这次换不带boost的MySQL版本,然后按文档里说的,boost必须是1.59版本。

用wget下载boost实在太慢了,最后我上了迅雷,下载好后传到了虚拟机上。

解压boost tar -zxv -f /usr/local/src/boost_1_59_0.tar.gz -C /usr/local/src/ 。创建安装目录 mkdir /usr/local/boost-1.59.0 。进入解压生成的目录 cd /usr/local/src/boost-1.59.0 。执行预编译脚本 ./bootstrap.sh --prefix=/usr/local/boost-1.59.0 。然后执行 ./b2 ,这一步必较久,等着吧。报了一些看不懂的错误,查了一下还要安装依赖什么的,那就装上吧 yum install gcc gcc-c++ bzip2 bzip2-libs bzip2-devel python python-devel 。删掉解压的目录前面的步骤再执行一次。接着执行 ./b2 install 就ok了。

接下来重新编译安装MySQL。

删除之前的安装生成文件 rm -rf /usr/local/mysql-5.7.18/* 。解压新的安装文件 tar -zxv -f /usr/local/src/mysql-5.7.18.tar.gz -C /usr/local/src/ 。进入解压生成的目录 cd /usr/local/src/mysql-5.7.18 。执行预编译命令 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 -DWITH_BOOST=/usr/local/boost-1.59.0 。

啊,报错了:

 

 1 CMake Error at cmake/boost.cmake:81 (MESSAGE):

 2   You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

 3

 4   This CMake script will look for boost in <directory>.  If it is not there,

 5   it will download and unpack it (in that directory) for you.

 6

 7   If you are inside a firewall, you may need to use an http proxy:

 8

 9   export http_proxy=http://example.com:80

10

11 Call Stack (most recent call first):

12   cmake/boost.cmake:167 (COULD_NOT_FIND_BOOST)

13   CMakeLists.txt:460 (INCLUDE)

14

15

16 -- Configuring incomplete, errors occurred!

17 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeOutput.log".

18 See also "/usr/local/src/mysql-5.7.18/CMakeFiles/CMakeError.log".

 

想想应该是预编译时boost的包含路径有问题,应该包含安装生成文件里的include目录。那么,依次执行  rm CMakeCache.txt 和 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.18 -DWITH_BOOST=/usr/local/boost-1.59.0/include 。

结果ok。接下来执行 make 和 make install 就可以了。

漫长的等待过程,去干点别的吧。

终...终于好了。

接下来就是初始化了。

按照文档,要先修改安装目录和文件所属组和所属用户 chgrp -R mysql /usr/local/mysql-5.7.18  chown -R mysql /usr/local/mysql-5.7.18 。

接下来创建一个放数据库文件、socket文件、pid文件和配置文件的目录,就放在/var目录下好了

1 mkdir /var/local/mysql-5.7.18

2 mkdir /var/local/mysql-5.7.18/data

3 mkdir /var/local/mysql-5.7.18/run

4 mkdir /var/local/mysql-5.7.18/log

5 mkdir /var/local/mysql-5.7.18/etc

生成一个配置文件 vim /var/local/mysql-5.7.18/etc/my.cnf ,内容为:

 

[client]

port=3306

socket=/var/local/mysql-5.7.18/run/mysql.sock

 

[mysql]

no-auto-rehash

 

[mysqld]

basedir=/usr/local/mysql-5.7.18

datadir=/var/local/mysql-5.7.18/data

user=mysql

port=3306

socket=/var/local/mysql-5.7.18/run/mysql.sock

pid-file=/var/local/mysql-5.7.18/run/mysql.pid

 

网上抄来的,似懂非懂。

把上述目录和文件都修改所属 chgrp -R mysql /var/local/mysql-5.7.18  chown -R mysql /var/local/mysql-5.7.18 。

然后执行初始化命令:

1 /usr/local/mysql-5.7.18/bin/mysqld

2 --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf

3 --initialize

4 --character_set_server=utf8

5 --collation_server=utf8_general_ci

虽然报了一些看不懂的警告,但是初始化好像是成功了,还生成了随机密码:

 

1 2017-04-24T10:27:35.480795Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2 2017-04-24T10:27:36.378470Z 0 [Warning] InnoDB: New log files created, LSN=45790

3 2017-04-24T10:27:36.557201Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

4 2017-04-24T10:27:36.666538Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a2c08f2f-28d8-11e7-b53a-08002728b6d3.

5 2017-04-24T10:27:36.673556Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.

6 2017-04-24T10:27:36.676216Z 1 [Note] A temporary password is generated for [email protected]: jyJoLj>9G_!-

 

接下来试着启动服务 /usr/local/mysql-5.7.18/bin/mysqld --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf & ,按 Ctrl + C 退出控制台占用,执行 /usr/local/mysql-5.7.18/bin/mysql --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf -u root -p ,之后要输入密码。后面的密码来自之前初始化后成功的提示的最后一行。

5.8版本规定进入MySQL后并不能执行任何操作,必须先改密码 ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘new_password‘; 。且密码必须大于8位,包含字符数字字母,真是烦死了。

 

如图,终于成功了。接下来可以执行 exit 退出。再接着可以执行 /usr/local/mysql-5.7.18/bin/mysqladmin --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf shutdown -u root -p 后输入密码来结束服务。

至此,MySQL5.7.18终于他喵的装好了。 

5.测试NginxPHPMySQL协同工作

接下来就是让这三个软件协同工作,成为一个可以跑php代码的环境。

首先启动所有服务:

1 /usr/local/nginx-1.12.0/sbin/nginx

2 /usr/local/php-7.1.4/sbin/php-fpm

3 /usr/local/mysql-5.7.18/bin/mysqld --defaults-file=/var/local/mysql-5.7.18/etc/my.cnf &

记得关闭iptables服务 service iptables stop 。

在数据库中创建一个test数据库。

创建一个测试用的PHP脚本 vim /usr/local/nginx-1.12.0/html/mysql.php  vim /usr/local/nginx-1.12.0/html/mysql.php ,其内容为:

 

 1 <?php

 2 echo "hello world";

 3 echo "<br>";

 4 echo "MySQLi<br>";

 5 $mysqli=new mysqli("127.0.0.1","root",‘[email protected]#123qwe‘,"test");

 6 if($mysqli->connect_error)

 7     echo "数据库连接失败!";

 8 else

 9     echo "数据库连接成功!";

10

11 echo "<br>";

12 echo "PDO<br>";

13 try

14     $dbc=new PDO("mysql:host=127.0.0.1;dbname=test","root","[email protected]#123qwe");

15 catch(PDOExtension $e)

16     echo "数据库连接失败:".$e->getMessage();

17

18 echo "数据库连接成功!";

19 ?>

 

然后访问这个脚本 http://192.168.31.222/mysql.php ,结果如下:

 

OK~没有问题~

总结

一步步操作下来,发现环境搭配对萌新来说一点都不友好。所以我觉得志不在运维的同学还是用集成环境吧,那个多省事的。

还有半吊子就不要参与运维了,会给人添麻烦的。

这还只是配了个能跑的环境,还没考虑性能的优化,MySQL主从这些蛋疼的东西。所以运维还是得交给专业的来。

有空的话多学学MySQL,很有必要。

 


lnmp环境编译安装

安装nginx[[email protected]src]#tar-xfnginx-1.6.2.tar.gz [[email protected]src]#lsnginx-1.6.2 nginx-1.6.2.tar.gz[[email protected]nginx-1.6.2]#[[email protected]nginx-1.6.2 查看详情

lnmp环境搭建

...1)创建用户(2)安装所需的依赖包(3)解压(4)配置编译程序(5)编译并安装php(6)修改配置文件(7)启动php4.安装Nginx(1)下载(2)解压nginx(3)配置编译参数(4)编译nginx(5)安装nginx(6)编写nginx启动 查看详情

源码编译安装lnmp架构环境

源码编译安装LNMP架构环境OS版本:2.6.32-431.el6.x86_64Nginx版本:nginx-1.6.1mariadb版本:mariadb-10.0.13php版本:php-5.4.261、安装编译安装所需系统环境~]#yumgroupinstall"DevelopmentTools""ServerPlatformDevelopment"-y2、编译安装nginx-1.6.1#yum 查看详情

centos6.9编译安装httpd2.4

实验环境准备:官网http://www.apache.org/下载源代码httpd2.4,以及相关依赖包apr-1.6.2,apr-util-1.6.0准备没有安装过httpd任何版本的centos6.9系统安装开发包]#yum install openssl-devel -y]#yum install pcre-devel -y]#yu 查看详情

源码编译安装lnmp环境

一、源码编译安装步骤首先说明源码安装的好处  速度快,可自定义路径主要有三步:1.配置进入源码安装包 ./configure--prefix=/uer/local/nginx 可指定参数--prefix为安装路径2.编译相当于rpm包 make3.安装makeinstall如果安... 查看详情

centos6.8编译安装lnmp环境

Centos6.8编译安装LNMP环境参考资料:http://www.jb51.net/article/107429.htmhttps://phperzh.com/articles/1360一准备工作 环境介绍: OS:Centos6.8最小化安装 Nginx:nginx-1.12.2.tar.gz mysql:mysql-boost-5.7.20.tar. 查看详情

centos6.9编译安装cmake3.10.2

1.去官网下载cmake源码包https://cmake.org/cmake最新版本3.10.2需要c++11支持,gcc4.8以下并未包含,因此,需要准备好新版本的gcc.gcc编译请参考cmake-3.9.6版本,此版本并不需要C++112.检查环境变量PATH=/usr/local/gcc-4.8.5/bin:$PATH3.检查动态库#cat/... 查看详情

centos7.2编译安装lnmp

一、前言1、环境说明基础环境Linux+Nginx+MySQL+PHPlinux:7.2nginx:1.10.2mysql:5.6.17php:5.5.122、部署说明php安装目录:/usr/local/phpphp.ini配置文件路径:/usr/local/php/etc/php.iniNginx安装目录:/usr/local/nginxNginx配置文件路径:/etc/nginx/nginx 查看详情

centos6.9安装桌面环境

1、安装Desctop组yumgroupinstall"Desktop"2、安装XWindowyumgroupinstall"XWindowSystem"3、安装中文支持yumgroupinstall"ChineseSupport"4、reboot重启服务器5、运行startx命令进入图形化编辑/etc/inittab文件,修改启级别为5 查看详情

源码编译lnmp环境

 一、环境准备:1.部署LNMP架构需要安装依赖包yum-yinstallmakegccgcc-c++flexbisonfilelibtoollibtool-libsautoconfkernel-devellibjpeglibjpeg-devellibpnglibpng-develgdfreetypefreetype-devellibxml2libxml2-develzlibzlib-d 查看详情

centos7一键编译安装lnmp环境

#!/bin/sh#!/bin/sh#author: vim#qq: 82996821#OS: Centos7.2#filename: auto_install_lnmp.sh#init variablePHP_VERSION=‘7.0.20‘    #PHP版本号NGINX_VERSION=‘1.10.3‘ 查看详情

lnmp环境搭建

centos7编译安装nginx-1.4.7.tar.gz编译安装nginx需要事先需要安装开发包组"DevelopmentTools"和"DevelopmentLibraries"。同时,还需要专门安装pcre-devel包:#yum-yinstallpcre-devel2、安装首先添加用户nginx,实现以之运行nginx服务进程:#groupadd-rnginx#user... 查看详情

centos6.9源码编译httpd2.4

...是Apache软件基金会的一个开放源码的网页web服务器;由于centos6默认安装的是httpd2.2版本,不具有httpd2.4的新特性,为了在6版本上使用2.4版本的,从而能利用httpd2.4的新功能,更好的完成工作中的需求。准备事项:1、系统环境: ... 查看详情

centos6源码编译安装lnmp环境(代码片段)

操作系统版本64位CentOS-6.6  10.0.0.20安装环境所需依赖包yum-yinstallgccautomakeautoconflibtoolmakegcc-c++glibclibxslt-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlib 查看详情

centos6.9编译安装新版本内核

一、编译安装前准备:1、安装依赖包组:#yum-ygroupinstall"ServerPlatformDevelopment""DevelopmentTools"2、从https://www.kernel.org/下载需要编译的内核源码包linux-3.10.105.tar.xz,并上传至服务器 二、编译安装新版本内核linux-3.10.105.tar.xz:1、查... 查看详情

编辑安装lnmp(代码片段)

....安装Nginx服务关闭防火墙1.安装依赖包2.创建运行用户3、编译安装4、优化路径5、添加Nginx系统服务三.安装MySQL服务1、安装Mysql环境依赖包2.创建运行用户3.编译安装4、修改mysql配置文件5、更改mysql安装目录和配置文件的属主属组6.... 查看详情

使用编译搭建lnmp环境

...要逐一安装这几个包下面我们就逐一安装各种包安装环境centos6.8_64一、安装Nginx1.10.3卸载Linux自带的MySQL5.1.73、安装Nginx使用下面命令卸载yumremovemysql-y安装Nginx需要的依赖包yum-yinstallgccgcc-c++autoconfautomakezlibzlib- 查看详情

lnmp环境编译安装(代码片段)

先安装nginx我的lnmp时编译安装的,下载Nginx安装包wgethttp://nginx.org/download/nginx-1.13.4.tar.gz关闭selinux和防火墙setenforce0serviceiptablesstop检查安装依赖项 (执行下面的命令安装nginx的依赖库)yum-yinstallgccpcrepcre-develzlibzlib-develo 查看详情