Centos6.2搭建lnmp环境

  1. 云栖社区>
  2. 博客>
  3. 正文

Centos6.2搭建lnmp环境

科技探索者 2017-11-21 16:08:00 浏览913
展开阅读全文

系统环境:Centos6.2

软件环境:Nginx1.1.9 + Mysql5.5.18 + PHP5.3.10

1、安装相关扩展包及编译工具

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

2、安装php扩展包

   tar zxvf libiconv-1.13.1.tar.gz 
   cd libiconv-1.13.1
    ./configure –prefix=/usr/local
   make
   make install

   tar zxvf libmcrypt-2.5.8.tar.gz 
   cd libmcrypt-2.5.8
    ./configure 
   make install
   /sbin/ldconfig 
   cd libltdl/
   ./configure –enable-ltdl-install
   make
   make install
   ln -sv /usr/local/lib/libmcrypt.* /usr/lib/
   ln -sv /usr/local/bin/libmcrypt-config /usr/bin/

   tar zxvf mhash-0.9.9.9.tar.gz 
   cd mhash-0.9.9.9
  ./configure 
   make;make install
   ln -sv /usr/local/lib/libmhash.* /usr/lib/

   tar zxvf mcrypt-2.6.8.tar.gz 
   cd mcrypt-2.6.8
   ldconfig 
   ./configure
   make;make install

3、安装Mysql

tar zxvf cmake-2.8.6.tar.gz
cd cmake-2.8.6
 ./bootstrap 
gamke;make install

 tar zxvf mysql-5.5.18.tar.gz 
 cd mysql-5.5.18
 groupadd mysql
 useradd -g mysql -s /sbin/nologin mysql
 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=OFF -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
 make;make install
 ln -sv /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
 ln -sv /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
不需要mysql的话以下步骤请无视之:
 mv /etc/my.cnf  /etc/my.cnf.bak
 cp my.cnf  /etc/
 chmod 755 mysql-5.5.18/scripts/mysql_install_db
  ./mysql-5.5.18/scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql
 cp mysql-5.5.18/support-files/mysql.server /etc/init.d/mysql
 chmod 755 /etc/init.d/mysql 
 chkconfig mysql on
 service mysql restart
 /usr/local/mysql/bin/mysqladmin -uroot password www.wisp888.com

4、安装PHP

tar jxvf php-5.3.10.tar.bz2
cd php-5.3.10
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –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-zip –enable-soap

其中编译出错如下:
configure: error: Cannot find ldap libraries in /usr/lib.
解决办法:
ln -sv /usr/lib64/libldap* /usr/lib/

接着安装php
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-production /usr/local/php/etc/php.ini
sed -i ‘s@; output_buffering@output_buffering=on@’ /usr/local/php/etc/php.ini
sed -i ‘s@;cgi.fix_pathinfo=1@cgi.fix_pathinfo=0@’ /usr/local/php/etc/php.ini
 sed -i ‘s@; extension_dir = “./”@extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626″@’ /usr/local/php/etc/php.ini
cd ..
cp php-fpm.conf /usr/local/php/etc/php-fpm.conf
echo “/usr/local/php/sbin/php-fpm” >> /etc/rc.local

5、安装php扩展模块

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make;make install
sed -i ’810aextension = “memcache.so”‘ /usr/local/php/etc/php.ini

tar xvf 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 -p /usr/local/eaccelerator_cache
sed -i ’810aextension = “pdo_mysql.so”‘ /usr/local/php/etc/php.ini
cat >> /usr/local/php/etc/php.ini << “EOF”
[eaccelerator]
zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/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″
EOF

tar xvf 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
 sed -i ’810aextension = “imagick.so”‘ /usr/local/php/etc/php.ini

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

其中make的时候会报错:
BEGIN failed–compilation aborted at Makefile.PL line 24.
make[1]: *** [PerlMagick/Makefile] Error 2
make[1]: Leaving directory `/root/ImageMagick-6.4.9-10′
make: *** [all] Error 2
解决办法:
yum -y install perl-CPAN

tar xvf imagick-2.3.0.tgz
cd imagick-2.3.0
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make;make install

6、安装nginx

unzip pcre-8.20.zip
cd pcre-8.20
./configure
make;make install
cd ..
tar xvf nginx-1.1.8.tar.gz
cd nginx-1.1.8
mkdir -p /data/www/logs
groupadd www
useradd -m www -g www -s /sbin/nologin -d /usr/local/nginx
chown -R www:www /data/www
./configure  –prefix=/usr/local/nginx  –with-http_stub_status_module –with-http_ssl_module –user=www –group=www –with-http_realip_module –with-http_flv_module –with-http_gzip_static_module
make;make install
mv /usr/local/nginx/conf/nginx.conf{,.bak}
cd ..
cp nginx.conf /usr/local/nginx/conf/nginx.conf
cat > /usr/local/nginx/conf/fcgi.conf << “EOF”
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;

fastcgi_param  REDIRECT_STATUS    200;
EOF

echo “ulimit -SHn 65535″ >> /etc/rc.local
echo “/usr/local/nginx/sbin/nginx” >> /etc/rc.local

7、安装memcached内存缓存工具

tar xvf libevent-2.0.11-stable.tar.gz
cd libevent-2.0.11-stable
./configure 
 make;make install
ln -sv /usr/local/lib/libevent-2.0.so.5 /usr/lib/
ln -sv /usr/local/lib/libevent-2.0.so.5 /usr/lib64/

tar xvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure –prefix=/usr/local/memcached –with-libevent=/usr
make;make install
echo “/usr/local/memcached/bin/memcached -d -m 256 -p 11211 -u www 127.0.0.1″ >> /etc/rc.local

8、优化内核参数

cat > /etc/sysctl.conf << “EOF”
# Add
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
kernel.shmmax = 128000000
EOF

/sbin/sysctl -p

9、启动服务

/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx
/usr/local/memcached/bin/memcached -d -m 256 -p 11211 -u www 127.0.0.1

本文转自运维笔记博客51CTO博客,原文链接http://blog.51cto.com/lihuipeng/798172如需转载请自行联系原作者


lihuipeng

网友评论

登录后评论
0/500
评论
科技探索者
+ 关注