Centos lnmp 記要

tags:    時間:2013-12-27 23:56:53
Centos lnmp 記錄
Mysql
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.56.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.59.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz/from/http://ftp.jaist.ac.jp/pub/mysql/
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.62.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/

PHP
http://cn.php.net/get/php-5.3.6.tar.gz/from/this/mirror
http://www.php.net/get/php-5.3.8.tar.gz/from/cn2.php.net/mirror
http://www.php.net/get/php-5.3.10.tar.gz/from/cn.php.net/mirror
http://www.php.net/get/php-5.3.10.tar.gz/from/cn2.php.net/mirror

Zend Guard
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

Nginx
http://nginx.org/download/nginx-0.8.54.tar.gz
http://nginx.org/download/nginx-1.0.14.tar.gz

PHPMyadmin
http://soft.vpser.net/datebase/phpmyadmin/phpmyadmin.tar.gz

Pure-ftpd
http://soft.vpser.net/ftp/pure-ftpd/pure-ftpd-1.0.29.tar.gz
http://soft.vpser.net/ftp/pure-ftpd/User_manager_for-PureFTPd_v2.1_CN.zip

http://soft.vpser.net/lnmp/lnmp0.7.tar.gz


yum -y remove httpd
yum -y remove php
yum -y remove mysql-server mysql
yum -y remove php-mysql
yum -y install yum-fastestmirror
yum -y remove httpd

yum -y remove httpd php mysql-server mysql php-mysql 

備註:
如查yum 失敗,執行 yum clean all,修改DNS伺服器

yum -y install gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg* libpng* gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel gmp-devel pspell-devel unzip libxslt libxslt-devel db4-devel mcrypt mcrypt-devel libmcrypt libmcrypt-devel mhash mhash-devel pcre pcre-devel libpcre libpcre-devel libc-client*;
# mysql
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
useradd -s /sbin/nologin mysql
cp support-files/my-medium.cnf /etc/my.cnf
#mkdir -p /var/lib/mysql/
chown mysql.mysql -R /usr/local/mysql
#chown mysql.mysql -R /var/lib/mysql/
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 700 /etc/init.d/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql
#ln -s /usr/local/mysql/bin/* /usr/local/bin
重要:
#ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
#ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/include/mysql/mysql.h /usr/lib
讓其它程序能找到mysql庫
ln -s /usr/local/mysql/lib/mysql/* /usr/lib
將mysql命令作為系統命令
#ls -s /usr/local/mysql/bin/* /usr/bin
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/

#ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/
#ln -s /usr/local/mysql/bin/mysql_conf /usr/bin/
#ln -s /usr/local/mysql/share/mysql/mysql.server /usr/bin/
64位系統還要執行
ln -s /usr/local/mysql/include/mysql/mysql.h /usr/lib64
ln -s /usr/local/mysql/lib/mysql/* /usr/lib64

作為系統開機服務啟動
chkconfig --level 345 mysql on

/etc/init.d/mysql start
/usr/local/mysql/bin/mysqladmin -u root password 123456

系統找不到mysql.sock
如mysql.sock在 /var/lib/mysql/mysql.sock
ln -s /var/lib/mysql/mysql.sock  /tmp/mysql.sock
如mysql.sock在 /tmp/mysql.sock
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

參數配置:
mkdir -p /usr/local/mysql/pid
vim /etc/my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
pid-file        = /usr/local/mysql/pid/mysql.pid
log             = /usr/local/mysql/pid/mysql.err
datadir         = /usr/local/mysql/var
skip-locking
#key_buffer_size = 16M
#max_allowed_packet = 1M
table_open_cache = 64
#sort_buffer_size = 512K
#net_buffer_length = 8K
#read_buffer_size = 256K
#read_rnd_buffer_size = 512K
#myisam_sort_buffer_size = 8M
key_buffer_size = 128M
max_allowed_packet = 10M
sort_buffer_size = 6M
net_buffer_length = 10M
read_buffer_size = 5M
read_rnd_buffer_size = 10M
myisam_sort_buffer_size = 768M
wait_timeout = 100
interactive_timeout = 100

innodb_file_per_table=1


# php-5.3.x
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-zip --with-imap --with-imap-ssl --with-kerberos --enable-zend-multibyte

cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
useradd -s /sbin/nologin www
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 700 /etc/init.d/php-fpm
編輯/usr/local/php/etc/php-fpm.conf,去掉以下內容中前面的#注視符即可
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice
[www]
listen = 127.0.0.1:9000
user = www
group = www
pm = dynamic
pm.max_children = 50   #此參數是pm=static才有效,永久線程數
pm.start_servers = 20   #此參數是pm=dynamic有效,啟動時的線程數
pm.min_spare_servers = 5   #此參數是pm=dynamic有效,允許最小的線程數
pm.max_spare_servers = 50  #此參數是pm=dynamic有效,允許最大的線程數

# Zend Guard
tar -zxvf ZendGuard.tar.gz
mkdir /usr/local/zendguard
cd ZendGuardLoader-php-5.3-linux-glibc23-x86_64
cp php-5.3.x/ZendGuardLoader.so /usr/local/zendguard

vim /usr/local/php/etc/php.ini
複製下面內容到php.ini底部
[Zend Guard]
zend_extension=/usr/local/zendguard/ZendGuardLoader.so
zend_loader.enable = 1
zend_loader.disable_licensing = 0
zend_loader.obfuscation_level_support = 3
zend_loader.license_path=

測試:
/usr/local/php/bin/php -v
看到 with Zend Guard Loader 即正常

# nginx 字元替換 substitutions_filter
yum -y install subversion
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ /root/software/substitutions4nginx-read-only

# nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=/root/software/substitutions4nginx-read-only

make install

/************************************
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/var/nginx.pid --lock-path=/usr/local/nginx/var/nginx.lock --without-select_module --without-poll_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_geo_module --without-http_memcached_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-pcre=/usr/local/src/pcre-8.12
*************************************/

mkdir /usr/local/nginx/conf/vhost
mkdir /usr/local/nginx/conf/proxy
mkdir /var/log/nginx

vim /usr/local/nginx/conf/nginx.conf
user www
在http里加上:
log_format logstring '$remote_addr - $remote_user [$time_local]  '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" "$gzip_ratio"';
在http 內的最後加上
include vhost/*.conf;
include proxy/*.conf;

#pureftpd
./configure --prefix=/usr/local/pureftpd CFLAGS=-O2 \
--with-mysql=/usr/local/mysql \
--with-quotas \
--with-cookie \
--with-virtualhosts \
--with-virtualroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-altlog \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg  \
--with-throttling \
--with-uploadscript \
--with-language=simplified-chinese

cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin/
chmod 700 /usr/local/pureftpd/sbin/pure-config.pl
cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/
cp pureftpd-mysql.conf /usr/local/pureftpd/

vim /usr/local/pureftpd/pure-ftpd.conf
去掉前面註釋,修改後面的路徑
MySQLConfigFile                /usr/local/pureftpd/pureftpd-mysql.conf
AllowUserFXP yes   #僅運行用戶進行FXP傳輸,設置yes,伺服器之間對傳。
NoAnonymous                 yes #關閉匿名鏈接
最後面加上
AllowOverwrite on
AllowStoreRestart on

vim /usr/local/pureftpd/pureftpd-mysql.conf
修改資料庫連接帳號
修改成md5
MYSQLCrypt     md5

vim /etc/init.d/pureftpd
chmod 700 /etc/init.d/pureftpd
########################################
#!/bin/bash
#
# chkconfig: 2345 85 15
# description: Pure-FTPd is an FTP server daemon based upon Troll-FTPd
# processname: pure-ftpd
### BEGIN INIT INFO
# Provides:          pureftpd
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts pureftpd server
# Description:       starts pureftpd server
### END INIT INFO
# Author:   licess
# website:  http://lnmp.org
# Pure-FTPd Settings
PURE_PERL="/usr/local/pureftpd/sbin/pure-config.pl"
PURE_CONF="/usr/local/pureftpd/pure-ftpd.conf"
PURE_PID="/var/run/pure-ftpd.pid"
RETVAL=0
prog="Pure-FTPd"
start() {
        echo -n $"Starting $prog: "
        $PURE_PERL $PURE_CONF --daemonize
        RETVAL=$?
        echo
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        if [ -e $PURE_PID ]; then
                kill `cat $PURE_PID`
        else
                echo -n $"$prog is not running."
        fi
        RETVAL=$?
        echo
        return $RETVAL
}
restart(){
        echo -n $"Restarting $prog: "
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  *)
        echo $"Usage: pureftpd {start|stop|restart}"
        RETVAL=1
esac
exit $RETVA
########################################

執行:
chmod 700 /etc/init.d/pureftpd

pureftpd 的 PHP 管理端要開啟 short_open_tag = on

wget -c http://soft.vpser.net/ftp/pure-ftpd/pure-ftpd-1.0.29.tar.gz
wget -c http://soft.vpser.net/ftp/pure-ftpd/User_manager_for-PureFTPd_v2.1_CN.zip

#開機啟動
vim /etc/rc.local
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini &
/etc/init.d/mysql start
/usr/local/nginx/sbin/nginx
#/root/pureftpd start
/etc/init.d/pureftpd start
#/etc/init.d/vsftpd start

vim /usr/local/php/etc/php.ini
expose_php = Off

nginx無法運行php-cgi的問題
fastcgi.conf或fastcgi_params里加一句:
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

PHP $_SERVER["SERVER_NAME"] 只獲得nginx的第一個域名解決方法:
在 fastcgi_params最後加一句:
fastcgi_param  SERVER_NAME    $host;

   sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    gzip_min_length  1000;
#    gzip_buffers     4 8k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types       text/plain text/htm text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_vary on;
server_tokens off;
fastcgi_connect_timeout 1800;
fastcgi_send_timeout 1800;
fastcgi_read_timeout 1800;
fastcgi_buffer_size 5120k;#256
fastcgi_buffers 16 5120k;
fastcgi_busy_buffers_size 10240k;
fastcgi_temp_file_write_size 10240k;
fastcgi_intercept_errors on;

server  {
                listen       80;
                server_name domain.name;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /var/www/path;

# location / {
# deny 192.168.1.1;
# allow 183.16.193.255;
# allow 183.16.61.43;
# allow 58.61.39.9;
# deny all;
# }
                location ~ .*\.(php|php5)?$ {
                        include fastcgi_params;
                        fastcgi_pass  127.0.0.1:9000;
                        fastcgi_index index.php;
                }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
                        expires      30d;
                }
                location ~ .*\.(js|css)?$ {
                        expires      12h;
                }
                access_log  /var/log/nginx/domain.access.log  logstring;
                error_log  /var/log/nginx/domain.error.log;
        }



PHP插件安裝

ftp://ftp.kddlabs.co.jp/graphics/ImageMagick/ImageMagick-6.6.9-10.tar.gz
http://pecl.php.net/get/imagick-3.0.1.tgz

安裝ImageMagick
./configure --prefix=/usr/local/imagemagick
make && make install

安裝imagick
cd imagick-xxx目錄
運行 /usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
make && make install

或者 yum -y install ImageMagick ImageMagick-devel
安裝imagick
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config

編輯 /usr/local/php/etc/php.ini
添加 extension=imagick.so

安裝 OpenCV 和 php-facedetect
http://sourceforge.net/projects/opencvlibrary/
http://www.xarg.org/project/php-facedetect/
https://github.com/infusion/PHP-Facedetect
先安裝cmake,OpenCV要用到
yum install cmake

註:若不是centos 6.0,必須得下載 opencv-2.2.0版本,否則安裝不上去
yum -y install gtk2 gtk2-devel
yum -y install gstreamer gstreamer-devel
yum -y install gstreamer-plugins-base gstreamer-plugins-base-devel
yum -y install gstreamer-plugins-good gstreamer-plugins-good-devel
yum -y install libtiff libtiff-devel

cd OpenCV-2.2.0/ 
mkdir opencv-build
cd opencv-build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
make && make intall
http://rpm.pbone.net/index.php3/stat/4/idpl/16612327/dir/centos_6/com/gstreamer-plugins-base-devel-0.10.29-1.el6.i686.rpm.html
http://rpmfind.net/linux/rpm2html/search.php?query=opencv

安裝PHP-Facedetect
cd infusion-PHP-Facedetect-75a1d8f
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
編輯 /usr/local/php/etc/php.ini
添加 extension=facedetect.so


substitutions4nginx參數:
例如:subs_filter 源字元 目標字元 [gior]
g(default):替換所有匹配的字元串。
i: 執行不區分大小寫的匹配。
o: 只需將第一個。
r: 該模式是作為一個正則表達式處理,默認是固定的字元串。
實際使用:
subs_filter 『<(no?script.*?)>(.*?)<(\/no?script.*?)>』 」 gi; //替換掉全部的<noscript></noscript>
subs_filter 『<(s?cript.*?)>(?:\s|\S)*?<(\/s?cript.*?)>』 」 gi; //替換掉全部的<script>包換中間換行</script>
subs_filter 『<(i?frame.*?)>(.*?)<(\/i?frame.*?)>』 」 gi; //替換<iframe></iframe>
使用範例:
location / {
    subs_filter_types text/html text/css text/xml; #替換的文件類型
    subs_filter st(\d*).example.com $1.example.com ir; #
    subs_filter a.example.com s.example.com;
}
實際測試中sub_filter比subs_filter的速度要快,但如果你開啟了nginx的cache速度上可以得到改善的。
測試過程發現對gzip源的內容無法實現替換的問題
可以在server段內加入 proxy_set_header Accept-Encoding "";
如果是替換中文片語則需要將nginx的配置文件保存為utf-8格式!

推薦閱讀文章

Bookmark the permalink ,來源:互聯網