Linux課程筆記 Day09 課上內容總結 MySql,Php的安裝及Apache,Nginx,Php的優化

一 MySql

1.1?? ?如何選擇MySql的版本

?

?

1.2?? MySql單實例安裝

(1)?????? 建立mysql用戶

首先以root身份登陸到linux系統,然后執行如下命令創建mysql用戶及用戶組

[root@test3 ~]# groupadd mysql

[root@test3 ~]# useradd -s /sbin/nologin -g mysql -M mysql

[root@test3 ~]# tail -1 /etc/passwd

mysql:x:1210:1210::/home/mysql:/sbin/nologin

[root@test3 ~]# mkdir tools? #建立專門放置安裝包的目錄,養成規范的習慣

[root@test3 ~]# cd tools/

[root@test3 tools]# wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz

?

(2)?????? 解壓安裝

[root@test3 mysql-5.1.62]#./configure? \

--prefix=/usr/local/mysql \

--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \? #指定MySQL socket文件存放目錄

--localstatedir=/usr/local/mysql/data \? #設定mysql數據文件存放路徑

--enable-assembler \?? #允許使用匯編模式(優化性能)

--with-mysqld-ldflags=-all-static \? #服務器使用靜態庫(優化性能)

--with-client-ldflags=-all-static? \? #客戶端使用靜態庫(優化性能)

--enable-thread-safe-client? \??? #以線程方式編譯客戶端

--with-mysqld-user=mysql \????? #指定mysql系統運行的用戶

--with-big-tables \

--without-debug \????????????? #使用非debug模式

--with-pthread? \????????????? #強制使用pthread線程序庫編譯

--with-extra-charsets=complex \

--with-readline? \

--with-ssl? \

--with-embedded-server \

--enable-local-infile \

--with-plugins=partition,innobase \

--with-plugin-PLUGIN

?

./configure --prefix=/usr/local/mysql --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --localstatedir=/usr/local/mysql/data --enable-assembler --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile? --with-plugins=partition,innobase --with-plugin-PLUGIN

?

?

#在執行./configure的時候遇到:

configure: error: No curses/termcap library found

原因:缺少ncurses安裝包

解決:yum install? -y? ncurses-devel,然后再執行./configure

?

(3)?????? 創建配置文件

[root@test3 mysql-5.1.62]# cd support-files/

[root@test3 support-files]# ll *.cnf

-rw-r--r-- 1 root root? 4714 09-03 16:31 my-huge.cnf

-rw-r--r-- 1 root root 19763 09-03 16:31 my-innodb-heavy-4G.cnf

-rw-r--r-- 1 root root? 4688 09-03 16:31 my-large.cnf

-rw-r--r-- 1 root root? 4699 09-03 16:31 my-medium.cnf

-rw-r--r-- 1 root root? 2467 09-03 16:31 my-small.cnf

[root@test3 support-files]# /bin/cp my-small.cnf /etc/my.cnf #用模板文件直接復制為配置文件

?

(4)?????? 創建數據文件

[root@test3 ~]# mkdir /usr/local/mysql/data?????? #創建數據文件目錄

[root@test3 ~]# chown -R mysql /usr/local/mysql/?? #授權mysql用戶訪問mysql安裝目錄

[root@test3 ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql?? #安裝mysql數據文件

?

(5)?????? 啟動數據庫

方法一:

[root@test3 ~]# cp tools/mysql-5.1.62/support-files/mysql.server /usr/local/mysql/bin/

[root@test3 ~]# chmod 700 /usr/local/mysql/bin/mysql.server ?#使腳本可執行

[root@test3 ~]# /usr/local/mysql/bin/mysql.server start

Starting MySQL..?????????????????????????????????????????? [確定]

[root@test3 ~]# netstat -tupnl |grep 3306

tcp??????? 0????? 0 0.0.0.0:3306??????????????? 0.0.0.0:*?????????????????? LISTEN????? 23990/mysqld

?

方法二:按照安裝mysql時候的提示

/usr/local/mysql/bin/mysqld_safe ?--user=mysql &

?

(6)?????? 配置mysql命令全局使用路徑

方法一:

[root@test3 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

[root@test3 ~]# source /etc/profile

方法二:

把mysql的啟動命令拷貝到/usr/local/sbin/

?

(7)?????? 配置/etc/init.d/mysqld start方式啟動數據庫

[root@test3 ~]# cp tools/mysql-5.1.62/support-files/mysql.server /etc/init.d/mysqld

[root@test3 ~]# chmod 700 /etc/init.d/mysqld

[root@test3 ~]# /etc/init.d/mysqld start

Starting MySQL.??????????????????????????????????????????? [確定]

?

(8)?????? 設置mysql開機啟動

方法一:

[root@test3 ~]# chkconfig --add mysqld

[root@test3 ~]# chkconfig --list |grep mysqld

mysqld????????? 0:關閉? 1:關閉? 2:啟用? 3:啟用? 4:啟用? 5:啟用? 6:關閉

方法二:

把啟動命令放到/etc/rc.local里面

?

(9)?????? 為root設置密碼

[root@test3 ~]# mysqladmin -uroot password "123456"

[root@test3 ~]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

?

(10)?? 清理多余用戶

[root@test3 ~]# mysql -uroot -p"123456"

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

Your MySQL connection id is 5

Server version: 5.1.62 Source distribution

?

Copyright (c) 2000, 2011, 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> select user,host from mysql.user;

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

| user | host????????????? |

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

| root | 127.0.0.1???????? |

|????? | localhost???????? |

| root | localhost???????? |

|????? | test3.localdomain |

| root | test3.localdomain |

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

5 rows in set (0.00 sec)

mysql> drop user ""@localhost;

Query OK, 0 rows affected (0.00 sec)

?

mysql> drop user ""@test3.localdomain;

Query OK, 0 rows affected (0.00 sec)

?

mysql> drop user "root"@test3.localdomain;

Query OK, 0 rows affected (0.00 sec)

?

mysql> select user,host from mysql.user;

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

| user | host????? |

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

| root | 127.0.0.1 |

| root | localhost |

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

2 rows in set (0.00 sec)

遇到的問題:

?

連接數據庫的時候提示:mysql: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

首先查看libmysqlclient.so.16文件是否存在,不存在要去下載一個

解決方案一:vi /etc/ld.so.conf 增加一行/usr/local/mysql/lib/mysql

解決方案二:ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so.16? /usr/lib/

但是還是有問題,應該是因為我之前卸載了系統自帶的mysql,而/usr/bin下的mysql這個腳本還是舊的原因,所以需要/bin/cp /usr/local/mysql/bin/mysql /usr/bin/

?

二? Php安裝配置(結合的是apache)

2.1 查看以下軟件包是否安裝

[root@test3 ~]# rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

zlib-1.2.3-7.el5

freetype-2.2.1-31.el5_8.1

libpng-1.2.10-17.el5_8

libpng-1.2.10-17.el5_8

zlib-1.2.3-7.el5

libjpeg-6b-37

gd-2.0.33-9.4.el5_4.2

curl-7.15.5-15.el5

zlib-devel-1.2.3-7.el5

libjpeg-6b-37

freetype-2.2.1-31.el5_8.1

?

如果沒有安裝可以使用yum的方式安裝:

[root@test3 ~]# yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

?

?

2.2? libiconv的安裝(可選擇的還有libmcrypt(與加密相關)庫,Mhash庫,mcrypt庫)

1. libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

?

2. libmcrypt

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"

tar zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

sleep 2

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

cd ../../

?

3. Mhash

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

tar zxf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

sleep 2

cd ../

rm -f /usr/lib/libmcrypt.*

rm -f /usr/lib/libmhash*

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

?

4.mcrypt

wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"

tar zxf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

cd ../

sleep 2

?

2.3? php的安裝

[root@test3 php-5.3.10]#./configure \

> --prefix=/application/php5.3.10 \

> --with-apxs2=/application/apache/bin/apxs \? #這個需要指定bin/apxs的路徑,通過apxs來來增加php模塊到apache中

> --with-mysql=/usr/local/mysql \?? #指定mysql的路徑

> --with-xmlrpc \

> --with-openssl \

> --with-zlib \

> --with-freetype-dir \

> --with-gd \

> --with-jpeg-dir \

> --with-png-dir \

> --with-iconv=/usr/local/libiconv \

> --enable-short-tags \

> --enable-sockets \

> --enable-zend-multibyte \

> --enable-soap \

> --enable-mbstring \

> --enable-static \

> --enable-gd-native-ttf \

> --with-curl \

> --with-xsl \

> --enable-ftp \

> --with-libxml-dir

#下面的參數適合Nagios的PHP環境

--enable-sigchild

--enable-pcntl

--enable-bcmath

?

[root@test3 php-5.3.10]#make && make install

?

[root@test3 php-5.3.10]# ls php.ini*

php.ini-development (開發版) ?php.ini-production (產品版)

[root@test3 php-5.3.10]# diff php.ini-development ?php.ini-production

521c521

< error_reporting = E_ALL | E_STRICT

---

> error_reporting = E_ALL & ~E_DEPRECATED

538c538

< display_errors = On

---

> display_errors = Off

549c549

< display_startup_errors = On

---

> display_startup_errors = Off

593c593

< track_errors = On

---

> track_errors = Off

611c611

< html_errors = On

---

> html_errors = Off

1318c1318

< mysqlnd.collect_memory_statistics = On

---

> mysqlnd.collect_memory_statistics = Off

1587c1587

< session.bug_compat_42 = On

---

> session.bug_compat_42 = Off

1596c1596

< session.bug_compat_warn = On

---

> session.bug_compat_warn = Off

?

#開發版與產品版相比,多開了一些方便調試的開關

#注意PHP5.2與PHP5.3安裝之間的差別。php5.2開啟fastcgi的參數是--enable-fastcgi,而php5.3開啟的參數則是--enable-fpm

?

2.4? Php的配置

[root@test3 php-5.3.10]#/bin/cp php.ini-production /application/php5.3.10/lib/php.ini

[root@test3 conf]# cp httpd.conf httpd.conf.qinbf.20131111-2

[root@test3 conf]# vi httpd.conf

#在大約311行,增加

AddType application/x-httpd-php .php .php3

AddType application/x-httpd-php-source .phps

?

#在大約166行,修改

<IfModule dir_module>

??? DirectoryIndex ?index.php index.html #增加了默認的首頁文件index.php

</IfModule>

?

?

2.5? php測試

測試:php和apache

?

如果不關閉虛擬主機的配置文件,那么htdocs里面的首頁文件不會生效,默認會顯示在第一個虛擬主機的站點。所以要測試的話,要么關閉虛擬主機配置文件,要么把默認站點的首頁文件移動到第一個虛擬主機的配置目錄中。

?

測試:php和mysql的連接 (在瀏覽器輸入ip/test_mysql.php即可看到)

?

[root@test3 www]# vi test_mysql.php

<?php

??????? //$link_id=mysql_connect('','?','');

??????? $link_id=mysql_connect('localhost','root','qbf19880328') or mysql_error();

??????? //$link_id=mysql_connect('localhost','test','');

??????? if($link_id){

??????????????? echo "mysql successful by qinbf !";

??????? }else{

??????????????? echo mysql_error();

??????? }

//php?

/* php? */

?>

?

?

?

三 建立屬于自己的博客網站

3.1 下載解壓

[root@test3 blog]# wget http://cn.wordpress.org/wordpress-3.7.1-zh_CN.zip

[root@test3 blog]# unzip wordpress-3.7.1-zh_CN.zip

在瀏覽器中其實已經可以打開index.php文件,但是還是缺少wp-config.php文件

?

3.2 創建數據庫

[root@test3 blog]# mysql -uroot -p

Enter password:

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

Your MySQL connection id is 12

Server version: 5.1.62 Source distribution

?

Copyright (c) 2000, 2011, 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> create database wordpress DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

Query OK, 1 row affected (0.19 sec)

#建立一個GBK數據庫(默認是拉丁文字符集)

?

mysql> show databases;

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

| Database?????????? |

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

| information_schema |

| mysql????????????? |

| test?????????????? |

| wordpress????????? |

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

4 rows in set (0.14 sec)

?

mysql> grant select,insert,delete,update,create on wordpress.* to wordpress@localhost identified by '123456';

Query OK, 0 rows affected (0.16 sec)

#安裝blog后,記得要撤銷create,保留select,insert,update,delete的授權

revoke create on wordpress.*? from wordpress@’localhot’;

?

mysql> flush privileges;?? #刷新權限

Query OK, 0 rows affected (0.11 sec)

?

mysql> select user,host from mysql.user;

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

| user????? | host????? |

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

| root????? | 127.0.0.1 |

| root????? | localhost |

| wordpress | localhost |

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

3rows in set (0.04 sec)

mysql> show grants for wordpress@localhost;? #查看授權

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

| Grants for wordpress@localhost?????????????????????????????????????????????????????????????????????????????????? |

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

| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*B492CDBF83DDE8AF7B2D2249ABFE0301E091503A' |

| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `wordpress`.* TO 'wordpress'@'localhost'???????????????????????? |

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

2 rows in set (0.03 sec)

?

3.3 創建配置文件

?

?

當界面無法下一步創建的時候,選擇使用直接創建wp-config.php文件

[root@test3 blog]# cp wp-config-sample.php wp-config.php

修改配置文件如下:

/** WordPress數據庫的名稱 */

define('DB_NAME', 'wordpress');

?

/** MySQL數據庫用戶名 */

define('DB_USER', 'wordpress');

?

/** MySQL數據庫密碼 */

define('DB_PASSWORD', '123456');

?

/** MySQL主機 */

define('DB_HOST', 'localhost');

?

/** 創建數據表時默認的文字編碼 */

define('DB_CHARSET', 'gbk');

?

/** 數據庫整理類型。如不確定請勿更改 */

define('DB_COLLATE', '');

?

3.4 博客站點目錄的特殊設置

[root@test3 html]# chown root.root blog -R

[root@test3 html]# chmod 755 blog -R

#為了防止apache出現了漏洞,僅給所有程序root屬主和組

?

[root@test3 blog]# mkdir -p wp-content/uploads

[root@test3 blog]# chown daemon.daemon wp-content/uploads/ -R

#授權文件上傳目錄,如果是集群要放在公共存儲

#經過測試,wordpress前端禁止*.php,*.sh,*.bat等文件上傳

?

?

四 php擴展緩存加速等查件安裝配置

4.1 查看lamp版本

1. 查看linux系統版本

[root@test3 ~]# cat /etc/redhat-release

CentOS release 5.8 (Final)

?

2.查看apache版本

[root@test3 ~]# /application/apache/bin/apachectl -v

Server version: Apache/2.2.25 (Unix)

Server built:?? Sep? 3 2013 18:25:54

?

3. 查看php版本

[root@test3 ~]# /application/php/bin/php -v

PHP 5.3.10 (cli) (built: Nov 12 2013 00:24:52)

Copyright (c) 1997-2012 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

?

4.?查看mysql版本

[root@test3 tmp]# mysqladmin -uroot -p'123456' -S /usr/local/mysql/tmp/mysql.sock version

mysqladmin? Ver 8.41 Distrib 5.0.95, for redhat-linux-gnu on x86_64

Copyright (c) 2000, 2011, 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.

?

Server version????????? 5.1.62

Protocol version??????? 10

Connection????????????? Localhost via UNIX socket

UNIX socket???????????? /usr/local/mysql/tmp/mysql.sock

Uptime:???????????????? 8 min 23 sec

?

Threads: 1? Questions: 1? Slow queries: 0? Opens: 16? Flush tables: 1? Open tables: 4? Queries per second avg: 0.1

?

4.2?? 解決Perl編譯問題

[root@test3 ~]# echo 'LC_ALL=C' >> /etc/profile

[root@test3 ~]# tail -1 /etc/profile

LC_ALL=C

[root@test3 ~]# source /etc/profile

[root@test3 ~]# echo $LC_ALL

C

?

4.3?? eACCelerator的安裝

eACCelerator是一個自由的開放源代碼的php加速、優化和動態內容緩存的擴展模塊,它可以提升php程序的緩存性能,降低php程序在解析時對服務器的性能開銷。eACCelerator還有對PHP優化作用,加快其執行效率,使PHP程序代碼效率提高1-10倍。

phpize是什么?

phpize是用來擴展php擴展模塊的,通過phpize可以建立php的外掛模塊。比如想在原來編譯好的php中加入memcache等擴展模塊,可以使用phpize。使用方式如下:

?

[root@test3 tools]# wget ?http://sourceforge.net/projects/eaccelerator/files/latest/download

[root@test3 tools]# unzip eaccelerator-0.9.6.1.zip

[root@test3 tools]# cd eaccelerator-0.9.6.1

[root@test3 eaccelerator-0.9.6.1]# /application/php/bin/phpize

Configuring for:

PHP Api Version:???????? 20090626

Zend Module Api No:????? 20090626

Zend Extension Api No:?? 220090626

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script

#出現這個錯誤是因為沒有安裝m4和autoconf包,可以嘗試使用yum install或者源碼安裝這兩個包,然后重新執行/application/php/bin/phpize

[root@test3 eaccelerator-0.9.6.1]# yum install m4 autoconf

[root@test3 eaccelerator-0.9.6.1]# /application/php/bin/phpize

Configuring for:

PHP Api Version:???????? 20090626

Zend Module Api No:????? 20090626

Zend Extension Api No:?? 220090626

[root@test3 eaccelerator-0.9.6.1]# ./configure --enable-eaccelerator=shared --with-php-config=/application/php/bin/php-config

[root@test3 eaccelerator-0.9.6.1]# make? && make? install

實踐測試:

提示:

1)? php5.3.10可用eaccelerator-0.9.6版本,如果使用eaccelerator-0.9.5.2版本會在make階段報如下錯誤:make: ***[optimize.lo] Error 1

2)? php5.2.6可用eaccelerator-0.9.5.2版本

?

4.4?? 安裝memcache緩存擴展模塊

軟件說明:

Memcache是一個高性能的分布式的內存對象緩存系統,通過在內存里維護一個統一的巨大的hash表,它能夠用來存儲各種格式的數據,包括圖像、視頻、文件以及數據庫檢索的結果等。簡單的說就是將數據調用到內存中,然后從內存中讀取,從而大大提高讀取速度。

Memcache分為服務端軟件(名字如:memcached-1.4.3.tar.gz)和客戶端插件(名字如:memcache-2.2.5.tar.gz)兩部分。本文是客戶端插件在php服務中的安裝。

[root@test3 tools]# wget ?http://pecl.php.net/get/memcache-2.2.5.tgz

[root@test3 tools]# tar zxf memcache-2.2.5.tgz

[root@test3 tools]# cd memcache-2.2.5

[root@test3 memcache-2.2.5]# /application/php/bin/phpize

[root@test3 memcache-2.2.5]# ./configure --with-php-config=/application/php/bin/php-config [root@test3 memcache-2.2.5]# make? &&? make install

[root@test3 memcache-2.2.5]# ll /application/php5.3.10/lib/php/extensions/no-debug-zts-20090626/

總計 628

-rwxr-xr-x 1 root root 406459 11-14 03:22 eaccelerator.so

-rwxr-xr-x 1 root root 222246 11-14 03:44 memcache.so

提示:如果安裝memcache-2.2.4,可能報錯make:***[memcache.lo] Error 1 解決:cp memcache.loT memcache.lo

?

4.5?? 安裝PDO_MYSQL擴展模塊

PDO擴展為PHP訪問數據庫定義了一個輕量級的、一致性的接口,它提供了一個數據訪問抽象層,這樣,無論是用什么數據庫,都可以通過一致的函數執行查詢和獲取數據。

[root@test3 tools]# wget ?http://lcmp.googlecode.com/files/PDO_MYSQL-1.0.2.tgz

[root@test3 tools]# tar zxf PDO_MYSQL-1.0.2.tgz

[root@test3 tools]# cd PDO_MYSQL-1.0.2

[root@test3 PDO_MYSQL-1.0.2]# /application/php/bin/phpize

[root@test3 PDO_MYSQL-1.0.2]# ./configure --with-php-config=/application/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

[root@test3 PDO_MYSQL-1.0.2]#make && make install

?

4.6?? 安裝圖像處理程序及imageMagick軟件

4.6.1 安裝imageMagick軟件

[root@test3 tools]# wget ?http://www.imagemagick.org/download/ImageMagick-6.8.7-5.tar.gz

[root@test3 tools]# tar zxf ImageMagick-6.8.7-5.tar.gz

[root@test3 tools]#cd? ImageMagick-6.8.7-5.tar.gz

[root@test3 tools]#./configure

[root@test3 tools]#make && make install

因為此步不是php的擴展,所以沒有.so文件

?

4.6.2 安裝image php擴展插件

image插件需要imageMagick的支持,不先安裝imageMagick會報錯。是一個供php調用imageMagick功能的擴展,進行圖片的創建與修改壓縮等操作,都集成在imagick這個擴展中。

[root@test3 tools]# wget http://pecl.php.net/get/imagick-3.0.1.tgz

[root@test3 tools]# tar zxf imagick-3.0.1.tgz

[root@test3 tools]# cd imagick-3.0.1

[root@test3 imagick-3.0.1]# ./configure --with-php-config=/application/php/bin/php-config

[root@test3 imagick-3.0.1]# make && make install

#make的過程中遇到checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h的報錯,解決如下:(imagick-2.3.0.tgz沒有遇到這個問題)

今天在新服上安裝php imagick,

?

環境如下:

php 5.3.20

ImageMagick-6.8.3-8

imagick-3.1.0RC2

可是出錯了一個問題.就是死說找不到MagickWand.h:

?

checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h

?

可是我明明正確安裝了ImageMagick的呀.GOOGLE了半天,也解決不了這個問題.后面對照另一個服務器上的ImageMagick才發現,原來ImageMagick 6.8這個版后的目錄結構變了,舊版本頭文件是放在/usr/local/include/ImageMagick目錄的,而ImageMagick 6.8則是放在/usr/local/include/ImageMagick-6

?

添加軟連接

?

命令如下:

?

ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick

?

后來發現imagick-3.1.0RC2編譯不通過,于是降低版本,使用imagick-3.01

?

make && make && install

?

搞掂!

?

?

?

更新:

?

最終解決方法:(以下是對于imagick操作的)

?

yum install pkgconfig

?

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/

?

rm -rf Makefile config.status config.h

?

./configure

?

make

?

make install

?

?

4.7?? 安裝Zend緩存及加速擴展模塊

Zend Optimizer使用優化代碼的方法來提高PHP應用程序的執行速度,要比不使用的要快40%到100%。(對于PHP 5.2或更早的版本有效,對5.3版本無效)

?

4.8?? 安裝xcache緩存加速擴展模塊

Xcache是一個又快又穩定的PHP opcode緩存器,能夠快速跟進PHP版本。

?

Xcache的2個特點:

將PHP代碼進行編譯,這樣可以不用重復讀取PHP文件,加速整個程序的運行效率

??? 可以緩存數據到內存中,直接可以方便調用,例如你的一些不會經常改動的數據,只用一次從數據庫讀取出來后保存到Xcache中,就不用再去使用數據庫了。

wget http://xcache.lighttpd.net/pub/Releases/3.0.0/xcache-3.0.0.tar.gz

tar zxf xcache-3.0.0.tar.gz

cd xcache-3.0.0

/application/php/bin/phpize?

./configure --enable-xcache --with-php-config=/application/php/bin/php-config

make?

make install

ll /application/php5.3.10/lib/php/extensions/no-debug-zts-20090626/

?

4.9?? 配置相關php擴展插件模塊

4.9.1????????? 修改php的配置文件

(1) 修改/application/php/lib/php.ini 查找;extension_dir=”./”,修改為/application/php5.3.10/lib/php/extension/no-debug-zts-20090626

[root@test3 ~]# cd /application/php/lib/

[root@test3 lib]# ls

php? php.ini

[root@test3 lib]# cp php.ini php.ini.20131115

?

[root@test3 lib]# sed -i 's#; extension_dir = "./"#extension_dir = "/application/php5.3.10/lib/php/extension/no-debug-zts-20090626/"#g' php.ini

?

[root@test3 lib]# grep "extension_dir =" php.ini

extension_dir = "/application/php5.3.10/lib/php/extensions/no-debug-zts-20090626/"

; extension_dir = "ext"

;sqlite3.extension_dir =

(2) 在php.ini的最后幾行添加:

cat >>/application/php/lib/php.ini << EOF

;--cache ext start by qinbf 2013-11-15--

extension = memcache.so

extension = pdo_mysql.so

extension = imagick.so

;--cache ext end by qinbf 2013-11-15--

EOF

[root@test3 lib]# tail -5 php.ini

;--cache ext start by qinbf 2013-11-15--

extension = memcache.so

extension = pdo_mysql.so

extension = imagick.so

;--cache ext end by qinbf 2013-11-15--

?

4.10 ?配置eAccelerator插件

4.10.1配置eaccelerator緩存目錄

[root@test3 lib]# mkdir -p /tmp/eaccelerator

[root@test3 lib]# egrep "User|Group" /application/apache/conf/httpd.conf

# User/Group: The name (or #number) of the user/group to run httpd as.

User daemon

Group daemon

[root@test3 lib]# chown daemon.daemon? -R /tmp/eaccelerator

?

4.10.2 配置eaccelerator參數

注意:[eaccelerator]要放在Zend配置內容之前

[root@oldboy lib]# cat >> /application/php/lib/php.ini<<EOF

[eaccelerator]

extension=eaccelerator.so

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

EOF

?

[root@test3 lib]# tail -20 php.ini

;--cache ext start by qinbf 2013-11-15--

extension = memcache.so

extension = pdo_mysql.so

extension = imagick.so

;--cache ext end by qinbf 2013-11-15--

[eaccelerator]

extension=eaccelerator.so

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

[root@test3 lib]# /application/php/bin/php -v

PHP 5.3.10 (cli) (built: Nov 12 2013 00:24:52)

Copyright (c) 1997-2012 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

?

[root@test3 lib]# ll /tmp/eaccelerator/

總計 64

drwxrwxrwx 18 root root 4096 11-14 07:10 0

drwxrwxrwx 18 root root 4096 11-14 07:10 1

drwxrwxrwx 18 root root 4096 11-14 07:10 2

drwxrwxrwx 18 root root 4096 11-14 07:10 3

drwxrwxrwx 18 root root 4096 11-14 07:10 4

drwxrwxrwx 18 root root 4096 11-14 07:10 5

drwxrwxrwx 18 root root 4096 11-14 07:10 6

drwxrwxrwx 18 root root 4096 11-14 07:10 7

drwxrwxrwx 18 root root 4096 11-14 07:10 8

drwxrwxrwx 18 root root 4096 11-14 07:10 9

drwxrwxrwx 18 root root 4096 11-14 07:10 a

drwxrwxrwx 18 root root 4096 11-14 07:10 b

drwxrwxrwx 18 root root 4096 11-14 07:10 c

drwxrwxrwx 18 root root 4096 11-14 07:10 d

drwxrwxrwx 18 root root 4096 11-14 07:10 e

drwxrwxrwx 18 root root 4096 11-14 07:10 f

?

4.11 ? 修改php.ini配置xcache

一般認為xcache和eaccelerator功能相近,安裝一個即可。如果想同時安裝,那么eaccelerator的配置內容必須在xcache之后。

;xcache config by qinbf 20131115---------------------

[xcache-common]

;; install as zend extension (recommended), normally "$extension_dir/xcache.so"

;zend_extension = /usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so

; zend_extension_ts = /usr/local/lib/php/extensions/non-debug-zts-xxx/xcache.so

;; For windows users, replace xcache.so with php_xcache.dll

;zend_extension_ts = c:/php/extensions/php_xcache.dll

;; or install as extension, make sure your extension_dir setting is correct

extension = xcache.so

;; or win32:

; extension = php_xcache.dll

?

;xcache config by qinbf 20131115----------------------

?

[xcache.admin]

[xcache.admin]

xcache.admin.enable_auth = On

?

xcache.admin.user = "mOo"

; xcache.admin.pass = md5($your_password)

xcache.admin.pass = ""

?

[xcache]

[xcache]

; ini only settings, all the values here is default unless explained

?

; select low level shm/allocator scheme implemenation

xcache.shm_scheme =??????? "mmap"

; to disable: xcache.size=0

; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows

xcache.size? =?????????????? 128M

; set to cpu count (cat /proc/cpuinfo |grep -c processor)

xcache.count =???????????????? 2

; just a hash hints, you can always store count(items) > slots

xcache.slots =??????????????? 8K

; ttl of the cache item, 0=forever

xcache.ttl?? =???????????????? 86400

; interval of gc scanning expired items, 0=no scan, other values is in seconds

xcache.gc_interval =?????????? 3600

?

; same as aboves but for variable cache

xcache.var_size? =??????????? 0

xcache.var_count =???????????? 1

xcache.var_slots =??????????? 8K

; default ttl

xcache.var_ttl?? =???????????? 0

xcache.var_maxttl?? =????????? 0

xcache.var_gc_interval =???? 300

?

否則會報錯:

[root@oldboy lib]# /application/php/bin/php -v

PHP Warning:? Cannot load module 'XCache' because conflicting module 'eAccelerator' is already loaded in Unknown on line 0

PHP 5.3.10 (cli) (built: Apr? 7 2012 22:42:50)

Copyright (c) 1997-2012 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

?

?

正常情況下:

?

?

?

?

五 ?Apache服務優化

5.1 配置Apache日志輪詢

apache自帶的日志輪詢工具也是可以使用的,但是老師測試會丟日志,所以采用cronolog來配置日志輪詢

?

tar zxf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

./configure?

make?

make install

<VirtualHost *:80>

??? ServerAdmin qinbf@etiantian.com

??? DocumentRoot "/var/html/www"

??? ServerName www.etiantian.com

??? ServerAlias etiantian.com

??? ErrorLog "logs/www.etiantiancom-error_log"

?? # CustomLog "logs/www.etiantiancom-access_log" common

CustomLog "|/usr/local/sbin/cronolog /application/apache/logs/access_www_%w.log" combined

#注意這里要寫全路徑,%w表示按周輪詢

</VirtualHost>

?

5.2 錯誤頁面優雅顯示

[root@test3 bin]# grep "ErrorDocument 404" /application/apache/conf/httpd.conf

#ErrorDocument 404 /missing.html

#ErrorDocument 404 "/cgi-bin/missing_handler.pl"

#可以指定404錯誤提示的頁面,可以是URL,也可以是腳本或者文件

?

5.3 mod_deflate文件壓縮功能

5.3.1 mod_deflate模塊介紹

mod_deflate模塊提供了DEFLATE輸出過濾器,允許服務器在將輸出內容發送到客戶端之前進行壓縮,提升用戶體驗。

?

5.3.2 mod_deflate安裝檢查

(1)編譯安裝httpd情況時是否已經安裝mod_deflate,命令為:

[root@test3 ~]# /application/apache/bin/apachectl -l |grep mod_deflate

? mod_deflate.c

(2)如果是以DSO方式編譯的(--enable-so開啟DSO編譯方式),則查看方法為:

[root@test3 ~]# ls /application/apache/modules/ |grep mod_deflate

mod_deflate.so

[root@test3 ~]# grep mod_deflate.so /application/apache/conf/httpd.conf

LoadModule? deflate_module? modules/mod_deflate.so

[root@test3 ~]# /application/apache/bin/apachectl -M |grep deflate

?deflate_module(dynamic) ?#static是表示在編譯的時候就已經安裝了

Syntax OK

特別說明:以上兩種情況不能同時存在,否則會有沖突

?

5.3.3 mod_deflate安裝

cd? /root/tools/httpd-2.2.25/modules/filters

/application/apache/bin/apxs -c -a -i mod_deflate.c

ll /application/apache/modules/mod_deflate.so

?

#如果提示沖突,要把/application/apache/conf/httpd.conf文件中,LoadModule? deflate_module? modules/mod_deflate.so這句命令注釋掉。

?

5.3.4 mod_deflate應用

<ifmodule mod_deflate.c>

DeflateCompressionLevel? 9

SetOutputFilter DEFLATE

DeflateFilterNote? Input? instream

DeflateFilterNote? Output? outstream

DeflateFilterNote? Ratio? ratio

#Logformat? ‘? “%r”? %{outstream}n/%{instream}n? (%{ratio}n%%)’ deflate

#CustomLog? logs/deflate_log.log deflate

</ifmodule>

?

#把以上這段代碼嵌入到/application/apache/conf/extra/httpd-vhosts.conf的/var/html/www配置內容里面(也可以配置到全局目錄里面)

?

<VirtualHost *:80>

??? ServerAdmin qinbf@etiantian.com

??? DocumentRoot "/var/html/www"

??? ServerName www.etiantian.com

??? ServerAlias etiantian.com

??? ErrorLog "logs/www.etiantiancom-error_log"

??? CustomLog "logs/www.etiantiancom-access_log" common

?? <ifmodule mod_deflate.c>

??????? DeflateCompressionLevel? 9

??????? SetOutputFilter DEFLATE

??????? DeflateFilterNote? Input? instream

??????? DeflateFilterNote? Output? outstream

??????? DeflateFilterNote? Ratio? ratio

??????? #Logformat? ‘? “%r”? %{outstream}n/%{instream}n? (%{ratio}n%%)’ deflate

??????? #CustomLog? logs/deflate_log.log deflate

?? </ifmodule>

?

</VirtualHost>

?

?

測試:把老師的test_deflate.tar.gz壓縮包上傳到/var/html/www下,然后解壓,不需要做任何移動。打開Firefox開發專版,訪問192.168.1.4/test/deflate.html,打開firebug,在YSlow中可以看到測試結果。

?

?

?

?

5.4 mod_expires緩存功能

Expire其實就是通過header報文來指定特定類型的文件在瀏覽器中的緩存時間。大多數的圖片,flash在發布后都不是需要經常修改的,做了緩存以后這樣的瀏覽器以后就不需要再從服務器下載這些文件而是直接從緩存中讀取,這樣再訪問頁面的速度會大大加快。

?

在剛才的mod_deflate模塊配置內容下面加入以下配置:

ExpiresActive on

ExpiresDefault "access plus 12 month"

ExpiresByType text/html "access plus 12 months"

ExpiresByType text/css "access plus 12 months"

ExpiresByType image/gif "access plus 12 months"

ExpiresByType image/jpeg "access plus12? 12 months"

ExpiresByType image/jpg "access plus 12 months"

ExpiresByType image/png "access plus 12 months"

EXpiresByType application/x-shockwave-flash "access plus 12 months"

EXpiresByType application/x-javascript "access plus 12 months"

ExpiresByType video/x-flv "access plus 12 months"

[root@test3 www]# curl -I 192.168.1.4/01.jpg

HTTP/1.1 200 OK

Date: Sun, 17 Nov 2013 03:51:45 GMT

Server: Apache/2.2.25 (Unix) DAV/2 PHP/5.3.10

Last-Modified: Sun, 07 Nov 2010 12:20:20 GMT

ETag: "40904-486f3-4947587f66900"

Accept-Ranges: bytes

Content-Length: 296691

Cache-Control: max-age=31104000

Expires: Wed, 12 Nov 2014 03:51:45 GMT

Vary: Accept-Encoding

Content-Type: image/jpeg

?

5.5 更改Apache默認用戶

創建一個用戶例如Apache(最好起一個不常用的名字),用于子進程和子線程。

useradd? -M? -s /sbin/nologin? apache

vi? /application/apache/conf/httpd.conf

User? apache

Group? apache

5.6? worker模式提升并發數

?

5.7? 屏蔽apache版本等敏感信息

(1) 修改httpd.conf文件,打開httpd-default.conf模塊

(2) 修改httpd-default.conf文件,ServerSignature Off以及ServerTokens Prod之后apachectl graceful使設置生效

?

5.8 apache目錄文件權限設置(root,目錄755,文件644)

[root@test3 html]# ll

總計 12

drwxr-xr-x 2 root root 4096 09-03 18:51 bbs

drwxr-xr-x 5 root root 4096 11-12 01:53 blog

drwxr-xr-x 3 root root 4096 11-17 11:43 www

提示:在網站架構中,應把資源文件,包括用戶上傳的圖片,福建等和程序分離,最好把上傳程序也分離,這樣就可以從容授權了。

?

5.9 開啟httpd-mpm.conf增加連接數

?

5.10 apache防盜鏈功能

?

5.11 禁止目錄Index

Option? FollowSymLinks 這一個參數去掉Index選項

?

5.12 禁止用戶覆蓋(重載)

AllowOverride None? #禁止用戶覆蓋(重載)

#加快服務器速度,因為它不再為每個請求尋找每個目錄訪問控制問價(.htaccess)

?

5.13 關閉CGI

ScriptAlias /cgi-bin/ "/application/apache2.2.25/cgi-bin/"

<Directory "/application/apache2.2.25/cgi-bin">

??? AllowOverride None

??? Options None

??? Order allow,deny

??? Allow from all

</Directory>

刪除以上內容

?

5.14 避免使用.htaccess文件(分布式配置文件)

首先從性能上,就應該避免使用.htaccess文件

?

5.15 apache安裝模塊

(mod_evasive20防DDOS、mod_limitipconn(針對單站點)配置、mod_security防SQL注入等

makejail?? http://www.floc.net/makejail

是一個自動把建立jail所需要的程序放到jail內的軟件

mod_security?? http://www.modsecurity.org

是apache的一個模塊,他有請求過濾,日志審計等功能,可以防止SQL Injection,跨站腳本攻擊,很不錯的一個模塊

?

16. 正確途徑取得源代碼,勤打apache補丁

?

17. apache日志授予root700權限

chown? -R root.root logs

chmod? -R 700 logs?

?

18. 系統內核參數優化

?

19. 禁止PHP解析指定站點目錄

?

20. 使用tmps文件系統替代頻繁訪問的目錄

?

21盡可能減少HTTP請求數

?

22. 使用CDN做網站加速

?

23. apache程序架構優化

1) 程序頁面服務器? 2)圖片附件服務器? 3)上傳服務器? 三者的功能盡量分離

a) 分離最佳方式是分別使用獨立的服務器(需要程序支持)

b) 次選方案在前端負載均衡器通過haproxy/nginx根據目錄或擴展名請求后面對應的服務器

?

?

?

六 apache服務Forbidden 403問題精彩講解

403 Forbidden資源不可用。服務器理解客戶的請求,但拒絕處理它。通常由于服務器上文件或目錄的權限設置導致。

?

原因1(重要)

apache配置文件中沒有對站點目錄的權限許可配置,這通常是在初始安裝apache后,更改了默認的apache站點目錄導致。如編譯安裝apache(假定安裝目錄為/application/apache2.2.23/)后,將站點目錄更改為其他的路徑:/var/html,則會報403錯誤

?

原因2

站點目錄下無首頁文件,而apache的配置又禁止了目錄瀏覽,就會提示403錯誤

?

原因3

Directory目錄權限問題: Order中allow,deny的順序以及限制

?

原因4

站點目錄權限問題:站點目錄需要apache的用戶有訪問的權限(把/var/html的屬主和屬組設為root,那么就要給755權限,否則apache的用戶無法讀取文件)

?

?

七 Nginx深入應用實踐

7.1 關于Nginx模塊

Nginx使用不同的模塊實現不同的功能,主要有2組重要的模塊:

(1) Nginx core modules(必需的)

包括Main、Events

?

(2) Standard? HTTP modules(雖然不是必需的,但是缺省都會安裝,不建議改動)

典型的包括

Core、Access、FastCGI、Gzip、Log、Proxy、Rewrite、Upstream

?

7.2 Nginx目錄結構

/application/nginx

|-- client_body_temp

|-- conf

|?? |-- fastcgi.conf?? #fastcgi配置文件

|?? |-- fastcgi.conf.default?? #default文件均屬于備份文件

|?? |-- fastcgi_params

|?? |-- fastcgi_params.default

|?? |-- koi-utf

|?? |-- koi-win

|?? |-- mime.types

|?? |-- mime.types.default

|?? |-- nginx.conf?? #Nginx主配置文件

|?? |-- nginx.conf.default

|?? |-- nginx.conf.qinbf-20131101

|?? |-- scgi_params

|?? |-- scgi_params.default

|?? |-- uwsgi_params

|?? |-- uwsgi_params.default

|?? `-- win-utf

|-- fastcgi_temp

|-- html

|?? |-- 50x.html? #錯誤優雅顯示文件

|?? `-- index.html

|-- logs

|?? |-- access.log? #訪問日志

|?? |-- error.log?? #錯誤日志

|?? `-- nginx.pid?

|-- proxy_temp

|-- sbin

|?? `-- nginx

|-- scgi_temp

`-- uwsgi_temp

?

9 directories, 22 files

?

7.3 Nginx.conf配置文件

worker_processes? 1;? #ps -ef |grep nginx可以查看到nginx的子線程數

?

events {

??? worker_connections? 1024;? #可以理解為最大并發數

}

?

?

http {

??? include?????? mime.types;

??? default_type? application/octet-stream;

??? sendfile??????? on;

??? keepalive_timeout? 65;

?

??? server {? #一個server相當于apache的一個vhost,可以復制多個server模塊配置多個主機

??????? listen?????? 80;

??????? server_name? localhost;

?

??????? location / {?? #相當于htdocs

??????????? root?? html;

??????????? index? index.html index.htm;

??????? }

?

??????? error_page?? 500 502 503 504? /50x.html;? #優雅顯示頁面

??????? location = /50x.html {

??????????? root?? html;

?

??????? }

?

??? }

?

}

?

7.4 基于域名的虛擬主機配置

http {

?10???? include?????? mime.types;

?11???? default_type? application/octet-stream;

?12???? sendfile??????? on;

?13???? keepalive_timeout? 65;

?14

?15???? server {

?16???????? listen?????? 80;

?17???????? server_name? www.etiantian.org;

?18

?19???????? location / {

?20???????????? root?? html;

?21???????????? index? index.html index.htm;

?22???????? }

?23

?24???????? error_page? ?500 502 503 504? /50x.html;

?25???????? location = /50x.html {

?26???????????? root?? html;

?27

?28???????? }

?29

?30???? }

?31

?32 }

?

然后檢查語法,優雅重啟

[root@test2 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.2.9/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.2.9/conf/nginx.conf test is successful

[root@test2 conf]# /application/nginx/sbin/nginx -s reload

[root@test2 conf]# netstat -tupnl |grep 80

tcp??????? 0????? 0 0.0.0.0:80?????? ???????????0.0.0.0:*?????????????????? LISTEN????? 21475/nginx??

?

配置虛擬主機流程:

1)? 復制server標簽段,到結尾,注意放到http的結束大括號前

2)? 更改server_name及對應網頁的根目錄

3)? 創建對應網頁的根目錄,并建立測試文件

4)? 檢查語法,重啟服務

5)? 在host文件做解析

6)? 瀏覽器訪問

?

7.5 禁止ip訪問

為防止域名惡意解析到自己的服務器上,必須要配置禁止ip訪問

server? {

???? listen? 80? default;

???? return 500;

}

#這段配置,是將訪問沒有配置為本服務器虛擬主機的域名,默認返回500錯誤

?

#也可以利用rewrite規則,把惡意解析到本服務器的域名訪問流量,導入到自己的站點

server? {

?????? listen? 80? default;

?????? rewrite? ^(.*)? http://www.etiantian.com? permanent;

}

#域名解析到本地服務器,但是并未為該域名配置本地服務器的虛擬主機,將跳轉到rewrite定義的站點上

?

#server_name? _;? 這個的含義代表輸入ip地址直接訪問的結果

#listen? 80? default_server;? default_server這個參數用于nginx 0.8版本之后

?

7.6 nginx日志配置及切割

目前還沒有比較好的Nginx日志切割工具

日志的格式定義:

log_format? commonlog? '$remote_addr - $remote_user [$time_local] "$request" '

?????????????????????????? '$status $body_bytes_sent "$http_referer" '

?????????????????????????? '"$http_user_agent" "$http_x_forwarded_for"';

?

??? server {

??????? listen?????? 80;

??????? server_name? www.etiantian.com;

?

??????? location / {

??????????? root?? /data0/www/www;

??????????? index? index.html index.htm;

??????? }

?

??????? error_page?? 500 502 503 504? /50x.html;

??????? location = /50x.html {

??????????? root?? html;

?

??????? }

?

??????? access_log /app/logs/www_access.log commonlog;

??????? #日志格式的調用

???? }

?

192.168.1.1 - - [22/Nov/2013:00:27:32 +0800] "GET /favicon.ico HTTP/1.1" 404 570 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36" "-"

?

?

日志切割腳本

#!/bin/bash

date=`date +%Y%m%d`

Nginx_Dir="/application/nginx"

Nginx_Logs="/app/logs"

Log_Name="www_access"

?

cd /tmp

[ -d $Nginx_Logs ] && cd $Nginx_Logs || exit 1

[ -f $Log_Name.log ] && /bin/mv $Log_Name.log? ${Log_Name}.${date}.log || exit 1

if [ $? -eq 0 -a -f $Nginx_Dir/logs/nginx.pid ]

?? then

????? kill -USR1 `cat? $Nginx_Dir/logs/nginx.pid`?

#把nginx的日志重命名相當于刪除文件,需要重啟nginx服務

fi

?

?

然后每天晚上12點切割

crontab? -e

00 ?00 ?* * * /bin/sh /root/scripts/cut_nginx_log.sh >/dev/null 2>&1

?

統計IP并排序

awk '{print $1}' www_access.log? | sort | uniq -c | sort -rn -k 1 | head

?

?

7.7? Nginx配置文件優化

worker_processes? 1;

?

?

events {

??? worker_connections? 1024;

}

?

?

http {

??? include?????? mime.types;

??? default_type? application/octet-stream;

??? sendfile??????? on;

??? keepalive_timeout? 65;

??? log_format? commonlog? '$remote_addr - $remote_user [$time_local] "$request" '

?????????????????????????? '$status $body_bytes_sent "$http_referer" '

?????????????????????????? '"$http_user_agent" "$http_x_forwarded_for"';

???

??? include extra/www.conf;

??? include extra/bbs.conf;

??? include extra/blog.conf;

??? include extra/default.conf;

?

}

模仿apache配置文件,把虛擬主機的配置寫在extra目錄的配置文件內,然后用include的方式調用。

?

7.8? Nginx別名及連接狀態信息配置

#別名其實就是以相應的別名配置虛擬主機,然后利用rewrite規則,跳轉到主域名上。

專門寫一個配置文件內容如下:

server {

??????? listen?????? 80;

??????? server_name? etiantian.com;

???????

??????? rewrite ^(.*) http://www.etiantian.com permanent;

?

?}

?

然后在nginx文件將調用此文件:include? extra/www_alias.conf

?

?

即是配置一個虛擬主機文件,內容如下:

server {

??????? listen?????? 80;

??????? server_name? status.etiantian.com;

?

??????? location / {

??????? stub_status on;

??????? access_log off;

??????? }

}

然后在nginx.conf文件中調用此配置文件

?

?

?

?

八 動態語言php應用(fastCGI應用)

8.1? FastCGI介紹

FastCGI是語言無關的,可伸縮架構的CGI開放擴展,其主要行為是將CGI解釋器進程保持在內存中并因此獲得較高的性能。它還支持分布式的運算, 即 FastCGI 程序可以在網站服務器以外的主機上執行并且接受來自其它網站服務器來的請求。即nginx和FastCGI是獨立的,而不像apache和php那樣是密不可分的。

FastCGI用于結合nginx和PHP,類似于apache和php結合的模塊。

?

8.2? FastCGI原理

1、Web Server啟動時載入FastCGI進程管理器(IIS ISAPI或Apache Module)

2、FastCGI進程管理器自身初始化,啟動多個CGI解釋器進程(可見多個php-cgi)并等待來自Web Server的連接。

3、當客戶端請求到達Web Server時,FastCGI進程管理器選擇并連接到一個CGI解釋器。Web server將CGI環境變量和標準輸入發送到FastCGI子進程php-cgi。

4、FastCGI子進程完成處理后將標準輸出和錯誤信息從同一連接返回Web Server。當FastCGI子進程關閉連接時,請求便告處理完成。FastCGI子進程接著等待并處理來自FastCGI進程管理器(運行在Web Server中)的下一個連接。 在CGI模式中,php-cgi在此便退出了。

?

在上述情況中,你可以想象CGI通常有多慢。每一個Web請求PHP都必須重新解析php.ini、重新載入全部擴展并重初始化全部數據結構。使用FastCGI,所有這些都只在進程啟動時發生一次。一個額外的好處是,持續數據庫連接(Persistent database connection)可以工作。

?

8.3 檢查以下軟件包是否安裝

[root@test3 ~]# rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

zlib-1.2.3-7.el5

freetype-2.2.1-31.el5_8.1

libpng-1.2.10-17.el5_8

libpng-1.2.10-17.el5_8

zlib-1.2.3-7.el5

libjpeg-6b-37

gd-2.0.33-9.4.el5_4.2

curl-7.15.5-15.el5

zlib-devel-1.2.3-7.el5

libjpeg-6b-37

freetype-2.2.1-31.el5_8.1

?

如果沒有安裝可以使用yum的方式安裝:

[root@test3 ~]# yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel ?openldap-devel libxslt-devel

?

?

附上CentOS下常見編譯PHP的錯誤及解決辦法

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

yum install libxml2-devel

?

configure: error: Cannot find OpenSSL’s

yum install openssl-devel

?

configure: error: Please reinstall the libcurl distribution -

?

?

easy.h should be in /include/curl/

yum install curl-devel

configure: error: libjpeg.(a|so) not found

yum install libjpeg-devel

?

configure: error: libpng.(a|so) not found.

yum install libpng-devel

?

configure: error: libXpm.(a|so) not found.

yum install libXpm-devel

?

configure: error: freetype.h not found.

yum install freetype-devel

?

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

yum install libc-client-devel

?

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

yum install libmcrypt-devel

?

configure: error: Please reinstall libmhash – I cannot find mhash.h

yum install mhash-devel

?

configure: error: Cannot find MySQL header files under /usr.

Note that the MySQL client library is not bundled anymore!

yum install mysql-devel

?

configure: error: Please reinstall ming distribution. libming.(a|so) not found

- temp remove the config for ‘–with-ming=/opt/ming/’

?

configure: error: Cannot find pspell

yum install pspell-devel

?

configure: error: cannot find mm library

Download from http://www.ossp.org/pkg/lib/mm/

wget ftp://ftp.ossp.org/pkg/lib/mm/mm-1.4.2.tar.gz

Extract it:? tar -zxvf mm-1.4.2.tar.gz

./configure

make

make install

?

configure: error: Cannot find libtidy

yum install libtidy-devel

yum install libtidy

change path at configure: ‘–with-tidy=/usr’

?

configure: error: not found. Please reinstall the expat distribution.

yum install expat-devel

?

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install libxslt-devel

?

*Tips: To uninstall, just enter:

yum remove {package-name}

?

8.4? libiconv、libmcrypt、Mhash、mcrypt的安裝

1. libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

?

2. libmcrypt

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"

tar zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

sleep 2

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

cd ../../

?

3. Mhash

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

tar zxf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

sleep 2

cd ../

rm -f /usr/lib/libmcrypt.*

rm -f /usr/lib/libmhash*

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

?

4.mcrypt

wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"

tar zxf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make

make install

cd ../

sleep 2

?

?

8.5 ?php5.3.27的編譯參數(結合的是nginx)

./configure \

--prefix=/application/php5.3.27 \

--with-mysql=/usr/local/mysql \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-safe-mode \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--with-curlwrappers \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-ldap \

--with-ldap-sasl \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-zend-multibyte \

--enable-static \

--with-xsl \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-ftp

#--enable-discard-path

#--enable-fastcgi

#--enable-force-cgi-redirect

#--with-libevent-dir 這個參數在php5.3.10中是支持的

--enable-fpm這個參數時開啟fastcgi的,是nginx結合php用的參數,在apache編譯的參數中是沒有的

?

要記得先安裝8.2步驟中的那些軟件包,否則在安裝過程中可能會遇到各種各樣的問題

?

8.6? PHP的配置

1. php.ini的配置

[root@test2 php-5.3.27]# pwd

/root/tools/php-5.3.27

[root@test2 php-5.3.27]# /bin/cp php.ini-production /application/php5.3.27/lib/php.ini

?

2. php-fpm

[root@test2 etc]# pwd

/application/php5.3.27/etc

[root@test2 etc]# ls php-fpm.conf.default

php-fpm.conf.default

[root@test2 tools]# cp php-fpm.conf.5.3.10 /application/php5.3.27/etc/php-fpm.conf

#用老師改好的文件復制為/application/php5.3.27/etc/php-fpm.conf

?

[root@test2 tools]# /application/php/sbin/php-fpm -t

[29-Nov-2013 00:28:11] NOTICE: configuration file /application/php5.3.27/etc/php-fpm.conf test is successful

#檢查語法

?

[root@test2 tools]# pkill php-fpm

[root@test2 tools]# /application/php/sbin/php-fpm

#重啟服務

?

[root@test2 tools]# ps -ef |grep php-fpm

root???? 17875???? 1? 1 00:29 ???????? 00:00:00 php-fpm: master process (/application/php5.3.27/etc/php-fpm.conf)

nginx??? 17876 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17877 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17878 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17879 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17880 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17881 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17882 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17883 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17884 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17885 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx? ??17886 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17887 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17888 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17889 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17890 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

nginx??? 17891 17875? 0 00:29 ???????? 00:00:00 php-fpm: pool www???????????

root???? 17893? 2685? 0 00:29 pts/0??? 00:00:00 grep php-fpm

[root@test2 tools]# netstat -tupnl |grep 9000

tcp??????? 0????? 0 127.0.0.1:9000????????????? 0.0.0.0:*?????????????????? LISTEN????? 17875/php-fpm??????

[root@test2 tools]#

[root@test2 tools]# lsof -i :9000

COMMAND?? PID? USER?? FD?? TYPE DEVICE SIZE/OFF NODE NAME

php-fpm 17875? root??? 7u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17876 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17877 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17878 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17879 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17880 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17881 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17882 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17883 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17884 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17885 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17886 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17887 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17888 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17889 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17890 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

php-fpm 17891 nginx??? 0u? IPv4 177862????? 0t0? TCP localhost.localdomain:cslistener (LISTEN)

#檢查服務的運行情況

8.7 整合PHP和Nginx

server {

??????? listen?????? 80;

??????? server_name? blog.etiantian.org;

??????? root?? /data0/www/blog;

??????? index? index.php index.html index.htm;

????

? location ~ .*\.(php|php5)?$?? #以php或者php5結尾的文件

???? {?????

?????? #fastcgi_pass? unix:/tmp/php-cgi.sock;

??????? fastcgi_pass? 127.0.0.1:9000;?? #交給本機的9000端口處理

??????? fastcgi_index index.php;??????? #首頁文件

??????? include fastcgi.conf;

???? }

}

?

8.8 安裝wordpress博客

1.建立博客數據庫(默認是拉丁字符集)

(1)創建數據庫

create database wordpress;

也可按下面方式創建庫:

建立一個名為wordpress的GBK數據庫

create database wordpress DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

?

(2)授權用戶

grant select,insert,delete,update,create on wordpress.* to wordpress@localhost identified by '19880328';

flush privileges;

?

  1. 如果是使用瀏覽器安裝,那么blog目錄需要對nginx用戶授權,即把把屬主和組改為nginx

chown nginx.nginx blog -R

?

  1. 編輯wp-config.php配置文件

只需要編輯該文件的數據庫名、數據庫用戶名、密碼即可。

特別注意的是在編輯wp-config.php文件的時候,應該是數據root用戶編輯的,要改為nginx.nginx。在瀏覽器端配置完標題用戶之后,blog整個目錄下的文件都可以改root權限,但是wp-config.php文件必須是nginx.nginx權限。

?

  1. 在瀏覽器端輸入blog.etiantian.com創建用戶
  2. 把blog目錄下的文件改為root.root(wp-config.php除外)
  3. 在數據庫中把創建數據庫的權限回收:

mysql> use wordpress;

Database changed

mysql> revoke create on wordpress.* from wordpress@'localhost';

Query OK, 0 rows affected (0.00 sec)

?

作業:對wordpress的博客使用偽靜態

轉載于:https://www.cnblogs.com/fengze/p/6751802.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/252839.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/252839.shtml
英文地址,請注明出處:http://en.pswp.cn/news/252839.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

jenkins 通過自動拉取Gitlab上的代碼實現自動更新NGINX

所需要用到的環境&#xff1a; Gitlab&#xff1a; 172.20.7.70Jenkins&#xff1a; 172.20.7.71nginx&#xff1a; 172.20.7.72 gitlab 和Jenkins安裝自行百度 開始實驗操作 首先通過網頁訪問nginx&#xff0c;nginx默認測試頁我是改了的 &#xff0c;所以看到的不是它原…

Kylin工作原理、體系架構

核心思想&#xff1a;預計算。 對多維分析可能用到的度量進行預計算&#xff0c;將計算好的結果保存成Cube&#xff0c;并存在HBase中&#xff0c;供查詢時直接訪問 將高復雜度的聚合運算、多表連接……操作轉換成對預計算結果的查詢。決定了Kylin擁有很好的快速查詢、高并發能…

工業相機圖像傳感器的靶面大小

在機器視覺中&#xff0c;工業相機是一種比較重要的配件。而在 工業相機中&#xff0c;圖像傳感器又是最最關鍵核心的東西。而圖像傳感器的靶面的大小&#xff0c;往往直接關系到成像的質量。通常來講&#xff0c;圖像的成像質量與像素的大小成正比。這也就意味著&#xff0c;同…

SpringMVC+Mybatis學習

簡單Web項目搭建&#xff1a; 一.流程 1. 導包 n個springMVC&#xff1b; 2個mybatis<其中一個是mybatis-spring>&#xff1b; 3個jackson包&#xff1b; 2. xml配置 web.xml和applicationContext.xml 3. 建包&#xff0c;建接口&#xff0c;建類 4. 建jsp 二&#xff1a…

PPT怎么在線轉視頻?

PPT在線轉視頻的方法有哪些&#xff1f;在PPT中有些播放上的問題還是可以進行文件的轉換&#xff0c;下面就給大家簡單的介紹一下方法。步驟一&#xff1a;PPT轉視頻的直接方法是進入迅捷PDF在線轉換器網站中&#xff0c;點擊導航欄中的視頻音頻轉換中的PPT轉視頻&#xff1b; …

At least one JPA metamodel must be present!

使用spring jpa是一直報這個錯&#xff0c;找了兩天網上沒有找到答案&#xff0c;最后發現時配置配錯了&#xff0c;如下&#xff1a; <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa<…

夜貓子”必需的!——融合夜視技術

融合夜視技術是一項正在發展中的前沿技術&#xff0c;通過將多個工作在不同波段的夜視傳感器獲得的圖像經過處理後生成高質量的融合圖像&#xff0c;融合圖像的分辨率更高&#xff0c;能夠揭示出那些很難被看到的特徵。按照融合的方式&#xff0c;融合夜視技術可以分為數字融合…

Vue中登錄模塊

轉載于:https://www.cnblogs.com/DZzzz/p/8921783.html

unity 中的UGUI 屏蔽鼠標穿透

void Update() { if(IsTouchedUI()) { Debug.Log("當前觸摸在UI上"); } else { Debug.Log("當前沒有觸摸在UI上"); } } void OnMouseDown() { if(IsTouchedUI()) { Debug.Log("當前觸摸在UI上"); } else { Debug.Log(&qu…

深度解析紅外探測器

輻射/設計/技術之前我們跟大家解析了紅外探測器的相關性能參數。 對于紅外探測器的工作原理你了解多少呢&#xff1f;今天小編再繼續上次的講解&#xff0c;為大家解析非制冷紅外焦平面探測器技術原理 及機芯介紹。 非制冷紅外技術原理 非制冷紅外探測器利用紅外輻射的熱效應&a…

js基礎總結性能優化

一.加載和執行1.推薦所有的script標簽盡可能放到body標簽的底部&#xff0c;以盡量減少對整體頁面下載速度的影響。2.組織腳本減少頁面包含的scirpt標簽數量&#xff0c;可以把多個文件合并成一個。3.無阻塞腳本1&#xff09;.延遲腳本defer:html解析完才加載&#xff0c;執行順…

Python2 Python3 爬取趕集網租房信息,帶源碼分析

*之前偶然看了某個騰訊公開課的視頻,寫的爬取趕集網的租房信息,這幾天突然想起來,于是自己分析了一下趕集網的信息,然后自己寫了一遍,寫完又用用Python3重寫了一遍.之中也遇見了少許的坑.記一下.算是一個總結.*python2 爬取趕集網租房信息與網站分析 分析目標網站url尋找目標標…

紅外熱成像技術原理

目前&#xff0c;新的熱成像儀主要采用非致冷焦平面陣列技術&#xff0c;集成數萬個乃至數十萬個信號放大器&#xff0c;將芯片置于光學系統的焦平面上&#xff0c;無須光機掃描系統而取得目標的全景圖像&#xff0c;從而大大提高了靈敏度和熱分辨率&#xff0c;并進一步地提高…

網站中公用頭部與尾部

一、html 1. <iframe src"1.html" frameborder"0"></iframe> 2. <embed src"1.html"/> 二、寫公用的js 文件&#xff0c;js中寫字divde符串&#xff0c;然后在需要的頁面適當位置引入公用的js. 三、ajax動態拉取填充 四、后端…

基于webpack的PC端和mobile端開發以及生產環境的搭建

我們用webpack做單頁面應用開發應該嘗試過很多次了&#xff0c;如果在同一個項目需要支持PC端和移動端&#xff0c;做成多頁面應用&#xff0c;開發時能根據請求的終端返回不同的內容&#xff0c;應該怎么做呢&#xff1f;以下描述的是我嘗試的一種方案&#xff0c;并且以vue-c…

深度學習簡介(一)——卷積神經網絡

本文的主要目的&#xff0c;是簡單介紹時下流行的深度學習算法的基礎知識&#xff0c;本人也看過許多其他教程&#xff0c;感覺其中大部分講的還是太過深奧&#xff0c;于是便有了寫一篇科普文的想法。博主也是現學現賣&#xff0c;文中如有不當之處&#xff0c;請各位指出&…

node+mongoose使用例子

https://github.com/Aquarius1993/nodeNotes 功能 1. 注冊 2. 登錄 3. 修改密碼 4. 修改頭像 5. 獲取用戶筆記 6. 添加&#xff0c;刪除,更新筆記安裝部署 1. 安裝 Node.js MongoDB 2. npm install 3. 啟動 MongoDB 4. npm start 5. visit http://localhost:8899 https://git…

FastJson的常用操作

轉載&#xff1a;https://www.cnblogs.com/Ming8006/p/6944954.html 常用操作包括以下內容&#xff1a; 對象與&#xff08;JsonObject或JsonArray&#xff09;與String的互換String轉換為&#xff08;JsonObject或JsonArray&#xff09;如何保持順序Eval的使用值為null的&…

Jenkins持續集成 之 Jenkins安裝

一、安裝JDK與TOMCAT8 參考地址&#xff1a; http://ibm.chick.blog.163.com/blog/static/144201610201652811537410/ 二、下載Jenkins安裝包 wget http://mirrors.jenkins.io/war/latest/jenkins.war 三、把jenkins.war放到TOMCAT下的webapps 四、啟動tomcat并訪問 http://10.…

夜視模式,多少猥瑣相機假汝之名

一般相機加裝一個紅外濾光片&#xff0c;就是一個可以用來干猥瑣事情的相機了。現在有相機直接把這個功能整合了&#xff0c;它的這個功能叫紅外夜視模式&#xff0c;可以拍下黑暗中的物體&#xff0c;當然&#xff0c;也可以透視紡織品和一些其他材質的衣物。這部相機具有500萬…