搭建基于Linux6,5系统下安装配置Nginx

2019-11-08 19:56 来源:未知

之前的Web服务器都是通过yum搭建的,想要添加新模块或者更新某些软件都很不方便(牵一发而动全身啊!)。所以,现在准备将环境改为源码编译安装,这样便于调整,性能上也会比yum方式好很多。以下是我的安装步骤,我的系统是CentOS 6.3 64位。

此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP。

LNMP最新源码安装脚本(定期更新)

  1. 修改 SSH 连接显示字符集 (可以忽略这一步,偶尔出现乱码影响也不大的)

注意:本文所以配置都是基于第二步所下载的软件版本,安装其他版本不保证会成功

本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件。大家安装完可以删除该目录。

 

# vi /etc/profile

推荐阅读:

使用方法:

Linux Nginx MySQL PHP Pureftpd User manager for PureFTPd,脚本中用到的软件包大多最新版本,修复了User manager for PureFTPd一些安全性问题,不建议使用phpMyAdmin,如需使用可以将解压包放到/data/admin目录下。

添加:

生产环境实用之LNMP架构的编译安装 SSL加密实现 http://www.linuxidc.com/Linux/2013-05/85099.htm

1、把shell脚本的内容保存为nginx_php

 

LANG=zh_CN.GB2312

LNMP 全功能编译安装 for CentOS 6.3笔记 http://www.linuxidc.com/Linux/2013-05/83788.htm

2、root权限下运行:

又见LNMP有木有?如有错误请各位大虾们及时告之

export LANG

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm

复制代码 代码如下:

 

使环境变量生效 保存后 断开 SSH 重新连接 

在部署LNMP的时候遇到Nginx启动失败的2个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

chmod u x nginx_php; ./nginx_php init; ./nginx_php ins_mysql-server; ./nginx_php ins_mysql-client; ./nginx_php ins_php52; ./nginx_php ins_php52-ext; ./nginx_php ins_mysql

LNMP已经放到github(定期更新)上,地址:

# source /etc/profile 

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm

在脚本运行过程中需要输入一次y确认。

 

注意:

一:安装依赖包

Shell脚本内容如下:

脚本中软件版本如下:

如果有添加这一步,在设置 mysql 密码时会出现个 sql 编码问题,需要注释掉这里的设置断开ssh后重连就可以了

yum install cmake make gcc gcc-c libjpeg libjpeg-devel libpng
libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc
glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl
curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl expat expat-devel
openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers unixODBC-devel
libxslt-devel libevent-devel libtool-ltdl bison libtool pcre-devel zip unzip gmp-devel gd gd-devel

复制代码 代码如下:

01

  1. 设置时区

二:下载LNMP所需软件

#/bash
# author:coralzd powered by www.freebsdsystem.org
# written by coralzd 2011.05.05
# version 0.1.3 build 20110505
nginx_dir="/usr/local/nginx"
php52_dir="/usr/local/php52"
mysql_dir="/usr/local/mysql"

cmake-2.8.10.2.tar.gz

# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget

function init()
{

02

同步时间

三、安装mysql

LANG=C
yum -y install wget gcc gcc-c autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

mysql-5.5.32.tar.gz

# /usr/bin/rdate -s rdate.darkorb.net

tar zxf mysql-5.5.19.tar.gz
cd mysql-5.5.19
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DSYSCONFDIR=/etc/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock
-DWITH_READLINE=1
-DWITH_EMBEDDED_SERVER=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
make && make install
chown -R mysql.mysql /usr/local/mysql
cd ..

read -p "Now,will download nginxphp software...Y|y:" nginxphp

03

写入 BIOS 避免失效

因为有专门的mysql服务器,所以mysql安装到此结束。如果想要在本地运行mysql的话还要做其他配置。比如my.cnf配置文件,mysql启动脚本等等。

case "$nginxphp" in

libiconv-1.14.tar.gz

# hwclock -w

四:安装PHP
安装PHP(FastCGI)
### 安装PHP支持库 ###
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make
make install
cd ..
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
cd ../../
tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make
make install
cd ../
tar zxf re2c-0.13.5.tar.gz
cd re2c-0.13.5
./configure
make && make install
cd ..

Y|y)

04

建议加入定时同步

在安装PHP主程序前,还需要做一些调整,不然会各种报错。

echo -n "starting download nginx_php ..."
cat > list << "EOF" &&
nginx-1.0.0.tar.gz
php-5.2.17.tar.gz
php-5.2.17-fpm-0.5.14.diff.gz
libiconv-1.13.1.tar.gz
libmcrypt-2.5.8.tar.gz
mcrypt-2.6.8.tar.gz
memcache-2.2.5.tgz
mhash-0.9.9.9.tar.gz
mysql-5.1.52.tar.gz
pcre-8.10.tar.gz
eaccelerator-0.9.6.1.tar.bz2
PDO_MYSQL-1.0.2.tgz
libunwind-0.99.tar.gz
ImageMagick.tar.gz
imagick-2.3.0.tgz
google-perftools-1.6.tar.gz
fcgi.conf
php.ini
nginx.conf
php-fpm.conf
EOF
mkdir packages
for i in `cat list`
do
if [ -s packages/$i ]; then
echo "$i [found]"
else
echo "Error: $i not found!!!download now......"
wget -P packages/
fi
done
;;

libmcrypt-2.5.8.tar.gz

# crontab -e

echo "/usr/local/lib"  > /etc/ld.so.conf.d/local.conf
echo "/usr/lib64" >> /etc/ld.so.conf.d/local.conf
ln -sv /usr/lib64/libldap* /usr/lib/
ln -sv /usr/include/sqlext.h /usr/local/include/sqlext.h
ln -sv /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
ln -sv  /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
ln -sv /lib64/libexpat.* /lib/
ln -sv /usr/lib64/libexpat.* /usr/lib/
ldconfig

*)

05

# 0 0 * * * /usr/bin/rdate -s rdate.darkorb.net

现在安装PHP

echo -n "exit install script"
exit 0
;;

mhash-0.9.9.9.tar.gz

  1. 配置服务器 yum 国内更新源地址

tar jxf php-5.3.18.tar.bz2
cd php-5.3.18
groupadd nginx
useradd -M -s /sbin/nologin -g nginx nginx
./configure
--prefix=/usr/local/php --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d
--with-pic --with-bz2 --with-gettext --with-gmp --with-iconv --with-openssl
--with-zlib --with-layout=GNU --with-kerberos --with-mhash --with-pcre-regex --enable-exif
--enable-magic-quotes --enable-sockets  --enable-ucd-snmp-hack --enable-shmop --enable-calendar
--enable-mbstring
--enable-xml --enable-fpm --enable-gd-native-ttf --enable-exif --enable-soap --with-gd --with-curl
--with-mcrypt
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql
--with-unixODBC
--enable-wddx --with-libexpat-dir --with-xmlrpc --with-xsl --with-ldap --enable-bcmath
--enable-dom --without-gdbm --disable-debug --disable-rpath --disable-fileinfo --without-pspell
--disable-posix --disable-sysvmsg --disable-sysvshm --disable-sysvsem
make ZEND_EXTRA_LIBS='-liconv'
make install

esac

06

# cd /etc/yum.repos.d

拷贝配置文件及启动脚本

groupadd www && useradd www -s /sbin/nologin -g www
groupadd mysql && useradd mysql -s /sbin/nologin -g mysql
echo "www and mysql user && group create!"

mcrypt-2.6.8.tar.gz

# mv CentOS-Base.repo CentOS-Base.repo.bak

cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd ../

/bin/rm -rf list

07

# wget

安装PHP扩展模块,别忘记在配置文件里开启模块,不然就白装了哈
### 安装扩展模块 ###
tar zxf memcache-2.2.7.tgz
cd memcache-2.2.7/
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar jxf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
mkdir /tmp/cache/eaccelerator
chmod 0777 /tmp/cache/eaccelerator
cd ../
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../
tar zxf igbinary-1.1.1.tgz
cd igbinary-1.1.1
/usr/local/php/bin/phpize
./configure --enable-igbinary --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
unzip master
cd phpredis-master
/usr/local/php/bin/phpize
./configure --enable-redis --enable-redis-igbinary --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ..
tar zxvf ImageMagick-6.8.3-10.tar.gz
cd ImageMagick-6.8.3-10/
./configure
make
make install
cd ../
tar zxvf imagick-3.0.1.tgz
cd imagick-3.0.1/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
make install
cd ../

echo -e "All of installed sucussful!"
}
function is_version()

php-5.3.26.tar.gz

# yum makecache

到此PHP环境配置完毕,接下来安装大名鼎鼎的Nginx。它的好咱就不说了,大家都知道哈。

{
if [ `uname -m` == "x86_64" ];then
tar zxf libunwind-0.99.tar.gz
tar zxvf libunwind-0.99.tar.gz
cd libunwind-0.99/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
cd ../
else

08

  1. 更新软件和安装依赖包

图片 1

echo "your system is 32bit ,not install libunwind lib!"
fi
}

memcache-2.2.5.tgz

# sudo -s

function ins_nginx()

09

# LANG=C

{

eaccelerator-0.9.6.1.tar.bz2

# yum -y install gcc gcc-c autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers ntpd nmap patch cmake bison cgi* *-gd-* libtool-* gettext *libxml-devel libcurl-devel libevent libevent-devel net-snmp-devel lsof unzip

cd packages

10

如果出现错误 如:Error: Package: glibc-headers-2.12-1.80.el6_3.4.x86_64 (updates)

is_version
tar zxf google-perftools-1.6.tar.gz
cd google-perftools-1.6
./configure
make
make install

PDO_MYSQL-1.0.2.tgz

查看

cd ..
tar zxf pcre-8.10.tar.gz
cd pcre-*
./configure
make
make install
cd ..
tar zxf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure --prefix=${nginx_dir} --with-google_perftools_module --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module

11

  1. 设置路径

make && make install
cd ..
rm -rf /usr/local/nginx/conf/nginx.conf
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
cp nginx.conf /usr/local/nginx/conf/
cp fcgi.conf /usr/local/nginx/conf/
echo "nginx installed sucussfully!"

ImageMagick-6.8.3-10.tar.gz

# vi /etc/ld.so.conf

}
function ins_mysql-server()
{

12

添加:

cd packages/
tar zxf mysql-5.1.52.tar.gz
cd mysql-5.1.52
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure "--prefix=${mysql_dir}" "--with-server-suffix=-DZWWW" "--with-mysqld-user=mysql" "--without-debug" "--with-charset=utf8" "--with-extra-charsets=all" "--with-pthread" "--with-big-tables" "--enable-thread-safe-client" "--enable-assembler" "--with-readline" "--with-ssl" "--enable-local-infile" "--with-plugins=partition,myisammrg" "--without-ndb-debug"

imagick-3.0.1.tgz

/usr/lib/

make && make install
cp support-*/mysql.server /etc/init.d/mysqld
cd /usr/local/mysql
chown -R mysql:mysql .
rm -rf sql-bench mysql-test
echo "mysql server 5.1.52 installed successfully!"
}
function ins_mysql-client()
{

13

/usr/local/lib/

cd packages/
tar zxf mysql-5.1.52.tar.gz
cd mysql-5.1.52
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure "--prefix=${mysql_dir}" "--with-mysqld-user=mysql" "--without-debug" "--with-charset=utf8" "--with-extra-charsets=all" "--with-pthread" "--with-big-tables" "--enable-thread-safe-client" "--enable-assembler" "--with-readline" "--with-ssl" "--enable-local-infile" "--without-server"

pecl_http-1.7.5.tgz

/usr/lib64/

make && make install
cd /usr/local/mysql
chown -R mysql:mysql .
rm -rf sql-bench mysql-test
echo "mysql client 5.1.52 installed successfully!"
}
function ins_php52()
{
cd packages/
tar zxf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../

14

/usr/local/lib64/

tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

pcre-8.32.tar.gz

  1. 最好重启一次

tar zxf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

15

# reboot

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

nginx-1.4.1.tar.gz

  1. 开始安装 nginx

tar zxf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
tar zxf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/
./configure --prefix=${php52_dir} --with-config-file-path=${php52_dir}/etc --with-mysql=${mysql_dir} --with-mysqli=${mysql_dir}/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --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 --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
make ZEND_EXTRA_LIBS='-liconv'
make install
cd ..
cp php.ini /usr/local/php52/etc/
cp php-fpm.conf /usr/local/php52/etc/

16

新建保存下载软件的目录

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf
/sbin/ldconfig
echo "php52 installed successfully!"
}

pure-ftpd-1.0.36.tar.gz

# mkdir -p /mydata/soft

function ins_php52-ext()

17

# mkdir -p /var/www/html

{
cd packages/

ftp_v2.1.tar.gz

# cd /mydata/soft/

tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5/
${php52_dir}/bin/phpize
./configure --with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../

使用方法:

下载:

tar jxf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
${php52_dir}/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../

 

# wget

tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
${php52_dir}/bin/phpize
./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}
make
make install
cd ../

1

# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz

tar zxf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../

wget

# wget

tar zxf imagick-2.3.0.tgz
cd imagick-2.3.0/
${php52_dir}/bin/phpize
./configure --with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../
echo "php52 extension installed successfully!"
}

2

# wget

case $1 in
init)

chmod x lnmp_install.sh

7.1 利用 TCMalloc 优化 nginx 性能

init
;;
ins_mysql-server)

3

针对 64 位操作系统必须安装 libunwind 库

ins_mysql-server

lnmp_install.sh

# tar zxvf libunwind-1.1.tar.gz

;;
ins_mysql-client)
ins_mysql-client
;;
ins_nginx)
ins_nginx
;;
ins_php52)
ins_php52
;;
ins_php52-ext)
ins_php52-ext
;;
*)
echo "Usage:`basename $0` {init|ins_mysql-server|ins_mysql-client|ins_php52|ins_php52-ext|ins_mysql}"
;;
esac

说明: 

# cd libunwind-1.1/

您可能感兴趣的文章:

  • 腾讯云主机安装LNMP环境及wordpress教程
  • lnmp环境中如何为nginx开启pathinfo
  • VPS中使用LNMP安装WordPress教程
  • CentOS6.5 编译安装lnmp环境
  • Zabbix安装图文教程(需要LAMP或者LNMP运行环境)
  • LNMP服务器环境配置 (linux nginx mysql php)
  • 阿里云主机一键安装lamp、lnmp环境的shell脚本分享
  • VPS CentOS-6 下 LNMP HTTP web服务器的搭建步骤
  • LNMP 解决Access Denied错误详细介绍

本人在 CentOS 6.x 32/64bit( Linode)上测试通过,并且在线上使用这个脚本。 

# CFLAGS=-fPIC ./configure

脚本内容

# make CFLAGS=-fPIC

 

# make CFLAGS=-fPIC install

 

# cd ../

001

安装 google-perftools 优化

#!/bin/bash

# tar zxvf gperftools-2.0.tar.gz

002

# cd gperftools-2.0/

# Check if user is root

# ./configure

003

# make && make install

[ $(id -u) != "0" ] && echo "Error: You must be root to run this script, please use root to install lnmp" && exit 1

# echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

004

# /sbin/ldconfig

 

# cd ..

005

7.2 安装 pcre 使 nginx 支持 URL 重写

echo "#######################################################################"

# tar zxvf pcre-8.31.tar.gz  

006

# cd pcre-8.31

echo "#                    LNMP for CentOS/RadHat Linux                     #"

# ./configure

007

# make && make install

echo "# For more information please visit #"

# cd ../

008

7.3 编译安装 nginx

echo "#######################################################################"

# tar zxvf nginx-1.2.4.tar.gz  

009

# cd nginx-1.2.4

echo ''

# ./configure --prefix=/usr/local/nginx --with-google_perftools_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/mydata/soft/pcre-8.31

010

# make && make install

 

#cd ../

011

# mkdir /tmp/tcmalloc

# get IP

# chmod 0777 /tmp/tcmalloc

012

7.4 添加用户和组

IP=`ifconfig | grep 'inet addr:' | cut -d: -f2 | grep -v ^10. | grep -v ^192.168 | grep -v ^172. | grep -v ^127. | awk '{print  $1}' | awk '{print;exit}'`

# /usr/sbin/groupadd www

013

# /usr/sbin/useradd -g www www

 

7.5 配置 nginx.conf

014

# vi /usr/local/nginx/conf/nginx.conf

# Set password

注意:要在 pid 下一行添加下面的代码才能使优化生效

015

google_perftools_profiles  /tmp/tcmalloc;

while :

示例:替换为以下内容

016

user www www;

do

worker_processes  4;

017

worker_cpu_affinity 0001 0100 1000 0010;

    read -p "Please input the root password of MySQL:" mysqlrootpwd

error_log  logs/error.log;

018

pid        logs/nginx.pid;

    read -p "Please input the manager password of Pureftpd:" ftpmanagerpwd

worker_rlimit_nofile  65535;

019

google_perftools_profiles  /tmp/tcmalloc;

    if (( ${#mysqlrootpwd} >= 5 && ${#ftpmanagerpwd} >=5 ));then

events {

020

   worker_connections  65535;

        break

}

021

http {

    else

   #include       deny_ips.conf;

022

   include       mime.types;

       echo "least 5 characters"

   default_type  application/octet-stream;

023

   server_tokens off;

    fi

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

024

                     '$status $body_bytes_sent "$http_referer" '

done

                     '"$http_user_agent" "$http_x_forwarded_for"';

025

   #access_log  logs/access.log  main;

 

   server_names_hash_bucket_size 128;

026

   client_header_buffer_size 32k;

# Download packages

   large_client_header_buffers 4 32k;

027

   client_max_body_size 50m;    

mkdir -p /root/lnmp/{source,conf}

   sendfile       on;

028

   tcp_nopush     on;

function Download()

   tcp_nodelay    on;

029

   keepalive_timeout  60;

{

   fastcgi_connect_timeout 300;

030

   fastcgi_send_timeout 300;

cd /root/lnmp

   fastcgi_read_timeout 300;

031

   fastcgi_buffer_size 64k;

[ -s init.sh ] && echo 'init.sh found' || wget

   fastcgi_buffers 4 64k;

032

   fastcgi_busy_buffers_size 128k;

cd /root/lnmp/source

   fastcgi_temp_file_write_size 256k;

033

   fastcgi_intercept_errors on;

[ -s cmake-2.8.10.2.tar.gz ] && echo 'cmake-2.8.10.2.tar.gz found' || wget

   gzip on;

034

   gzip_min_length   1k;

[ -s mysql-5.5.32.tar.gz ] && echo 'mysql-5.5.32.tar.gz found' || wget

   gzip_buffers      4 16k;

035

   gzip_http_version 1.0;

[ -s libiconv-1.14.tar.gz ] && echo 'libiconv-1.14.tar.gz found' || wget

   gzip_comp_level   2;

036

   gzip_types        text/plain application/x-javascript text/css application/xml;

[ -s libmcrypt-2.5.8.tar.gz ] && echo 'bmcrypt-2.5.8.tar.gz found' || wget

   gzip_vary on;

037

   include vhost/*.conf;

[ -s mhash-0.9.9.9.tar.gz ] && echo 'mhash-0.9.9.9.tar.gz found' || wget

}

038

7.6 启动 nginx

[ -s mcrypt-2.6.8.tar.gz ] && echo 'mcrypt-2.6.8.tar.gz found' || wget

# ulimit -SHn 65535

039

# /usr/local/nginx/sbin/nginx

[ -s php-5.3.26.tar.gz ] && echo 'php-5.3.26.tar.gz found' || wget

7.7 验证google-perftools是否已经正常加载 命令:

040

# lsof -n | grep tcmalloc

[ -s memcache-2.2.5.tgz ] && echo 'memcache-2.2.5.tgz found' || wget

显示如下:

041

nginx      2395 nobody   9w  REG  8,8       0    1599440 /tmp/tcmalloc.2395  

[ -s eaccelerator-0.9.6.1.tar.bz2 ] && echo 'eaccelerator-0.9.6.1.tar.bz2 found' || wget

nginx      2396 nobody   11w REG  8,8       0    1599443 /tmp/tcmalloc.2396  

042

nginx      2397 nobody   13w REG  8,8       0    1599441 /tmp/tcmalloc.2397  

[ -s PDO_MYSQL-1.0.2.tgz ] && echo 'PDO_MYSQL-1.0.2.tgz found' || wget

nginx      2398 nobody   15w REG  8,8       0    1599442 /tmp/tcmalloc.2398  

043

由于在Nginx配置文件中,设置worker_processes的值为4,因此开启了4个Nginx线程,每个线程会有一行记录。每个线程文件后面的数字值就是启动的Nginx的PID值。

[ -s ImageMagick-6.8.3-10.tar.gz ] && echo 'ImageMagick-6.8.3-10.tar.gz found' || wget

至此,利用TCMalloc优化Nginx的操作完成。

044

7.8 优化 nginx 内核

[ -s imagick-3.0.1.tgz ] && echo 'imagick-3.0.1.tgz found' || wget

# vi /etc/sysctl.conf

045

末尾添加:

[ -s pecl_http-1.7.5.tgz ] && echo 'pecl_http-1.7.5.tgz found' || wget

net.ipv4.tcp_max_tw_buckets = 6000

046

net.ipv4.ip_local_port_range = 1024 65000

[ -s pcre-8.32.tar.gz ] && echo 'pcre-8.32.tar.gz found' || wget

net.ipv4.tcp_tw_recycle = 1

047

net.ipv4.tcp_tw_reuse = 1

[ -s nginx-1.4.1.tar.gz ] && echo 'nginx-1.4.1.tar.gz found' || wget

net.ipv4.tcp_syncookies = 1

048

net.core.somaxconn = 262144

[ -s pure-ftpd-1.0.36.tar.gz ] && echo 'pure-ftpd-1.0.36.tar.gz found' || wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.36.tar.gz

net.core.netdev_max_backlog = 262144

049

net.ipv4.tcp_max_orphans = 262144

[ -s ftp_v2.1.tar.gz ] && echo 'ftp_v2.1.tar.gz found' || wget

net.ipv4.tcp_max_syn_backlog = 262144

050

net.ipv4.tcp_synack_retries = 1

cd ../conf

net.ipv4.tcp_syn_retries = 1

051

net.ipv4.tcp_fin_timeout = 1

[ -s init.d.nginx ] && echo 'init.d.nginx found' || wget

net.ipv4.tcp_keepalive_time = 30

052

刷新配置

[ -s nginx.conf ] && echo 'nginx.conf found' || wget

# /sbin/sysctl -p

053

7.9 添加 nginx 的系统服务

[ -s pure-ftpd.conf ] && echo 'pure-ftpd.conf found' || wget

之前在安装的时候写过了,详细内容可前往下面地址:

054

[ -s pureftpd-mysql.conf ] && echo 'pureftpd-mysql.conf found' || wget

7.10 添加各站点配置目录

055

# cd /usr/local/nginx/conf

[ -s script.mysql ] && echo 'script.mysql found' || wget

# mkdir vhost

056

7.10.1 配置 localhost 站点

}

# vi vhost/localhost.conf 

057

添加:

 

server

058

{

 

   listen       80;

059

   server_name  localhost;

function MySQL()

   index index.html index.php;

060

   root  /var/www/html/;

# install MySQL

   #limit_conn   crawler  20;    

061

   location ~ .*.(php|php5)?$

{

   {

062

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

cd /root/lnmp/source

       #upload filesize limit

063

       #client_max_body_size 10m;

useradd -M -s /sbin/nologin mysql

       fastcgi_pass  127.0.0.1:9000;

064

       fastcgi_index index.php;

mkdir -p /data/mysql;chown mysql.mysql -R /data/mysql

       include fastcgi.conf;

065

   }

tar xzf cmake-2.8.10.2.tar.gz

}

066

  1. 安装 mysql

cd cmake-2.8.10.2

8.1 检测是否之前有安装过 rpm mysql包

067

查看系统是否有安装过 MySQL

./configure

注意大小写,如果mysql 不行就换MySQL

068

# rpm -qa | grep mysql

make &&  make install

显示如:mysql-5.1.61-4.el6.x86_64

069

将搜索出的包名全部卸载:(nodeps表示强制删除),

cd ..

例如:

070

# rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64

tar zxf mysql-5.5.32.tar.gz

8.2 下载 MySQL 相关软件包

071

# cd /mydata/soft

cd mysql-5.5.32

# wget

072

8.3 新建 MySQL 用户和组

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/

# /usr/sbin/groupadd mysql

073

# /usr/sbin/useradd -g mysql mysql

-DMYSQL_DATADIR=/data/mysql  

8.4 新建目录并设置权限

074

# chmod w /usr/local/mysql

-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock

# chown -R mysql:mysql /usr/local/mysql

075

# mkdir -p /var/mysql/data/

-DWITH_INNOBASE_STORAGE_ENGINE=1

# mkdir -p /var/mysql/log/

076

# chown -R mysql:mysql /var/mysql/

-DENABLED_LOCAL_INFILE=1

# mkdir /home/mysql/temp

077

# chown -R mysql:mysql /home/mysql/temp

-DMYSQL_TCP_PORT=3306

8.5 开始安装 MySQL

078

# tar xvf mysql-5.5.28.tar.gz

-DEXTRA_CHARSETS=all

# cd mysql-5.5.28/

079

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

-DDEFAULT_CHARSET=utf8

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock

080

-DDEFAULT_CHARSET=utf8

-DDEFAULT_COLLATION=utf8_general_ci

-DDEFAULT_COLLATION=utf8_general_ci

081

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk

-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock

-DWITH_MYISAM_STORAGE_ENGINE=1

082

-DENABLED_LOCAL_INFILE=ON

-DWITH_DEBUG=0

-DWITH_INNOBASE_STORAGE_ENGINE=1

083

-DWITH_READLINE=1

make && make install

-DENABLED_LOCAL_INFILE=1

084

-DMYSQL_USER=mysql

 

-DMYSQL_DATADIR=/var/mysql/data

085

# make && make install

/bin/cp support-files/my-medium.cnf /etc/my.cnf

8.6 配置 my.cnf 文件

086

# cd support-files/

cp support-files/mysql.server /etc/init.d/mysqld

注意:my-large.cnf 适用于1G内存左右的服务器,

087

可以根据自己配置情况选用 my-large.cnf 或 my-huge.cnf 等不同配置

chmod 755 /etc/init.d/mysqld

# cp my-huge.cnf /etc/my.cnf

088

之前这里 my.cnf 的路径设置有问题(现已修改),导致没有生效,今天关闭 innodb 时才发现。。

chkconfig --add mysqld

是放在 etc 下面才会生效的。。

089

参考配置:关闭 innodb,binlog 保存 30 天内的

chkconfig mysqld on

# vi /etc/my.cnf

090

--------------------------------------忽略分隔线---------------------------------------

cd ..

[client]

091

port    = 3306

 

socket  = /usr/local/mysql/mysql.sock

092

[mysqld]

# my.cf

character-set-server = utf8

093

replicate-ignore-db = mysql

sed -i '38a ##############' /etc/my.cnf

replicate-ignore-db = test

094

replicate-ignore-db = information_schema

sed -i '39a skip-name-resolve' /etc/my.cnf

user    = mysql

095

port    = 3306

sed -i '40a basedir=/usr/local/mysql' /etc/my.cnf

socket  = /usr/local/mysql/mysql.sock

096

basedir = /usr/local/mysql

sed -i '41a datadir=/data/mysql' /etc/my.cnf

datadir = /var/mysql/data

097

tmpdir = /home/mysql/temp

sed -i '42a user=mysql' /etc/my.cnf

log-error = /var/mysql/log/error.log

098

pid-file = /var/mysql/mysql.pid

sed -i '43a #lower_case_table_names = 1' /etc/my.cnf

open_files_limit = 10240

099

back_log = 200

sed -i '44a max_connections=1000' /etc/my.cnf

max_connections = 1024

100

max_connect_errors = 1024

sed -i '45a ft_min_word_len=1' /etc/my.cnf

table_cache = 614

101

external-locking = FALSE

sed -i '46a expire_logs_days = 7' /etc/my.cnf

max_allowed_packet = 32M

102

sort_buffer_size = 4M

sed -i '47a query_cache_size=64M' /etc/my.cnf

join_buffer_size = 1M

103

thread_cache_size = 300

sed -i '48a query_cache_type=1' /etc/my.cnf

thread_concurrency = 4

104

query_cache_size = 512M

sed -i '49a ##############' /etc/my.cnf

query_cache_limit = 2M

105

query_cache_min_res_unit = 2k

 

default-storage-engine = MyISAM

106

thread_stack = 192K

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql

transaction_isolation = READ-COMMITTED

107

tmp_table_size = 246M

 

max_heap_table_size = 246M

108

long_query_time = 3

chown mysql.mysql -R /data/mysql

log-slave-updates

109

log-bin = /var/mysql/binlog/binlog

/sbin/service mysqld start

binlog_cache_size = 4M

110

binlog_format = MIXED

export PATH=$PATH:/usr/local/mysql/bin

max_binlog_cache_size = 8M

111

max_binlog_size = 1G

echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

#relay-log-index = /var/mysql/relaylog/relaylog

112

#relay-log-info-file = /var/mysql/relaylog/relaylog

source /etc/profile

#relay-log = /var/mysql/relaylog/relaylog

113

expire_logs_days = 30

 

key_buffer_size = 256M

114

read_buffer_size = 1M

/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to [email protected]'localhost' identified by "$mysqlrootpwd" with grant option;"

read_rnd_buffer_size = 16M

115

bulk_insert_buffer_size = 64M

/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd -e "delete from mysql.user where Password='';"

myisam_sort_buffer_size = 128M

116

myisam_max_sort_file_size = 10G

/sbin/service mysqld restart

myisam_repair_threads = 1

117

myisam_recover

}

interactive_timeout = 120

118

wait_timeout = 120

 

#skip-name-resolve

119

slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

function PHP()

#master-host     =   192.168.1.2

120

#master-user     =   username

# install PHP

#master-password =   password

121

#master-port     =  3306

{

server-id = 1

122

skip-innodb

cd /root/lnmp/source

innodb_additional_mem_pool_size = 16M

123

innodb_buffer_pool_size = 512M

tar xzf libiconv-1.14.tar.gz

innodb_data_file_path = ibdata1:256M:autoextend

124

innodb_file_io_threads = 4

cd libiconv-1.14

innodb_thread_concurrency = 8

125

innodb_flush_log_at_trx_commit = 2

./configure --prefix=/usr/local

innodb_log_buffer_size = 16M

126

innodb_log_file_size = 128M

make && make install

innodb_log_files_in_group = 3

127

innodb_max_dirty_pages_pct = 90

cd ../

innodb_lock_wait_timeout = 120

128

innodb_file_per_table = 0

 

slow-query-log = On

129

slow-query-log-file = /var/mysql/log/slow.log

tar xzf libmcrypt-2.5.8.tar.gz

long_query_time = 30

130

[mysqldump]

cd libmcrypt-2.5.8

quick

131

max_allowed_packet = 32M

./configure

--------------------------------------忽略分隔线---------------------------------------

132

# cp mysql.server /etc/init.d/mysqld

make && make install

# cd ../../ 

133

8.7 初始化安装数据库

/sbin/ldconfig

# /usr/local/mysql/scripts/mysql_install_db

134

--defaults-file=/var/mysql/my.cnf

cd libltdl/

--basedir=/usr/local/mysql

135

--datadir=/var/mysql/data

./configure --enable-ltdl-install

--user=mysql

136

8.8 将 mysql 加入开机启动

make && make install

# chmod x /etc/init.d/mysqld

137

# vi /etc/init.d/mysqld

cd ../../

查找并修改:

138

basedir=/usr/local/mysql

 

datadir=/var/mysql/data

139

8.9 添加为系统服务

tar xzf mhash-0.9.9.9.tar.gz

# chkconfig --add mysqld

140

# chkconfig --level 2345 mysqld on

cd mhash-0.9.9.9

8.10 启动mysql 设置 root 密码

141

# service mysqld start 

./configure

# /usr/local/mysql/bin/mysqladmin -u root password "123456"

142

错误一:

make && make install

mysqladmin, mysql ... 命令无法执行:

143

# export PATH=/usr/local/mysql/bin:$PATH

cd ../

错误二:

144

Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

 

# yum install ncurses-devel

145

8.11 添加并发优化

if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then

# vi /usr/local/mysql/bin/mysqld_safe

146

在 executing mysqld_safe 的下一行,加上:

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

export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

147

启动 mysql:

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

# service mysqld restart

148

使用lsof命令查看tcmalloc是否起效:

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

# /usr/sbin/lsof -n | grep tcmalloc

149

如果发现以下信息,说明tcmalloc已经起效:

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

mysqld    10847   mysql  mem       REG        8,5  1203756   20484960 /usr/local/lib/libtcmalloc.so.0.0.0

150

新建一个远程访问用户:

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

CREATE USER 'locoy'@'%' IDENTIFIED BY '*****';

151

GRANT ALL PRIVILEGES ON * . * TO 'locoy'@'%' IDENTIFIED BY '*****' WITH GRANT OPTIONMAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 

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

  1. 开始安装 PHP

152

9.1 下载 php 和相关软件包

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

# cd /mydata/soft

153

wget

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

wget

154

wget

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

wget

155

wget

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

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.8.0-2.tar.gz

156

wget

    ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/libmysqlclient.so.18

wget

157

wget

        ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1

wget

158

wget

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

wget

159

wget

        cp -frp /usr/lib64/libldap* /usr/lib

wget

160

wget

else

9.2 安装 php 相关的软件

161

这部分代码安装过好多太服务器几乎没有什么问题,可以直接全部复制粘贴到ssh就好了,我就不打 # 号了

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

tar zxvf libiconv-1.14.tar.gz

162

cd libiconv-1.14

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

./configure --prefix=/usr/local

163

make && make install

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

cd ../

164

tar zxvf libmcrypt-2.5.8.tar.gz

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

cd libmcrypt-2.5.8/

165

./configure

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

make && make install

166

/sbin/ldconfig

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

cd libltdl/

167

./configure --enable-ltdl-install

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

make && make install

168

cd ../../

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

tar zxvf mhash-0.9.9.9.tar.gz

169

cd mhash-0.9.9.9/

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

./configure

170

make && make install

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

cd ../

171

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

    ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib/libmysqlclient.so.18

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

172

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

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

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

173

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

        ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1

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

174

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

fi

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

175

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

176

ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib/libmysqlclient.so.18

tar xzf mcrypt-2.6.8.tar.gz

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

177

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

cd mcrypt-2.6.8

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

178

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

/sbin/ldconfig

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

179

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

./configure

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

180

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

make && make install

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

181

ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib64/libmysqlclient.so.18

cd ../

ln -sv /usr/lib64/libldap* /usr/lib/

182

tar zxvf mcrypt-2.6.8.tar.gz

 

cd mcrypt-2.6.8/

183

/sbin/ldconfig

tar xzf php-5.3.26.tar.gz

./configure

184

make && make install

useradd -M -s /sbin/nologin www

cd ../

185

9.3 新建扩展配置目录

cd php-5.3.26

# mkdir -p /usr/local/php/etc/php.d/

186

9.4 开始安装 PHP 5.4.8

./configure  --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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-ftp --with-gettext --enable-zip --enable-soap --disable-debug

# tar xvzf php-5.4.8.tar.gz

187

# cd php-5.4.8/

make ZEND_EXTRA_LIBS='-liconv'

# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc

188

--with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config

make install

--with-pdo-mysql=/usr/local/mysql/ --with-iconv-dir=/usr/local --enable-fpm

189

--disable-phar --with-fpm-user=www --with-fpm-group=www --with-pcre-regex

cp php.ini-production /usr/local/php/lib/php.ini

--with-config-file-scan-dir=/usr/local/php/etc/php.d

190

--with-zlib --with-bz2 --enable-calendar --with-curl --enable-dba --with-libxml-dir

 

--enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir

191

--enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt

#php-fpm Init Script

--enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip

192

--enable-bcmath --with-snmp --disable-ipv6 --with-xmlrpc --with-ldap --with-ldap-sasl --enable-exif

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

--enable-soap --enable-pdo --with-pdo-mysql --enable-sysvsem --enable-inline-optimization --with-curlwrappers

193

# make ZEND_EXTRA_LIBS='-liconv'

chmod x /etc/init.d/php-fpm

# make test

194

# make install

chkconfig --add php-fpm

# cp php.ini-production /usr/local/php/etc/php.ini

195

# PATH=/usr/local/php/bin:$PATH

chkconfig php-fpm on

# PATH=/usr/local/php/sbin:$PATH

196

提示:

cd ../

--enable-fastcgi --enable-force-cgi-redirect PHP 5.3以后已经强制开启了 fastcgi 了,具体查看官方说明:

197

 最下面 FastCGI is now always enabled and cannot be disabled.

 

错误:

198

configure: error: Cannot find ldap libraries in /usr/lib.

tar xzf memcache-2.2.5.tgz

解决办法:

199

ln -sv /usr/lib64/libldap* /usr/lib/

cd memcache-2.2.5

注意 make test 的时候可能会出现 :

200

/mnt/sun/php-5.4.8/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

/usr/local/php/bin/phpize

32位系统

201

# ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib/libmysqlclient.so.18

./configure --with-php-config=/usr/local/php/bin/php-config

64位系统

202

# ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib64/libmysqlclient.so.18

make && make install

9.5 开机启动 php-fpm

203

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

cd ../

# chmod x /etc/init.d/php-fpm

204

# chkconfig --add php-fpm

 

# chkconfig --level 2345 php-fpm on

205

# cd ../

tar xjf eaccelerator-0.9.6.1.tar.bz2

9.6 关于php-fpm 的操作说明与添加系统服务

206

PHP5.3.3以上版本的php-fpm重启、停止命令已经不是php-fpm start|stop|reload了,

cd eaccelerator-0.9.6.1

需要使用信号控制:

207

详细内容查看该文章

/usr/local/php/bin/phpize

PHP 5.4.8 添加系统服务命令

208

 

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

9.7 安装 PHP 扩展

209

9.7.1 服务器版 memcached

make && make install

memcached 把我搞晕了,有两个 memcached,我也不是很清楚具体区别,

210

按我的理解应该是分为 服务器版 和 php 扩展版

cd ../

一开始用 服务器版来编译 php 扩展,搞了半天都没弄出来,后来才发现居然有两个,晕死了

211

安装依赖包:

 

# tar zxvf libevent-2.0.20-stable.tar.gz

212

# cd libevent-2.0.20-stable

tar xzf PDO_MYSQL-1.0.2.tgz

# ./configure --prefix=/usr/local/libevent

213

# make && make install

cd PDO_MYSQL-1.0.2

# cd ../

214

# tar xvzf memcached-1.4.15.tar.gz

/usr/local/php/bin/phpize

# cd memcached-1.4.15

215

# ./configure --enable-64bit --enable-threads --with-libevent=/usr/local/libevent

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

# make && make install

216

# cd ../

make && make install

检测是否安装成功:

217

# ls -al /usr/local/bin/memcached

cd ../

# mkdir -p /var/run/memcached/

218

启动 memcached:

 

# /usr/local/bin/memcached -d -m 128 -u root -l 22.11.5.91 -p 11211 -c 256 -P /var/run/memcached/memcached.pid

219

# ps aux|grep memcached

tar xzf ImageMagick-6.8.3-10.tar.gz

关闭 memcached:

220

# kill `cat /var/run/memcached/memcached.pid`

cd ImageMagick-6.8.3-10

新建启动和关闭脚本并赋执行权限:

221

# cp memcached-1.4.15/scripts/memcached.sysv /etc/init.d/memcached

./configure

# chmod 755 /etc/init.d/memcached

222

修改配置:

make && make install

# vi /etc/init.d/memcached

223

修改:

cd ../

PORT=11212

224

USER=root

 

OPTIONS=""

225

查找:

tar xzf imagick-3.0.1.tgz

daemon memcached -d -p ....

226

修改为:

cd imagick-3.0.1

daemon /usr/local/bin/memcached -d -p ....

227

添加下面两行:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

chown $USER /usr/local/bin/memcached

228

/usr/local/bin/memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P /var/run/memcache/memcached.pid $OPTIONS

/usr/local/php/bin/phpize

添加到系统服务:

229

# chkconfig --add memcached

./configure --with-php-config=/usr/local/php/bin/php-config

# chkconfig --level 2345 memcached on

230

# chkconfig --list memcached

make && make install

测试启动 检测 关闭:

231

# service memcached start

cd ../

# ps aux|grep memcached

232

# service memcached stop

 

开启防火墙外网访问(单机可忽略该设置):

233

# iptables -I INPUT -p tcp --dport 11211 -j ACCEPT

# Support HTTP request curls

# iptables -I OUTPUT -p tcp --sport 11211 -j ACCEPT

234

# iptables-save

tar xzf pecl_http-1.7.5.tgz

# service iptables save

235

9.7.2 安装php扩展版 memcached

cd pecl_http-1.7.5

依赖库:

236

# tar zxvf libmemcached-1.0.13.tar.gz

/usr/local/php/bin/phpize

# cd libmemcached-1.0.13

237

# ./configure --prefix=/usr/local/libmemcached

./configure --with-php-config=/usr/local/php/bin/php-config

# make && make install

238

# cd ../

make && make install

安装 memcached

239

# tar vxzf memcached-2.1.0.tgz

cd ../

# cd memcached-2.1.0

240

# /usr/local/php/bin/phpize

 

# ./configure --enable-memcached --with-libmemcached-dir=/usr/local/libmemcached --with-php-config=/usr/local/php/bin/php-config

241

# make && make install

# Modify php.ini

# cd ..

242

9.7.3 安装 memcache

mkdir /tmp/eaccelerator

# tar zxvf memcache-3.0.7.tgz

243

# cd memcache-3.0.7/

/bin/chown -R www.www /tmp/eaccelerator/

# /usr/local/php/bin/phpize

244

# ./configure --prefix=/usr/local/memcache --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

sed -i '808a extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"' /usr/local/php/lib/php.ini

# make && make install

245

# cd ../

sed -i '809a extension = "memcache.so"' /usr/local/php/lib/php.ini

9.7.4 安装图片处理软件 可取代 gd

246

# tar zxvf ImageMagick-6.8.0-2.tar.gz

sed -i '810a extension = "pdo_mysql.so"' /usr/local/php/lib/php.ini

# cd ImageMagick-6.8.0-2/

247

# export CFLAGS='-fPIC'

sed -i '811a extension = "imagick.so"' /usr/local/php/lib/php.ini

# ./configure --prefix=/usr/local/ImageMagick --with-quantum-depth=8 --enable-share --enable-static

248

# make && make install

sed -i '812a extension = "http.so"' /usr/local/php/lib/php.ini

# cd ../

249

# tar zxvf imagick-3.1.0RC2.tgz

sed -i '135a output_buffering = On' /usr/local/php/lib/php.ini

# cd imagick-3.1.0RC2/

250

# /usr/local/php/bin/phpize

sed -i '848a cgi.fix_pathinfo=0' /usr/local/php/lib/php.ini

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

251

# ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/ImageMagick

sed -i

# make && make install

'[email protected]_open_tag

# cd ../

[email protected]_open_tag

[email protected]' /usr/local/php/lib/php.ini

252

sed -i

9.7.5 安装 eaccelerator 给 php 编译加速 缓存

'[email protected]_php

# wget

[email protected]_php

[email protected]' /usr/local/php/lib/php.ini

253

sed -i '[email protected];date.timezone [email protected] = Asia/[email protected]' /usr/local/php/lib/php.ini

254

sed -i '[email protected]#sendmail_path.*@#sendmail_path = /usr/sbin/sendmail [email protected]' /usr/local/php/lib/php.ini

255

echo '[eaccelerator]

256

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"

257

eaccelerator.shm_size="64"

258

eaccelerator.cache_dir="/tmp/eaccelerator"

259

eaccelerator.enable="1"

260

eaccelerator.optimizer="1"

261

eaccelerator.check_mtime="1"

262

eaccelerator.debug="0"

263

eaccelerator.filter=""

264

eaccelerator.shm_max="0"

265

eaccelerator.shm_ttl="0"

266

eaccelerator.shm_prune_period="0"

267

eaccelerator.shm_only="0"

268

eaccelerator.compress="0"

269

eaccelerator.compress_level="9"

270

eaccelerator.keys = "disk_only"

271

eaccelerator.sessions = "disk_only"

272

eaccelerator.content = "disk_only"' >> /usr/local/php/lib/php.ini

273

 

274

cat > /usr/local/php/etc/php-fpm.conf <<EOF

275

;;;;;;;;;;;;;;;;;;;;;

276

; FPM Configuration ;

277

;;;;;;;;;;;;;;;;;;;;;

278

 

279

;;;;;;;;;;;;;;;;;;

280

; Global Options ;

281

;;;;;;;;;;;;;;;;;;

282

 

283

[global]

284

pid = run/php-fpm.pid

285

error_log = log/php-fpm.log

286

log_level = notice

287

 

288

emergency_restart_threshold = 30

289

emergency_restart_interval = 1m

290

process_control_timeout = 5s

291

daemonize = yes

292

 

293

;;;;;;;;;;;;;;;;;;;;

294

; Pool Definitions ;

295

;;;;;;;;;;;;;;;;;;;;

296

 

297

[www]

298

 

299

listen = 127.0.0.1:9000

300

listen.backlog = -1

301

listen.allowed_clients = 127.0.0.1

302

listen.owner = www

303

listen.group = www

304

listen.mode = 0666

305

user = www

306

group = www

307

 

308

pm = dynamic

309

pm.max_children = 32

310

pm.start_servers = 4

311

pm.min_spare_servers = 4

312

pm.max_spare_servers = 16

313

pm.max_requests = 512

314

 

315

request_terminate_timeout = 0

316

request_slowlog_timeout = 0

317

 

318

slowlog = log/$pool.log.slow

319

rlimit_files = 51200

320

rlimit_core = 0

321

 

322

catch_workers_output = yes

323

env[HOSTNAME] = $HOSTNAME

324

env[PATH] = /usr/local/bin:/usr/bin:/bin

325

env[TMP] = /tmp

326

env[TMPDIR] = /tmp

327

env[TEMP] = /tmp

328

EOF

329

 

330

# php start

331

service php-fpm start

332

}

333

 

334

function Nginx()

335

# install Nginx

336

{

337

cd /root/lnmp/source

338

tar xzf pcre-8.32.tar.gz

339

cd pcre-8.32

340

./configure

341

make && make install

342

cd ../

343

 

344

#tar xzf ngx_cache_purge-2.1.tar.gz

345

tar xzf nginx-1.4.1.tar.gz

346

cd nginx-1.4.1

347

 

348

# Modify Nginx version

349

sed -i '[email protected]#define NGINX_VERSION.*[email protected]#define NGINX_VERSION      "2.2.14"@g' src/core/nginx.h

350

sed -i '[email protected]#define NGINX_VER.*[email protected]#define NGINX_VER          "Apache/" [email protected]' src/core/nginx.h

351

#./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_cache_purge-2.1

352

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module

353

make && make install

354

cd /root/lnmp/conf

355

cp init.d.nginx /etc/init.d/nginx

356

chmod 755 /etc/init.d/nginx

357

chkconfig --add nginx

358

chkconfig nginx on

359

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf_bk

360

cp nginx.conf /usr/local/nginx/conf/nginx.conf

361

 

362

#logrotate nginx log

363

echo '/usr/local/nginx/logs/*.log {

364

daily

365

rotate 5

366

missingok

367

dateext

368

compress

369

notifempty

370

sharedscripts

371

postrotate

372

    [ -f /usr/local/nginx/logs/nginx.pid ] && kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`

373

endscript

374

}' > /etc/logrotate.d/nginx

375

 

376

service nginx restart

377

}

378

 

379

function Pureftp()

380

# install Pureftpd and pureftpd_php_manager

381

{

382

cd /root/lnmp/source

383

tar xzf pure-ftpd-1.0.36.tar.gz

384

cd pure-ftpd-1.0.36

385

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

386

make && make install

387

cp configuration-file/pure-config.pl /usr/local/pureftpd/sbin

388

chmod x /usr/local/pureftpd/sbin/pure-config.pl

389

cp contrib/redhat.init /etc/init.d/pureftpd

390

sed -i '[email protected]=.*@fullpath=/usr/local/pureftpd/sbin/[email protected]' /etc/init.d/pureftpd

391

sed -i '[email protected]=.*@pureftpwho=/usr/local/pureftpd/sbin/[email protected]' /etc/init.d/pureftpd

392

sed -i '[email protected]/etc/[email protected]/usr/local/pureftpd/[email protected]' /etc/init.d/pureftpd

393

chmod x /etc/init.d/pureftpd

394

chkconfig --add pureftpd

395

chkconfig pureftpd on

396

 

397

cd /root/lnmp/conf

398

/bin/cp pure-ftpd.conf /usr/local/pureftpd/

399

/bin/cp pureftpd-mysql.conf /usr/local/pureftpd/

400

mysqlftppwd=`cat /dev/urandom | head -1 | md5sum | head -c 8`

401

sed -i 's/tmppasswd/'$mysqlftppwd'/g' /usr/local/pureftpd/pureftpd-mysql.conf

402

sed -i 's/mysqlftppwd/'$mysqlftppwd'/g' script.mysql

403

sed -i 's/ftpmanagerpwd/'$ftpmanagerpwd'/g' script.mysql

404

/usr/local/mysql/bin/mysql -uroot -p$mysqlrootpwd< script.mysql

405

service pureftpd start

406

 

407

mkdir -p /data/admin

408

cd ../source

409

tar xzf ftp_v2.1.tar.gz

410

mv ftp /data/admin;chown -R www.www /data/admin

411

sed -i 's/tmppasswd/'$mysqlftppwd'/g' /data/admin/ftp/config.php

412

sed -i "s/myipaddress.com/`echo $IP`/g" /data/admin/ftp/config.php

413

sed -i 's/127.0.0.1/localhost/g' /data/admin/ftp/config.php

414

sed -i '[email protected]@[email protected]' /data/admin/ftp/language/english.php

415

rm -rf  /data/admin/ftp/install.php

416

echo '<?php

417

phpinfo()

418

?>' > /data/admin/index.php

419

cd ../

420

}

421

 

422

function Iptables()

423

{

424

cat > /etc/sysconfig/iptables << EOF

425

# Firewall configuration written by system-config-securitylevel

426

# Manual customization of this file is not recommended.

427

*filter

428

:INPUT DROP [0:0]

429

:FORWARD ACCEPT [0:0]

430

:OUTPUT ACCEPT [0:0]

431

-A INPUT -i lo -j ACCEPT

432

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

433

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

434

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

435

-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT

436

-A INPUT -p tcp -m state --state NEW -m tcp --dport 20000:30000 -j ACCEPT

437

-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT

438

-A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT

439

COMMIT

440

EOF

441

service iptables restart

442

}

443

 

444

Download 2>&1 | tee -a /root/lnmp/lnmp_install.log

445

Download

446

chmod x /root/lnmp/init.sh

447

/root/lnmp/init.sh 2>&1 | tee -a /root/lnmp/lnmp_install.log

448

echo -e "33[32minitialized successfully33[0m"

449

MySQL 2>&1 | tee -a /root/lnmp/lnmp_install.log

450

[ -d "/usr/local/mysql" ] && echo -e "33[32mMySQL install successfully33[0m" || echo "MySQL install failed"

451

PHP 2>&1 | tee -a /root/lnmp/lnmp_install.log

452

[ -d "/usr/local/php" ] && echo -e "33[32mPHP install successfully33[0m" || echo "PHP install failed"

453

Nginx 2>&1 | tee -a /root/lnmp/lnmp_install.log

454

[ -d "/usr/local/nginx" ] && echo -e "33[32mNginx install successfully33[0m" || echo "Nginx install failed"

455

Pureftp 2>&1 | tee -a /root/lnmp/lnmp_install.log

456

[ -d "/usr/local/pureftpd" ] && echo -e "33[32mPureftpd install successfully33[0m" || echo "Pureftpd install failed"

457

Iptables 2>&1 | tee -a /root/lnmp/lnmp_install.log

458

 

459

echo "################Congratulations####################"

460

echo "The path of some dirs:"

461

echo -e "Nginx dir:                     33[32m/usr/local/nginx33[0m"

462

echo -e "MySQL dir:                     33[32m/usr/local/mysql33[0m"

463

echo -e "PHP dir:                       33[32m/usr/local/php33[0m"

464

echo -e "Pureftpd dir:                  33[32m/usr/local/pureftpd33[0m"

465

echo -e "Pureftp_php_manager dir:       33[32m/data/admin33[0m"

466

echo -e "MySQL Password:                33[32m${mysqlrootpwd}33[0m"

467

echo -e "Pureftp_manager url:           33[32m"

468

echo -e "Pureftp_manager Password:      33[32m${ftpmanagerpwd}33[0m"

469

echo "###################################################"

 

Linux Nginx MySQL PHP Pureftpd User manager for PureFTPd,脚本中用到的软件包大多最新版本,修复了User manager for Pure...

# mv master eaccelerator-eaccelerator-42067ac.tar.gz

# tar zxvf eaccelerator-eaccelerator-42067ac.tar.gz

# cd eaccelerator-eaccelerator-42067ac/

# /usr/local/php/bin/phpize

# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

# make && make install

# cd ../

新建目录:

# mkdir /tmp/eaccelerator_cache

# chmod 0777 /tmp/eaccelerator_cache

9.7.6 配置扩展

打开自动扫描的扩展目录:

# cd /usr/local/php/etc/php.d

--------------------------------忽略分割线------------------------------ 

# vi eaccelerator.ini

写入:

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"

eaccelerator.shm_size="20"

eaccelerator.cache_dir="/tmp/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 memcache.ini

写入:

extension = "memcache.so"

memcache.chunk_size = 32768

--------------------------------忽略分割线------------------------------ 

# vi memcached.ini

写入:

extension = "memcached.so"

--------------------------------忽略分割线------------------------------ 

# vi imagick.ini

写入:

extension = "imagick.so"

--------------------------------忽略分割线------------------------------ 

修改php配置:

# vi /usr/local/php/etc/php.ini

查找并修改:

cgi.fix_pathinfo=0

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"

expose_php = Off

allow_url_fopen = Off

open_basedir = /tmp/:/var/www/

disable_functions = exec,system,passthru,chroot,scandir,chgrp,Shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

date.timezone = Asia/Shanghai

拷贝 php-fpm 配置:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

# vi /usr/local/php/etc/php-fpm.conf

查找并修改:

以下为示例数值,按自己服务器实际性能配置:

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 10240

rlimit_files = 65535

  1. 设置开机启动

# vi /etc/rc.local

写入:

ulimit -SHn 65535

service mysqld start

service php-fpm start

service memcached start

service nginx start

  1. 配置完成

弄了好几天,每天都熬到凌晨3点,终于弄完了,搞服务器真要累死人。。。


TAG标签:
版权声明:本文由美高梅网投平台发布于美高梅简介,转载请注明出处:搭建基于Linux6,5系统下安装配置Nginx