码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp

时间:2017-07-23 22:54:26      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:lnmp

lnmp


####mysql###

 

注意:源码编译完mysql后,就不要再安装mariadb-server,不然源码的脚本会被覆盖掉

 

源码安装 mysql

 

使用cmake,make,make install命令,cmake的命令可以显示安装的进度的百分比

 

mysql 官网:www.mysql.com

 

软件包依赖性:

1 yum install -y gcc gcc-c++ make ncurses-devel cmake

 

2 tar  zxf mysql-boost-5.7.17.tar.gz

 

3 cmake-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all

 

 

**********************************************************************************************

#####参数说明##########

 

-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql#安装目录

-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data#数据库存放目录,注意该目录的路径要在安装目录的路径下

-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock#Unix socket 文件路径

-DWITH_MYISAM_STORAGE_ENGINE=1#安装 myisam 存储引擎,要是不想安装,只要将1写成0即可

DWITH_INNOBASE_STORAGE_ENGINE=1#安装 innodb 存储引擎

-DDEFAULT_CHARSET=utf8#使用 utf8 字符

DDEFAULT_COLLATION=utf8_general_ci#校验字符

-DEXTRA_CHARSETS=all#安装所有扩展字符集

*************************************************************************************************

 

4 make  &&   make   install

 

5 groupadd  -g 27 mysql###创建mysql组###

 

6 useradd -u 27 -g 27 -s /sbin/nologin -M -d /usr/local/lnmp/mysql/data mysql###创建mysql用户###

 

7 cp support-files/my-default.cnf /etc/my.cnf###在/etc/my.cnf文件下有datadir和socket的路径,与源码编译时的路径不符,所以要将/etc/my.cnf文件用源码编译产生的配置文件覆盖。####

 

8 vim ~/.bash_profile###将mysql的脚本文件路径写在该目录下,则执行脚本时更方便###

 

内容:PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

 

9 source ~/.bash_profile

 

10 cd /usr/local/lnmp/mysql/support-files/

 

11 cp mysql.server /etc/init.d/mysqld###在企业六的版本里,服务的启动和停止脚本文件一般都是放在/etc/init.d/目录下,所以将mysql服务的脚本文件放在该目录下,通过/etc/init.d/mysqld   startr就可以启动mysql服务###

 

12 chown root.root .  -R(当前路径:/usr/local/lnmp/mysql)

 

13 chown mysql  data -R###将data的目录及目录下的文件的用户身份改成mysql###

 

14 mysqld --initialize --user=mysql###以mysql用户的身份进行mysql的初始化###

 

15 /etc/init.d/mysqld start

 

16 mysql -p

 

【过程:

[root@server1 mysql]# mysql -p

Enter password: ###使用初始化产生的临时密码###

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.17

 

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

mysql> show databases;###使用临时密码,没有权限查看mysql的内容,要进行初始化###

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql>

 


17 mysql_secure_installation###由于在源码编译时,有编译字符校验模块,所以当修该密码时,会询问是否要使用字符校验的功能###

 

【过程:

[root@server1 mysql]# mysql_secure_installation

 

Securing the MySQL server deployment.

 

Enter password for user root:

 

The existing password for the user account root has expired. Please set a new password.

 

New password:

 

Re-enter new password:

 

VALIDATE PASSWORD PLUGIN can be used to test passwords###询问是否要使用字符校验的功能###

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

 

Press y|Y for Yes, any other key for No: y

 

There are three levels of password validation policy:

 

LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

 

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1###选择字符校验的级别###

Using existing password for root.

 

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : y###不能直接回车,不然会跳过该问题###

 

New password:

 

Re-enter new password:

(....省略)

 

 

 

编译的具体过程如下:

 

[root@server1 ~]# tar zxf  mysql-boost-5.7.17.tar.gz

[root@server1 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm

[root@server1 ~]# cd mysql-5.7.17/

[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=al

 

(过程省略,主要看Error)

*****************************************************************************

CMake Error at cmake/boostNaNake:81 (MESSAGE):

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

 

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

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

 

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

 

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

 

Call Stack (most recent call first):

  cmake/boostNaNake:238 (COULD_NOT_FIND_BOOST)

  CMakeLists.txt:455 (INCLUDE)

 

 

-- Configuring incomplete, errors occurred!

 

*******************************************************************************

由此可以看出缺少-DWITH_BOOST=<directory>

 

[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=al -DWITH_BOOST=boost/boost_1_59_0/ ###指定-DWITH_BOOST=boost/boost_1_59_0/###

 

(过程省略,看Error)

*********************************************************************************

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

CMake Error: Internal CMake error, TryCompile configure of cmake failed

 

.....)

 

      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/readlineNaNake:107 (FIND_CURSES)

  cmake/readlineNaNake:197 (MYSQL_USE_BUNDLED_EDITLINE)

  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)

*********************************************************************************

CMAKE_CXX_COMPILER not set可以看出缺少c++编译器,还有要安装ncurses-devel

 

 

[root@server1 mysql-5.7.17]# yum install -y ncurses-devel gcc-c++

[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=al -DWITH_BOOST=boost/boost_1_59_0/

 

 

(省略过程...看Error)

*****************************************************************************

      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/readlineNaNake:107 (FIND_CURSES)

  cmake/readlineNaNake:197 (MYSQL_USE_BUNDLED_EDITLINE)

  CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)

*****************************************************************************

由于ncurses-devel已经装过,(可用rpm   -q   ncurses-devel查看),因此是CMakeCache.txt文件的影响,cmake在编译的过程中,会产生缓存文件,当继续编译时,就会从刚才停下的地方继续编译,而刚才停下的地方就是出错的地方,因此要将该缓存文件删除

 

[root@server1 mysql-5.7.17]# rm -f CMakeCache.txt

[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=al -DWITH_BOOST=boost/boost_1_59_0/

 

###没有报错,编译成功####

 

[root@server1 mysql-5.7.17]# make && make install

 

 

 

测试:

登入mysql

 

[root@server1 data]# mysql -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.7.17 Source distribution

 

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> exit

Bye

 

 

 

 

####php####

 

一源码编译php

 

php下载软件网址:php.net

 

tar  jxf  php-5.6.20.tar.bz2

 

cd php-5.6.20

 

1 编译:./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext -enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash

 

**********************************************************************************

####参数说明######

--prefix=/usr/local/lnmp/php###指定安装目录###

 

--with-config-file-path=/usr/local/lnmp/php/etc###指定php主配置文件的位置###

--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd###php如果要使用到mysql,可以通过调用外部的mysql模块,也可以使用php原身带有的数据库驱动mysqlnd,但是调用外部模块,内存需求量更大,性能也不高,而调用原身具有的mysqlnd模块,性能可以提高40%,因此建议使用原身的mysqlnd模块####

 

--with-openssl###加密###

 

--with-snmp###监控###

 

--with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp###支持图片###

 

--with-zlib###网页压缩###

 

--with-gettext###支持文本###

 

--enable-soap###支持动态模块的加载,编译完后如果有想要再添加什么功能的模块,再添加,就不用重新编译####

 

 

--enable-fpm###支持fastcgi,fastcgi与cgi的区别在于fastcgi有后台进程,而cgi没有后台进程###

 

 

--with-mcrypt --with-mhash###网页加密###

****************************************************************************************

 

2 软件依赖性:取决于你编译时安装的模块的依赖性,此时的依赖软件有libmcrypt-2.5.8-9.el6.x86_64.rpm,libjpeg-turbo-devel-1.2.1-1.el6.x86_64,

net-snmp-devel,re2c-0.13.5-1.el6.x86_64.rpm,libxml2-devel ,curl-devel, jpeglib-devel,libpng-devel,freetype-devel,gmp-devel

 

3 make&&makeinstall

 

 

nginx和php联系在一起

 

1 cd php-5.6.20

 

2 cp php.ini-production /usr/local/lnmp/php/etc/php.ini###将配置文件移到/usr/local/lnmp/php/etc/下,并且一定以要命名为php.ini

 

 

3 cp    sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 

4 chmod   +x/etc/init.d/php-fpm

 

5 vim /usr/local/lnmp/php/etc/php.ini

 

内容:

 

date.timezone=Asia/Shanghai

 

 

6 cp  /usr/local/lnmp/php/etc/php-fpm.conf.default  /usr/local/lnmp/php/etc/php-fgm.conf

 

7 vim  php-fpm.conf

 

内容:

pid = run/php-fgm.pid

 

8 /etc/init.d/php-fpm   reload###使用的fastcgi,有后台进程,有自己的端口(:9000),因此可以直接reload###

 

9 vim  ~/.bash_profile

 

内容:

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin

 

10 source  ~/.bash_profile

 


 

11 netstat-antlp    | grep  :9000

 

12 vim  /usr/local/lnmp/nginx/conf/nginx.conf

 

内容:

   location / {

            root   html;

            index  index.php index.html index.htm;

        }

 

 

 

 

 location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            include        fastcgi.conf;

 

13 vim   /usr/local/lnmp/nginx/html/index.php

 

内容:

 

<?php

phpinfo()

?>

 

 

测试:

 

访问172.25.78.1可以看到php的信息页

 

 

 

nginx+php+mysql

 

 

client  -- >  nginx将所有的php的处理转发 --- >  php-fpm(端口号为9000) --- > php-mysqlnd --- > mysql:3306  --- > nginx  --- > client

 

部署论坛

 

1 网上下载一个论坛的压缩包并解压

unzip Discuz_X3.2_SC_UTF8.zip

 

2 less  readme/readme.txt###查看论坛部署的方法###

 

3 mv upload/ /usr/local/lnmp/nginx/html/bbs###readme.txt中写的要上传upload到服务器###

 

 

4 cd /usr/local/lnmp/nginx/html/bbs/

 

5 chmod 777 config/ uc_client/ data/ uc_server/ -R###安装过程要将目录权限开启###

 

 

安装过程会碰到该问题:

数据库连接错误:php不能连接到数据库

 

解决:

php的配置文件里指定数据库socket的位置

 

vim  /usr/local/lnmp/php/php.ini

 

内容:

**************************************************************

mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock

pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock

mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock

 

**************************************************************

 

 /etc/init.d/php-fpm  reload

 

 

还会碰到由于权限而无法连接数据库:

 

Permission denied

 

解决:

chmod 755 /usr/local/lnmp/mysql/data/

 

 

 

 

 

###php功能模块的扩展###

 

 

client  -- >  nginx将所有的php的处理转发 --- >  php-fpm(端口号为9000) --- > php-mysqlnd --- > mysql:3306  --- > nginx  --- > client

 

 

 

memcache

 

它是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的 Hash 表,能够用来存储各种格式的数据。可以类比于 MySQL 这样的服务,而 PHP 扩展的 Memcache 实际上是连接Memcache 的方式,一般的使用目的是,通过缓存数据库查询结果,减少数据库访问次数,以提高动态web应用的速度,提高可扩展性。

 

可通过php   -m  |  grep   memcached   查看是否有memcached模块,php   -m显示所有的php编译的模块,如果没有就要通过phpize添加该功能模块。

phpize官方说明:是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块。

 

******************************************************************************************

使用phpize扩展memcached模块的步骤:

 

1 下载网址 http://memcached.googlecode.com/

 

tar zxf memcache-2.2.5.tgz

 

2  cd memcache-2.2.5

 

3 phpize(我已经将路径加入到~/.bash_profile文件下,如果没有加入的要用绝对路径)

 

 

****************************************

可能出现的问题:

Cannot find config.m4.

解决:

是因为你没有cd到memcache-2.2.5目录下

***************************************

 

4 ./configure

 

5 make  &&  make insall

 

6 vim   /usr/local/lnmp/php/etc/php.ini

 

内容:(配置文件里有说明添加扩展模块怎么写,模仿着写)

 

extension=memcache.so

 

7 /etc/init.d/php-fpm reload

 

 

*******************************************************************************************

可能出现reload服务后仍然没有memcache的情况,这时要检查你使用的是系统带有的rpm包,还是源码编译的包,如果是系统的rpm包则要先把系统的包删除,然后就可以了

[root@server1 etc]# which php

/usr/bin/php

[root@server1 etc]# rpm -qa|grep php

php-cli-5.3.3-26.el6.x86_64

php-common-5.3.3-26.el6.x86_64

php-5.3.3-26.el6.x86_64

[root@server1 etc]# rpm -e `rpm -qa|grep php`

[root@server1 etc]# source  ~/.bash_profile

[root@server1 etc]# which php

/usr/local/lnmp/php/bin/php

[root@server1 etc]# php -m |grep mem

memcache

******************************************************************************************

 

 

###往mecache里存信息###

[root@server1 ~]# telnet localhost 11211

Trying ::1...

Connected to localhost.

Escape character is ‘^]‘.

set name 0 0 6###第二个0指不过期,如果是10,则指10后过期,6指的是存的字符数为6####

westos

STORED

get name

VALUE name 0 6

westos

END

delete name

DELETED

get name

END

 

 

 

###openresty###

 

nginx本身具有高并发的特点,如果将缓存放在php后面,则客户请求发给nginx,nginx给php-fpm处理,然后缓存到memcache上,则nginx就要等待php-fpm的处理结束,那么就会影响到ngnix本身的效率,但是,如果把memcache放在nginx之后,客户请求过来,如果缓存里有,就可以直接从memcache中取来发给客户端,而不用再等php-fpm,因此就不会影响到nginx的效率,将缓存放在nginx之后需要memc和srcache模块,此实验直接安装openresty做更方便。

 

openresty是一个全功能的web服务器。他打包了标准的nginx核心,很多的常用的第三方模块,以及他们大多数的依赖项。(来自官网)

 

vim /usr/local/openresty/nginx/conf/nginx.conf

 

内容:

  upstream memcache {

                server  127.0.0.1:11211;

                keepalive 512;

        }

 

        location /memc {

                internal;

                 memc_connect_timeout 100ms;

                memc_send_timeout 100ms;

                memc_read_timeout 100ms;

                 set $memc_key $query_string;

                set $memc_exptime 300;

                memc_pass memcache;

 

        }

 

  location ~ \.php$ {

             set $key $uri$args;

             srcache_fetch GET /memc $key;

             srcache_store PUT /memc $key;

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

           # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            include        fastcgi.conf;

        }

 

 

 

 

 

 

 

具体过程如下:

[root@server1 ~]# tar zxf openresty-1.11.2.3.tar.gz

[root@server1 ~]# cd openresty-1.11.2.3

[root@server1 openresty-1.11.2.3]# ls

bundle     COPYRIGHT  README.markdown   util

configure  patches    README-win32.txt

[root@server1 openresty-1.11.2.3]# ./configure

 

[root@server1 openresty-1.11.2.3]# gmake && gmake install

 

[root@server1 openresty-1.11.2.3]# ls

build   configure  Makefile  README.markdown   util

bundle  COPYRIGHT  patches   README-win32.txt

[root@server1 openresty-1.11.2.3]# cd /usr/local/openresty/

[root@server1 openresty]# ls

bin  luajit  lualib  nginx  pod  resty.index  site

[root@server1 openresty]# nginx -s stop

[root@server1 openresty]# cd nginx/

[root@server1 nginx]# ls

conf  html  logs  sbin

[root@server1 nginx]# cd conf/

[root@server1 conf]# ls

fastcgi.conf            koi-win             scgi_params

fastcgi.conf.default    mime.types          scgi_params.default

fastcgi_params          mime.types.default  uwsgi_params

fastcgi_params.default  nginx.conf          uwsgi_params.default

koi-utf                 nginx.conf.default  win-utf

[root@server1 conf]# vim nginx.conf

 

测试:

 ab -c10 -n 50000 http://172.25.78.1/index.php


lnmp

标签:lnmp

原文地址:http://12774272.blog.51cto.com/12764272/1950252

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!