本文共 10778 字,大约阅读时间需要 35 分钟。
linux nginx php fastcgi fpm 编译安装
软件列表
eaccelerator-0.9.6.1.tar.bz2 fontconfig-2.6.0.tar.gz freetype-2.3.7.tar.gz gd-2.0.33.tar.gz gettext-0.17.tar.gz jpegsrc.v6b.tar.gz libevent-1.4.14b-stable.tar.gz libmcrypt-2.5.6.tar.gz libpng-1.2.35.tar.gz libxml2-2.6.30.tar.gz mcrypt-2.6.4.tar.gz memcache-2.2.5.tgz memcached-1.4.5.tar.gz mhash-0.9.8.tar.gz mysql-5.1.32.tar.gz nginx-0.8.43.tar.gz pcre-8.10.zip PDO_MYSQL-1.0.2.tgz php-5.2.6-fpm-0.5.9.diff.gz php-5.2.6.tar.gz ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz zlib-1.2.3.tar.gz##############################################install##################################################
tar zxvf libmcrypt-2.5.6.tar.gz
cd libmcrypt-2.5.6/ ./configure make make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make make install cd ../../tar zxvf mhash-0.9.8tar.gz
cd mhash-0.9.8/ ./configure make make install cd ../ echo "/usr/local/lib/" >> /etc/ld.so.conf /sbin/ldconfig 安装mcrypt的时候需要mhash和libmcrypt的lib库,所以在这里共享一下tar zxvf mcrypt-2.6.4.tar.gz
cd mcrypt-2.6.4/ /sbin/ldconfig ./configure make make install cd ../groupadd mysql //创建组
useradd -g mysql -s /sbin/nologin -M mysql //新建用户并添加到mysql组中,拒绝作为本地用户登陆shell tar zxf mysql-5.1.32.tar.gz cd mysql-5.1.32 ./configure --prefix=/app/mysql --with-charset=utf8 --with-extra-charsets=all --with-tcp-port=3306 --with-plugins=all --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-user=mysql --enable-local-infile --with-big-tables --prefix=/app/mysql //mysql的安装路径 --with-charset=utf8 //数据库字符集使用utf-8 --with-extra-charsets=all //支持多言语 --with-tcp-port=3306 //mysql的通讯端口 --with-plugins=all //添加所有数据引擎的支持 --with-unix-socket-path=/tmp/mysql.sock //mysql的套接字路径 --with-mysqld-user=mysql //指定数据用户为mysql --enable-local-infile //启用数据库的本地负载信息 --with-big-tables //支持4G的表 make make install cp mysql-5.1.30/support-files/my-medium.cnf /etc/my.cnf //拷贝mysql的模板配置文件 /app/mysql/bin/mysql_install_db --user=mysql //使用mysql用户初始化mysql数据库 cd /app/mysql chown -R root . //更改mysql目录下所有目录的属主为root用户 chgrp -R mysql . //更改mysql目录下所有目录的属组为mysql用户 cd /app/mysql/var chown -R mysql.mysql . //更改mysql数据库文件夹的属主和属组为mysql用户 cp /app/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld //复制mysql的启动脚本文件到init下面 chkconfig --add mysqld //添加mysqld为系统服务 chkconfig --level 3 mysqld on //配置mysqld在系统的运行级别3下开机自动启动 service mysqld start //启动mysql服务 mysqladmin -u root password 'newpassword' //设置mysql数据库root的密码###############php的支持库#################
tar -zxf jpegsrc.v6b.tar.gz
cd jpeg-6b mkdir /app/jpeg6 mkdir /app/jpeg6/bin mkdir /app/jpeg6/lib mkdir /app/jpeg6/include mkdir /app/jpeg6/man mkdir /app/jpeg6/man/man164位的系统需要拷贝两个文件
在jpeg6的源码目录下操作
tar -zxf libpng-1.2.33.tar.gz
cd libpng-1.2.33 ./configure --prefix=/app/libpng make make installtar -zxf freetype-2.3.5.tar.gz
cd freetype-2.3.5 ./configure --prefix=/app/freetype make make installtar -zxf fontconfig-2.6.0.tar.gz
cd fontconfig-2.6.0 ./configure--prefix=/app/fontconfig--enable-libxml2--with-freetype-config=/app/freetype/bin/freetype-config Make Make installtar -zxf gd-2.0.33.tar.gz
cd gd-2.0.33 ./configure --prefix=/app/gd2 --with-png=/app/libpng/ --with-freetype=/app/freetype/ --with-fontconfig=/app/fontconfig/ --with-jpeg=/app/jpeg6/ ** Configuration summary for gd 2.0.33: Support for PNG library: yes Support for JPEG library: yes Support for Freetype 2.x library: yes Support for Fontconfig library: yes Support for Xpm library: no Support for pthreads: yes vi gd_png.c 修改#include "png.h" 成#include "/app/libpng/include/png.h" linpng的绝对路径 Make Make installtar -zxf zlib-1.2.3.tar.gz
cd zlib-1.2.364位的系统需要以下方法编译
CFLAGS="-O3 -fPIC" ./configure //使用64位元的方法进行编译
32位的
./configure --prefix=/app/zlib Make Make installtar -zxf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30 ./configure --prefix=/app/libxml --with-zlib=/app/zlib/ Make Make installtar -zxf gettext-0.17.tar.gz
cd gettext-0.17 ./configure --prefix=/app/gettext --with-libxml2-prefix=/app/libxml/ Make Make installtar zxf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1 //给php打上fpm的补丁,补丁程序下载的时候最好能和php的版本对应上,fpm是php的fastcgi的管理工具 cd php-5.2.6 ./configure --prefix=/app/php --with-config-file-path=/etc/ --with-mysql=/app/mysql/ --with-gd=/app/gd2/ --with-libxml-dir=/app/libxml/include/libxml2/libxml/ --with-gettext=/app/gettext/ --with-freetype-dir=/app/freetype/ --with-zlib-dir=/app/zlib --with-jpeg-dir=/app/jpeg6/ --with-png-dir=/app/libpng/ --with-mysql-sock=/tmp/mysql.sock --enable-zend-multibyte --enable-mbstring --enable-sockets --enable-ftp --with-bz2 --enable-soap --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --with-mcrypt --with-mhash cp php.ini-dist /etc/php.initar zxf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable ./configure --prefix=/app/libevent make make installtar zxf memcached-1.4.5.tar.gz
cd memcached-1.4.5 ./configure --prefix=/app/memcached --with-libevent=/app/libevent/ make make install /app/memcached/bin/memcached -d -m 128 -u root -l 172.16.6.165 -p 1111 -c 256 -P /tmp/memcached.pid -d选项是启动一个守护进程, -m是分配给Memcache使用的内存数量,单位是MB,我这里是128MB, -u是运行Memcache的用户,我这里是root, -l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.1.9, -p是设置Memcache监听的端口,我这里设置了1111,最好是1024以上的端口, -c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定, -P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5 /app/php/bin/phpize ./configure --with-php-config=/app/php/bin/php-config make make test make installtar jxf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1 /app/php/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/app/php/bin/php-config make make installtar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2 /app/php/bin/phpize ./configure --with-php-config=/app/php/bin/php-config --with-pdo-mysql=/app/mysql/ make make install groupadd www useradd -g www -s /sbin/nologin www chown -R /opt/www/unzip pcre-8.10.zip
cd pcre-8.10 ./configure --prefix=/app/pcre --enable-utf8 make make installtar zxf nginx-0.8.43.tar.gz
cd nginx-0.8.43 ./configure --prefix=/app/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=/back/pcre-8.10 安装nginx的时候注意一下pcre的路径是解压的目录而不是安装目录别搞错了,如果你不加--with-pcre的参数,默认会找到系统自带的pcre make make install#####################################################configure############################################
修改php.ini文件
手工修改:查找/etc/php.ini中的extension_dir = "./" 修改为extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/" 并在此行后增加以下几行,然后保存: extension = "memcache.so" extension = "pdo_mysql.so" 再查找output_buffering = Off 修改为output_buffering = On 再查找; cgi.fix_pathinfo=0 修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。 [eaccelerator] zend_extension="/app/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="30" #这个值对应系统的/proc/sys/kernel/shmmax 文件,是允许使用的共享内存总量,该文件表示内核所允许的最大共享内存段的大小(bytes)。 #缺省设置:33554432 #建议设置:物理内存 * 50% eaccelerator.cache_dir="/app/php/eaccelerator_cache" 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"vi /app/php/etc/php-fpm.conf修改fpm的配置文件
<value name="listen_address">127.0.0.1:9000</value> 这行是fpm的监听地址和端口 <value name="display_errors">0</value> 显示错误信息 <value name="user">www</value> 启动fpm的用户 <value name="group">www</value> 启动fpm的组 <value name="max_children">10</value> 启动的fast-cgi进程数vi /app/nginx/conf/nginx.conf
user www www; worker_processes 4; error_log /var/log/nginx_error.log crit; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; server { listen 80; server_name 172.16.6.165; index index.php; root /opt/www; #limit_conn crawler 20; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /var/log/access.log access; } }vi /app/nginx/conf/fcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200;/app/nginx/sbin/nginx -t 测试nginx的配置是否有问题
/app/nginx/sbin/nginx 启动nginx服务 /app/php/sbin/php-fpm start 启动fpmvi /etc/sysctl.conf
添加以下内容,作为系统的优化参数 net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 2 net.ipv4.tcp_tw_recycle = 1 #net.ipv4.tcp_tw_len = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800 #net.ipv4.tcp_fin_timeout = 30 #net.ipv4.tcp_keepalive_time = 120 net.ipv4.ip_local_port_range = 1024 65535 sysctl -p 配置文件立即生效