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###不能直接回車,不然會跳過該問題###
(....省略)
編譯的具體過程如下:
[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.
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)
由于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]# make && make install
測試:
登入mysql
[root@server1 data]# mysql -p
Enter password:
Your MySQL connection id is 7
Server version: 5.7.17 Source distribution
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功能子產品的擴充###
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
/usr/local/lnmp/php/bin/php
[root@server1 etc]# php -m |grep mem
###往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
END
delete name
DELETED
###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;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
具體過程如下:
[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
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
本文轉自blueclo51CTO部落格,原文連結:http://blog.51cto.com/12774272/1950252 ,如需轉載請自行聯系原作者