lamp
資源類型:
靜態資源:原始形式與響應給客戶端的結果一致;
動態資源:原始形式通常為程序文件(為某種編程語言開發),需要運行后將生成的結果展示給客戶端;如果請求的資源不存在那么結果就會重定向至指定的文件中
客戶端技術:javascript 服務端技術:php, jsp, ...
CGI:Common Gateway Interface
CGI是一種協議,定義了客戶端(web服務器程序)與服務端(特定的應用程序服務進程)進行數據交換的一種規范; 程序:指令+數據 指令:代碼 數據:存儲 文件系統:單機文件,分布式文件系統; DBMS: SQL:Oracle, SQL Server, DB2, MySQL, PostgreSQL(PGSQL), MariaDB, Percona-Server, ... NoSQL: KV:redis, ... Document:MongoDB, ... Column:HBase, ... Graph:
開源領域:
httpd+php/perl/python+mysql/mongodb: amp httpd+tomcat+mysql/mongodb: amt jsp:tomcat, jetty, resin, jboss, websphere, weblogic php:編程語言,嵌入式編程語言,高度模塊化(extensions),配置文件(/etc/php.ini, /etc/php.d/*.ini); <html> ... <?php code ?> ... </html> httpd+php: CGI Module prefork:libphp worker, event:libphp-zts FastCGI php以fpm機制獨立地監聽在一個套接字上;工作模式類似于httpd的prefork;
amp:資源請求的過程
靜態資源:Client --> http --> httpd (IO操作) php動態資源:Client --> http --> httpd --> libphp5.so (IO操作) php動態資源:Client --> http --> httpd --> libphp5.so (IO操作, php-mysql)--> mysql --> mysqld
php:嵌入式web應用編程語言
作者:Rasmus Lerdorf, Personal Home Page tool, C語言(CGI,Web Forms), PHP/FI zeev, andi重寫php的解析器, zend engine 1.0, php 4.0; zend engine 2.0 php 5.0(增強的面向對象,PDO) zend engine:編譯 --> opcode, 執行 Scanning(Lexing), Parsing, Compilation, Excution hhvm php加速器: APC,eAccelerator XCache XCache: XCache is a fast, stable PHP opcode and data cacher that has been tested and is now running on production servers under high load.
Xcache這個能使php這種動態請求快3倍最為常用的加速器
安裝php的擴展
yum install php-mbstring (這個表示使php支持中文) php-mcrypt -y
快速部署lamp環境 1:
1、下載
-
CentOS 7:
# yum install mariadb-server httpd php php-mysql # systemctl start httpd.service mariadb.service
-
CentOS 6:
yum install httpd php php-mysql mysql-server
service httpd start
service mysqld start
2、改mysql配置文件
-
vim /etc/my.cnf
-
skip_name_resolve=ON
innodb_file_per_table=ON -
注意6的話為
skip_name_resolve
3、改mysql的root管理密碼及各種配置
mysql_secure_installation (1)給管理員加密碼 (2)刪除匿名用戶 (3)是否禁用管理員遠程登錄(一般禁用) (4)刪除測試文件 (5)重載授權表
收拾好了以后可以用下面的命令進入看看
mysql -u root -p >(這里是密碼)
添加一條記錄試試
GRANT ALL ON wpdb.* TO wpuser@'172.0.0.1' IDENTIFIED BY 'wppass'; 這條記錄表示添加一個數據庫名為 wpdb 用戶名為 wpuser 密碼為 wppass
php應用程序:
開源代表:wordpress, discuzX, phpwind, drupal...
客戶端—(http協議)—http服務器–(fcgi協議)–php動態資源服務器端—(php-mysql)–數據庫服務器 》》》》》 模型
php-fpm:就是說把本來是模塊化裝載的php模塊改成獨立的程序文件
FastCGI Process Manager, an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. 客戶端---(http協議)---服務端----(fcgi協議)---后端服務器 fpgi是一個簡裝版的http協議當用戶動態請求到達時,直接將 url 從前端web服務器轉到fpgi server
安裝方式:
# yum install php-fpm
注意這個和 php模塊不能一塊安裝
-
主程序:/usr/sbin/php-fpm
-
Unit File:/usr/lib/systemd/system/php-fpm.service
-
配置文件:
php的通用公共組件的包為 php-common 包來提供通用的公共組件
配置文件(配置PHP的解釋器的配置):/etc/php.ini, /etc/php.d/*.ini
ini:配置php解釋器工作環境; /etc/php.ini, /etc/php.d/*.ini conf:配置fpm守護進程的工作模式; /etc/php-fpm.conf, /etc/php-fpm.d/*.conf 默認有一個www.conf 里面定義了一個可用的www連接池的配置 ini:風格格式 [section_id] directive = value
注釋符 ’#‘ 、 ‘;’
#表示純屬的是注釋信息 ’;‘號注釋符 后面跟一個空格的行表示可啟用的選項 ’;‘跟兩個空格的行表示多此選項的說明
-
php.ini的核心配置選項參考:
http://php.net/manual/zh/ini.core.php
-
php.ini配置選項列表參考:
http://php.net/manual/zh/ini.list.php
一般需改動 /etc/php.ini 中的時區要不會報錯
一般改為 州/市
date.timezone = Asia/Shanghai
1、反代主機的基本配置:
fpm配置虛擬主機反代配置示例1: <VirtualHost *:80> ServerName www.magedu.com DocumentRoot "/vhosts/www" <Directory "/vhosts/www"> Options None AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1 DirectoryIndex index.php index.html </VirtualHost>
fpm配置虛擬主機反代配置示例2: <VirtualHost *:80> ServerName www.magedu.com DocumentRoot "/vhosts/www" <Directory "/vhosts/www"> Options None AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1 ProxyPassMatch ^/(pm-status|ping)$ fcgi://127.0.0.1:9000/$1 DirectoryIndex index.php index.html </VirtualHost>
2、連接池的配置
[pool-id] //定義的連接池名稱 listen = 127.0.0.1:9000 #(允許本機當客戶端訪問fpm,在同一個主機,如果不一致要寫入 web主機的地址) listen.backlog = -1 (超出請求時隊列的長度 -1表示沒有上線) listen.allowed_clients = 127.0.0.1 (允許那些客戶端主機訪問) user = apache (運行work進程的用戶和組) group = apache pm = dynamic 定義process管理機制:static, dynamic static: 服務啟動時創建出所有子進程; dynamic: 根據用戶請求量的變化來維護子進程數量; pm.max_children = 50 最大子進程數量 pm.start_servers = 5 啟動時啟動多少進程 pm.min_spare_servers = 5 最小空閑子進程 pm.max_spare_servers = 35 最大空閑子進程 pm.max_requests = 500 每一個進程相應多少請求后就殺死重新創建 pm.status_path = /fpm-status 監控的status頁面 ping.path = /ping ping.response = pong 這兩個是為了探測服務是否正常 rlimit_files = 1024 rlimit_core = 0
連接池的status參數
http://WEB_SERVER:PORT/pm-status
pool: www # 連接池名稱 process manager: dynamic # 進程管理器類型 start time: 26/Sep/2016:15:10:26 +0800 # 啟動時間 start since: 7437 # 運行時長 accepted conn: 6 # 連接池已經處理過的總請求數 listen queue: 0 # 隊列的長度 max listen queue: 0 # 請求隊列的最大長度 listen queue len: 128 # 監聽socket等待隊列的最大長度; idle processes: 4 # 空閑的進程數; active processes: 1 # 活躍的進程數量; total processes: 5 # 總進程數; max active processes: 1 # 連接池當中過去最大活躍進程度; max children reached: 0 # 進程數量達到連接池上限的次數; slow requests: 0 # 慢請求的數量;
status 其它格式的輸出:
/pm-status?json /pm-status?xml /pm-status?html /pm-status?full
full格式的輸出:(單個進程的相關信息)
pid: 33095 state: Idle # 當前進程的狀態,idle, running, ... start time: 26/Sep/2016:15:10:26 +0800 # 進程啟動的日期時間 start since: 7968 # 運行時長 requests: 2 # 處理過的請求數量 request duration: 112 # 請求處理過程的時長 request method: GET # 請求方法 request URI: /pm-status?html # 請求的URL content length: 0 # 請求內容的長度,POST方法才有意義 user: - # 用戶 script: - # php腳本; last request cpu: 0.00 # 最近一次請求消耗CPU last request memory: 262144 # 最近一次請求消耗的內存量
注意:
httpd-2.2默認沒有自帶fcgi模塊;php-5.3.3-默認不支持fpm,需要打補丁方可;
CentOS 6.X:要使用fpm 需要安裝額外的模塊 mod_proxy_fcgi
# yum install httpd mod_proxy_fcgi php-fpm php-mysql mysqld-server
Xcache這個能使php這種動態請求快3倍最為常用的加速器
lamp 部署 2
兩種部署方式
centos 7
-
Modules:程序包,httpd,php,php-mysql,mariadb-server
-FastCGI:程序包,httpd,php-fpm,php-mysql,mariadb-server
centos 6
-
Modules:程序包,httpd,php,php-mysql,mysql-server
-FastCGI:需要先打補丁,httpd、mod_proxy_fcgi php-fpm、 php-mysql、 mysqld-server
步驟
保證 iptables selinux 都沒啟用
1、安裝 httpd php-fpm
2、去除注釋 /etc/http/conf/http.conf 中的 ServerName
注釋 DocumentRoot "/var/www/html"
3、在conf.d/新建 虛擬主機
fpm配置虛擬主機反代配置示例1: <VirtualHost *:80> ServerName www.magedu.com DocumentRoot "/vhosts/www" <Directory "/vhosts/www"> Options None AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1 DirectoryIndex index.php index.html </VirtualHost> fpm配置虛擬主機反代配置示例2: <VirtualHost *:80> ServerName www.magedu.com DocumentRoot "/vhosts/www" <Directory "/vhosts/www"> Options None AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/vhosts/www/$1 ProxyPassMatch ^/(pm-status|ping)$ fcgi://127.0.0.1:9000/$1 DirectoryIndex index.php index.html </VirtualHost>
4、創建目錄和文件重啟服務并訪問就行了
編譯安裝amp:
(1) 系統環境:CentOS 6, 7 CentOS 6:apr, apr-util的版本為1.3.9,不適用于httpd-2.4的編譯; CentOS 7:apr, apr-util的版本為1.4+, (2) 開發環境: Development Tools, Server Platform Development (3) 各程序版本 httpd: 2.2, 2.4 php:5.3.x 5.4.x, 5.6.x mysql:5.1, 5.5, 5.6, 5.7, 5.8, 8.0 mariadb:5.x, 10.x (4) httpd+php php的編譯選項: Modules:--with-apxs httpd MPM: prefork: worker, event:專用選項--enable-maintainer-zts ftm:--enable-fpm CentOS 7:httpd-2.4, mariadb, php-5.4 安裝次序:httpd, mariadb, php 安裝MariaDB: 預制的包管理器格式的程序包: rpm包: os vendor:mariadb-devel MariaDB官方 通用二進制格式的程序包: 源碼包編譯:項目構建工具為cmake, 而非流行的make; 通用二進制格式包的安裝配置步驟: # useradd -r mysql # tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local/ # cd /usr/local/ # ln -sv mariadb-VERSION-linux-x86_64 mysql # cd mysql # chown -R root:mysql ./* # mkdir -pv /mydata/data # chown -R mysql.mysql /mydata/data # scripts/mysql_install_db --user=mysql --datadir=/mydata/data --skip_name_resolve # cp support-files/my-large.cnf /etc/my.cnf [mysqld] ....... datadir = /mydata/data skip_name_resolve = ON innodb_file_per_table = ON # cp support-files/mysql.server /etc/rc.d/init.d/mysqld # chkconfig --add mysqld httpd-2.4: ~]# yum install pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel -y # ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr # make -j # # make install # echo 'export PATH=/usr/local/apache2/bin:$PATH' > /etc/profile.d/httpd.sh # . /etc/profile.d/httpd.sh # apachectl start 安裝php5: 安裝: (1) 作為httpd的模塊安裝: # ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/ # make -j # && make install 注意:如果mpm為線程模型,則需要額外使用--enable-maintainer-zts (2) 安裝為fpm: # ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --enable-fpm --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/ # make -j # && make install 復制配置文件: cp php.ini-production /etc/php.ini 編譯php為httpd的模塊后,整合php至httpd: 編譯httpd.conf,添加: DirectoryIndex index.php index.html AddType application/x-httpd-php .php
原創文章,作者:qzx,如若轉載,請注明出處:http://www.www58058.com/52838