前戏:
1.系统:Ubuntu 14 或者 Debian 7
2.准备LNMP环境所需的源码包
Nginx : nginx-1.11.2.tar.gz
PHP : php-5.4.22.tar.gz
Mysql : mysql-boost-5.7.12.tar.gz(这是内嵌boost的MySQL版本)
############################### 我有话说 ###############################
在此声明一点:使用哪个Linux系统都差异不大,重要是不同系统安装的依赖包名称不一致。当然,小众Linux系统对源码包安装服务的过程需要的依赖关系也可能不一样,不只是名称不一样这么简单。(对依赖关系的解决也是不熟悉服务安装过程的重要问题,这点我也是深有体会。故,不多解释)但LNMP在目前的搭建过程中,不论是Ubuntu 还是 Debian ,还是 RED HAT ,还是CentOS,甚至是对应系统近年内的几个系统版本,这些源码包和依赖关系都使用。(小众的系统除外,具体参考服务对应的相关官方文档)编译安装可以根据自己的需求来自定义安装路径、监听端口、服务配置等,使用非root用户权限安装可以避免权限的错误使用,这就是使用普通用户编译安装服务的好处和。
############################### 废话说完 ###############################
过程:
对于部分依赖包的安装,还需更改软件源才能获得,这也是一般安装完系统之后需要做的事情
修改软件源 source:
Debian 7 阿里云源:
cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/debian wheezy main contrib non-free
deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free
deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
deb http://http.debian.net/debian wheezy-backports main
EOF
Ubuntu 14 网易源:
#cat > /etc/apt/sources.list << EOF
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
EOF
更新软件源:
#apt-get update
安装部分依赖:
aptitude install -y libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev \
libpng12-0 libpng12-dev libxml2-dev ldap-utils sudo \
lrzsz ntpdate libncurses5 libncurses5-dev bison make cmake g++ autoconf \
vim libtool libmemcached-dev curl libfreetype6-dev libmcrypt-dev libbz2-dev \
libevent-dev libmysqld-dev subversion unzip openssl libcurl4-openssl-dev \
libxslt1-dev gearman-job-server libgearman-dev php-pear php5-dev libgd2-xpm \
libgd2-xpm-dev libperl-dev imagemagick libmagick++-dev \
libmagickcore-dev libncurses5-dev libxml2-dev rsync libjpeg62 libjpeg62-dev
##注:如果没有aptitude工具,请先进行安装,因为它对依赖关系的处理比较优秀。对于其中的警告提醒情忽略,只是告诉用户依赖之间的冲突,保留哪个,安装哪个而已,不影响体验。具体截图我也不再张贴啦~
######################↓↓↓ 修改于 2017年1月12日 ↓↓↓######################
鉴于有同事在使用aptitude安装以来包的时候发生过安装过程中因为某种原因导致aptitude工具的依赖库文件被破坏,所以我们特地对此博客做出修改,推荐使用 apt-get 安装依赖工具。现在,我在此更改一下,使用 apt-get 安装本文章 LNMP 环境所需的对应依赖工具,给大家作为参考。
apt-get install -y sudo vim build-essential libxml2-dev autoconf libssl-dev \
libcurl4-openssl-dev libbz2-dev libjpeg62-dev libpng12-dev libmcrypt-dev \
libmemcached-dev libgearman-dev cmake libncurses5-dev
sudo 和 vim 是不必要的,就是我习惯而已,大家可以忽略。在此,特地赠予大家一些额外的姿势:
sudo 安装完毕后,我们需要进行一些设置。是的,大家很可能都已经知道,但我作为测试机,喜欢直接使用无密钥的获得 root 权限。
vim /etc/sudoers
方案一:复制 root ALL=(ALL:ALL) ALL ,黏贴在下一行,然后更改 root 为你的普通用户账号,比如 stt ^_^
这样就能够让普通用户临时获取 root 权限了,并且在5分钟内不需要密钥访问。
方案二:就像我的截图上面显示的例子,输入 stt ALL=(ALL) NOPASSWD:ALL
这样就能够让普通用户永久无需密钥获取 root 权限了。
vim ?拜托,这个好好学吧,Linux 入门必备工具。我喜欢他,是因为它可以设置高亮而,看着舒服而已。
######################↑↑↑ 修改于 2017年1月12日 ↑↑↑######################
高潮:
编译安装 pcre :(Nginx 以来工具)
卸载旧版本的pcre:(如果有旧版本的 pcre )
sudo apt-get purge libpcre3 libpcre3-dev -y
编译安装 指定版本的 pcre:
./configure --enable-utf8 --enable-jit
make
sudo make install
检测版本:
$pcre-config --version
8.39
$apt-get install -y libpcre3-dev
安装Nginx:
流程:
配置 - 编译 - 安装
解压源码包:
tar zxf nginx-1.11.2.tar.gz
配置:(配置的参数是根据业务需求来增加的,不可胡乱添加,否则影响服务性能,这点切记)
./configure --prefix=/home/stt/server/nginx \
--conf-path=/home/stt/server/nginx/conf/nginx.conf \
--error-log-path=/home/stt/server/nginx/var/log/error.log \
--pid-path=/home/stt/server/nginx/var/run/nginx.pid \
--lock-path=/home/stt/server/nginx/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_dav_module \
--with-http_realip_module
编译参数中文详解可以查看有关博客:http://blog.sina.com.cn/s/blog_68c25adf01014037.html
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/home/stt/server/nginx"
nginx binary file: "/home/stt/server/nginx/sbin/nginx"
nginx modules path: "/home/stt/server/nginx/modules"
nginx configuration prefix: "/home/stt/server/nginx/conf"
nginx configuration file: "/home/stt/server/nginx/conf/nginx.conf"
nginx pid file: "/home/stt/server/nginx/var/run/nginx.pid"
nginx error log file: "/home/stt/server/nginx/var/log/error.log"
nginx http access log file: "/home/stt/server/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
(编译)make
sed -e "s|%%PREFIX%%|/home/stt/server/nginx|" \
-e "s|%%PID_PATH%%|/home/stt/server/nginx/var/run/nginx.pid|" \
-e "s|%%CONF_PATH%%|/home/stt/server/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/home/stt/server/nginx/var/log/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/tmp/nginx-1.11.2'
(安装)make install
make -f objs/Makefile install
make[1]: Entering directory `/tmp/nginx-1.11.2'
test -d '/home/stt/server/nginx' || mkdir -p '/home/stt/server/nginx'
test -d '/home/stt/server/nginx/sbin' \
|| mkdir -p '/home/stt/server/nginx/sbin'
test ! -f '/home/stt/server/nginx/sbin/nginx' \
|| mv '/home/stt/server/nginx/sbin/nginx' \
'/home/stt/server/nginx/sbin/nginx.old'
cp objs/nginx '/home/stt/server/nginx/sbin/nginx'
test -d '/home/stt/server/nginx/conf' \
|| mkdir -p '/home/stt/server/nginx/conf'
cp conf/koi-win '/home/stt/server/nginx/conf'
cp conf/koi-utf '/home/stt/server/nginx/conf'
cp conf/win-utf '/home/stt/server/nginx/conf'
test -f '/home/stt/server/nginx/conf/mime.types' \
|| cp conf/mime.types '/home/stt/server/nginx/conf'
cp conf/mime.types '/home/stt/server/nginx/conf/mime.types.default'
test -f '/home/stt/server/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/home/stt/server/nginx/conf'
cp conf/fastcgi_params \
'/home/stt/server/nginx/conf/fastcgi_params.default'
test -f '/home/stt/server/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/home/stt/server/nginx/conf'
cp conf/fastcgi.conf '/home/stt/server/nginx/conf/fastcgi.conf.default'
test -f '/home/stt/server/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/home/stt/server/nginx/conf'
cp conf/uwsgi_params \
'/home/stt/server/nginx/conf/uwsgi_params.default'
test -f '/home/stt/server/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/home/stt/server/nginx/conf'
cp conf/scgi_params \
'/home/stt/server/nginx/conf/scgi_params.default'
test -f '/home/stt/server/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/home/stt/server/nginx/conf/nginx.conf'
cp conf/nginx.conf '/home/stt/server/nginx/conf/nginx.conf.default'
test -d '/home/stt/server/nginx/var/run' \
|| mkdir -p '/home/stt/server/nginx/var/run'
test -d '/home/stt/server/nginx/logs' \
|| mkdir -p '/home/stt/server/nginx/logs'
test -d '/home/stt/server/nginx/html' \
|| cp -R html '/home/stt/server/nginx'
test -d '/home/stt/server/nginx/var/log' \
|| mkdir -p '/home/stt/server/nginx/var/log'
make[1]: Leaving directory `/tmp/nginx-1.11.2'
安装完成后,配置目录下会有以下配置文件,过滤掉xx.default配置:
~/server/nginx/conf$ tree | egrep -v default
.
├── fastcgi.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── nginx.conf
├── scgi_params
├── uwsgi_params
└── win-utf
0 directories, 15 files
nginx.conf是主配置文件,默认的配置去掉注释之后的内容如下图所示:
~/server/nginx/conf$ grep -vE "#|^$" nginx.conf
worker_processes 1; #表示工作进程数量,一般设置为cpu的核数
events {
worker_connections 1024; #表示每个工作进程的最大连接数
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server { #块定义了虚拟主机
listen 80; #监听端口
server_name localhost; #监听域名
location / { #localtion ()是用来为匹配的 URI 进行配置,URI 即语法中的“/uri/”
root html; #指定对应uri的资源查找路径,这里html为相对路径,完整路径为/home/stt/server/nginx/html
index index.html index.htm;#指定首页index文件的名称,可以配置多个,以空格分开。如有多个,按配置顺序查找
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
赋予nginx执行文件的root特殊权限:(Nginx要求必须是root用户的权限方能启动,要不切换超级管理员来启动,要不给予该启动工具特殊权限)
sudo chown root ./sbin/nginx
sudo chmod u+s ./sbin/nginx
测试配置文件并启动服务:
./sbin/nginx -t (检测配置文件是否存在语法上和配置上的错误,这一步也很重要,建议不要忽略)
./sbin/nginx (启动服务,也可以加上参数 -c 指定配置文件)
报错一:
$ /home/yx/server/nginx/sbin/nginx -c /home/yx/server/nginx/conf/nginx.conf -t
/home/yx/server/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方案:
$ sudo apt-get install -y libpcre3-dev
安装PHP:
流程:
配置 - 编译 - 安装
解压源码包:
tar zxf php-5.4.22.tar.gz
安装依赖:(没错,这是PHP在这几个版本中要求的依赖关系,否则在配置的过程中就会报错)
freetype安装:
unzip freetype-2.4.11.zip
cd freetype-2.4.11/
./configure && make
sudo make install
注意:
rmdir: 删除 "/usr/local/include/freetype2/freetype/internal" 失败: 没有那个文件或目录
make: [install] 错误 1 (忽略)
配置:
./configure --prefix=/home/stt/server/php \
--enable-cli \
--with-libxml-dir=/usr \
--with-kerberos=/usr \
--enable-bcmath \
--enable-calendar \
--enable-fpm \
--with-mcrypt \
--enable-soap \
--enable-exif \
--enable-mbstring \
--enable-pdo \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock \
--with-curl=/usr \
--enable-ftp \
--enable-mbstring \
--with-png-dir \
--with-gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr/ \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib=/usr \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-gd \
--with-jpeg-dir \
--with-openssl
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
(编译)make
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
pharcommand.inc
clicommand.inc
directorygraphiterator.inc
invertedregexiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.
make test(可忽略跳过)
=====================================================================
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #52202 (CURLOPT_PRIVATE gets clobbered) [ext/curl/tests/bug52202.phpt]
Bug #61948 (CURLOPT_COOKIEFILE '' raises open_basedir restriction) [ext/curl/tests/bug61948.phpt]
DOMDocument::validate() should validate an external DTD declaration [ext/dom/tests/DOMDocument_validate_external_dtd.phpt]
Bug #43073 (TrueType bounding box is wrong for angle<>0) freetype < 2.4.10 [ext/gd/tests/bug43073.phpt]
Bug #48801 (Problem with imagettfbbox) freetype < 2.4.10 [ext/gd/tests/bug48801.phpt]
=====================================================================
You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it. You can then email it to [email protected] later.
Do you want to send this report now? [Yns]: (选择默认——回车确认)
(安装)make install
PHP扩展安装,这也是根据业务的需要进行具体的安装的,请酌情:
扩展yaf安装:
unzip yaf.zip
cd php-yaf-master/
/home/stt/server/php/bin/phpize
./configure --with-php-config=/home/stt/server/php/bin/php-config
make
make test(忽略)
make install
Installing shared extensions: /home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/
扩展memcached安装:
/home/stt/server/php/bin/pear install /home/stt/src/memcached-2.1.0.tgz
407465 336 -rwxr-xr-x 1 stt stt 343526 7月 26 06:05 /tmp/pear/temp/pear-build-yx5xO9dU/install-memcached-2.1.0/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/memcached.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/memcached.so'
install ok: channel://pecl.php.net/memcached-2.1.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcached.so" to php.ini
扩展redis安装:
/home/stt/server/php/bin/pear install /home/stt/src/redis-php-2.2.4.tgz
407470 1084 -rwxr-xr-x 1 stt stt 1106009 7月 26 06:14 /tmp/pear/temp/pear-build-yxs0UoUr/install-redis-2.2.4/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/redis.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/redis.so'
install ok: channel://pecl.php.net/redis-2.2.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
扩展zendopcache安装:
/home/stt/server/php/bin/pear install /home/stt/src/zendopcache-7.0.2.tgz
407730 580 -rwxr-xr-x 1 stt stt 590997 7月 26 06:15 /tmp/pear/temp/pear-build-yxret9Lo/install-zendopcache-7.0.2/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/opcache.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/opcache.so'
install ok: channel://pecl.php.net/zendopcache-7.0.2
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=opcache.so" to php.ini
扩展memcache安装:
/home/stt/server/php/bin/pear install /home/stt/src/memcache-2.2.7.tgz
407476 292 -rwxr-xr-x 1 stt stt 297064 7月 26 06:19 /tmp/pear/temp/pear-build-yxxZWz9y/install-memcache-2.2.7/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so'
install ok: channel://pecl.php.net/memcache-2.2.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcache.so" to php.ini
扩展gearman安装:
/home/stt/server/php/bin/pear install /home/stt/src/gearman-1.1.0.tgz
407489 352 -rwxr-xr-x 1 stt stt 357091 7月 26 06:20 /tmp/pear/temp/pear-build-yx9D52DK/install-gearman-1.1.0/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/gearman.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/gearman.so'
install ok: channel://pecl.php.net/gearman-1.1.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=gearman.so" to php.ini
扩展yar安装:
/home/stt/server/php/bin/pear install /home/stt/src/yar-1.2.5.tgz
407816 424 -rwxr-xr-x 1 stt stt 430946 7月 26 06:21 /tmp/pear/temp/pear-build-yxhnasCy/install-yar-1.2.5/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/yar.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/yar.so'
install ok: channel://pecl.php.net/yar-1.2.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=yar.so" to php.ini
扩展msgpack安装:(不必要安装,像我们的业务就会与其存在冲突)
/home/stt/server/php/bin/pear install /home/stt/src/msgpack-0.5.7.tgz
408454 480 -rwxr-xr-x 1 stt stt 488072 7月 27 22:27 /tmp/pear/temp/pear-build-yxlK9LJm/install-msgpack-0.5.7/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so
Build process completed successfully
Installing '/home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/msgpack.so'
Installing '/home/stt/server/php/include/php/ext/msgpack/php_msgpack.h'
install ok: channel://pecl.php.net/msgpack-0.5.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=msgpack.so" to php.ini
扩展openssl安装:(默认已经安装,如果没有则可以不用重新编译PHP服务照着中途安装)
cd /tmp/php-5.4.22/ext/openssl
cp config0.m4 config.m4
/home/stt/server/php/bin/phpize
./configure --with-openssl --with-php-config=/home/stt/server/php/bin/php-config
make
make install
Installing shared extensions: /home/stt/server/php/lib/php/extensions/no-debug-non-zts-20100525/
测试配置文件并启动服务(根据业务需求修改配置文件,并且上面的提示把扩张写入php.ini文件中去):
测试:
/home/stt/server/php/sbin/php-fpm -c /home/stt/server/php/lib/php.ini -y /home/stt/server/php/etc/php-fpm.conf -t (应该很熟悉了,这就类似Nginx的验证配置文件过程)
启动:(PHP也照样要求使用root权限来启动,可以选择赋予特殊权限,也可以选择忽略警告信息,它不像Nginx没有root权限会启动不成功)
/home/stt/server/php/sbin/php-fpm -c /home/stt/server/php/lib/php.ini -y /home/stt/server/php/etc/php-fpm.conf
重启:
kill -USR2 `cat /home/stt/server/php/var/run/php-fpm.conf`
安装过程可能存在的报错:
报错一:
configure: error: Cannot find OpenSSL's libraries
解决方案:
sudo apt-get install -y libcurl4-openssl-dev
报错二:
configure: error: Please reinstall the BZip2 distribution
解决方案:
sudo apt-get install -y libbz2-dev
报错三:
configure: error: jpeglib.h
解决方案:
sudo apt-get install -y libjpeg62-dev
报错四:
configure: error: png.h not found.
解决方案:
sudo apt-get install -y libpng12-dev
报错五:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方案:
sudo apt-get install -y libmcrypt-dev
报错六:
checking for libmemcached location... configure: error: memcached support requires libmemcached 1.0.x. Use --with-libmemcached-dir=
ERROR: `/tmp/pear/temp/memcached/configure' failed
解决方案:
sudo apt-get install -y libmemcached-dev
报错七:
not found
configure: error: Please install libgearman
ERROR: `/tmp/pear/temp/gearman/configure' failed
解决方案:
sudo apt-get install -y libgearman-dev
报错八:
checking libxml2 install dir... /usr
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
解决方案:
sudo apt-get install -y libxml2-dev
报错九:(启动报错:)
[17-Aug-2016 15:45:58] NOTICE: fpm is running, pid 10788
[17-Aug-2016 15:45:58] ERROR: failed to prepare the stderr pipe: Too many open files (24)
[17-Aug-2016 15:45:58] ERROR: unable to read what child say: Bad file descriptor (9)
[17-Aug-2016 15:45:58] ERROR: unable to read what child say: Bad file descriptor (9)
[17-Aug-2016 15:45:58] ERROR: unable to read what child say: Bad file descriptor (9)
[17-Aug-2016 15:45:58] ERROR: unable to read what child say: Bad file descriptor (9)
[17-Aug-2016 15:45:58] ERROR: unable to read what child say: Bad file descriptor (9)
解决方案:
减少进程数: pm.max_children = 200 rlimit_files = 1024 (这是我的配置数值,请勿照抄,具体得看系统支持多少进程数,那是后话,日后会在我的博客上找机会说)
PHP 注意问题(php.ini文件的配置):
engine = On
error_reporting = E_ALL //报告所有错误信息
display_errors = Off
display_startup_errors = Off
log_errors = On //错误信息日志记录动作开启
error_log =/home/stt/server/php/log/php-error.log //错误信息日志保存路径
session.save_handler = memcache
session.save_path = 'tcp://127.0.0.1:12306' //memcache session文件初始化保存路径
安装MySQL:
创建服务安装目录:
sudo mkdir -p {/home/stt/server/mysql/data,/home/stt/server/mysql/etc,/home/stt/server/mysql/var/logs/binlog,/home/stt/server/mysql/var/logs/relay,/home/stt/server/mysql/var/tmp}
流程:
配置 - 编译 - 安装
解压源码包:
tar -zxf mysql-boost-5.7.12.tar.gz
cd mysql-5.7.12/
如果没有-DMYSQL_UNIX_ADDR该参数进行sock文件的指定路径,请根据下面方式创建服务默认目录:
sudo mkdir /var/run/mysqld
sudo chown stt:stt /var/run/mysqld/
添加开机自启动:
sudo vim /etc/profile
mkdir /var/run/mysqld
chown stt:stt /var/run/mysqld/
配置:
cmake -DCMAKE_INSTALL_PREFIX=/home/stt/server/mysql \
-DMYSQL_DATADIR=/home/stt/server/mysql/data \
-DSYSCONFDIR=/home/stt/server/mysql/etc \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/tmp/boost_1_59_0 \ //因为为了避免网络的瓶颈,所以我单独下载,否则请使用boost里面的路径/tmp/mysql-5.7.12/boost/boost_1_59_0,具体看你把mysql源码包解压在哪
-DMYSQL_USER=stt \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/home/stt/server/mysql/var/mysqld.sock \
-DMYSQL_TCP_PORT=33006 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
CMake Warning:
Manually-specified variables were not used by the project:
MYSQL_USER
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /tmp/mysql-5.7.12
(编译安装)make && make install (编译的时间长短与机器和系统的软硬件性能有关)
添加全局执行脚本,赋予执行权限并修改脚本(为什么要修改权限在此不多说):
sudo cp /home/stt/server/mysql/support-files/mysql.server /etc/init.d/mysqld
sudo chmod +x /etc/init.d/mysqld
修改启动脚本文件:
sudo vim /etc/init.d/mysqld
添加:
basedir=/home/stt/server/mysql
datadir=/home/stt/server/mysql/data
删除服务自动生成的配置文件:(切记,如果存在此文件,则必须要删除此文件,否则服务会加载这里默认的my.cnf配置文件)
sudo rm /etc/mysql/my.cnf
编辑MySQL配置文件:
vim /home/stt/server/mysql/etc/my.cnf //(根据自己的业务具体需求进行修改)
初始化MySQL服务:
/home/stt/server/mysql/bin/mysqld --initialize-insecure --user=stt --basedir=/home/stt/server/mysql --datadir=/home/stt/server/mysql/data
初始化服务报错:(包括警告)
2016-07-26T10:45:20.250774Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 50000) 修改配置文件的max_open_files或系统的/etc/security/limit.conf
2016-07-26T10:45:20.251110Z 0 [Warning] Changed limits: max_connections: 214 (requested 10000) 修改配置文件的max_connections或系统的/etc/security/limit.conf
2016-07-26T10:45:20.251119Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 10000) 修改配置文件的table_open_cache
2016-07-26T10:45:20.274193Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-07-26T10:45:20.274233Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set. 在[mysqld]节点下加入参数再重启:explicit_defaults_for_timestamp=true
2016-07-26T10:45:20.468197Z 0 [ERROR] Aborting
2016-07-26T10:53:28.020753Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2016-07-26T10:53:29.063276Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool //修改innodb_buffer_pool_size的值,因为对本地机器而言,目前的值太大了,无法正常分配
2016-07-26T10:53:29.072109Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2016-07-26T10:53:29.109333Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2016-07-26T10:53:29.122313Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-07-26T10:53:29.143122Z 0 [ERROR] Failed to initialize plugins.
2016-07-26T10:53:29.143208Z 0 [ERROR] Aborting
启动服务:
/etc/init.d/mysqld start
修改超级管理员root密码(很重要,一定要更改密码。这是5.7的特性,如果不是使用空密码初始化数据库就会在登录后强制用户更改密码方能继续下一步的操作):
>update mysql.user set authentication_string=password('PASSWORD') where user='root';
或者 >set password='PASSWORD';
>flush privileges;
报错:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:479 (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
解决方案:
sudo apt-get install -y libncurses5-dev && rm ./CMakeCache.txt