2312321 发表于 2016-5-16 10:28:51

LNMP+memcached平台的搭建

实验01:LNMP平台的搭建
实验目标:nginx可以解析php
实验步骤:
一:环境准备
1:准备搭建环境,创建用户
# useradd www
# useradd mysql
2:将原有的http网站服务停止并删除原有mysql的主配置文件,停掉mysql服务
3:解压软件包
# unzip lnmp+memcached.zip
lnmp+memcached               lnmp+memcached.zip
二:安装源码nginx软件包
1:解压软件包
# cd lnmp+memcached
# tar -zxf nginx-1.2.0.tar.gz
# cd nginx-1.2.0
2:编写运行的脚本
# vim nginx.sh
./configure    --prefix=/usr/local/nginx   --pid-path=/usr/local/nginx/nginx.pid   --user=www   --group=www--with-http_ssl_module   --with-http_flv_module   --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/usr/local/nginx/client--http-proxy-temp-path=/usr/local/nginx/proxy--http-fastcgi-temp-path=/usr/local/nginx/fcgi--http-uwsgi-temp-path=/usr/local/nginx/uwsgi--http-scgi-temp-path=/usr/local/nginx/scgi--with-pcre
3:运行脚本进行编译及安装
# sh nginx.sh
# make && make install
4:启动服务,测试
# /usr/local/nginx/sbin/nginx
# elinks --dump http://127.0.0.1
                               Welcome to nginx!
三:安装源码的mysql软件包
1:解压软件包
# tar -zxf cmake-2.8.10.2.tar.gz
2:编译安装
# cd cmake-2.8.10.2
# ./bootstrap --prefix=/usr/local/cmake
# make && make install
3:解压mysql软件包
# tar -zxf mysql-5.5.13.tar.gz
4:编写mysql运行脚本
# cd mysql-5.5.13
# vim mysql.sh
/usr/local/cmake/bin/cmake    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    -DSYSCONFDIR=/etc   -DMYSQL_DATADIR=/usr/local/mysql/data-DMYSQL_TCP_PORT=3306   -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock   -DMYSQL_USER=mysql   -DEXTRA_CHARSETS=all   -DWITH_READLINE=1   -DWITH_SSL=system   -DWITH_EMBEDDED_SERVER=1   -DENABLED_LOCAL_INFILE=1   -DWITH_INNOBASE_STORAGE_ENGINE=1
5:运行脚本,进行编译及安装
# sh mysql.sh
# make && make install
6:初始化授权库并建立主配置文件
# cd /usr/local/mysql/
# ./scripts/mysql_install_db --user=mysql
# cd /root/lnmp+memcached/mysql-5.5.13
# cd support-files/
# cp -p my-medium.cnf /etc/my.cnf
7:启动数据库服务,修改密码并测试
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
如果mysql如果起不来,执行
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &
进入/usr/local/mysql/data/目录删除ib_logfile0和ib_logfile1文件
# /usr/local/mysql/bin/mysqladmin -hlocalhost -uroot password "123"
# netstat -auntp | grep 3306
tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17806/mysqld      
# pkill -9 mysqld
+已杀死               /usr/local/mysql/bin/mysqld_safe --user=mysql
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
8:给源码mysql设置启动脚本
# cp -p mysql.server /etc/init.d/mysqldd
# chmod +x /etc/init.d/mysqldd
# chkconfig --add mysqldd
# chkconfig --list mysqldd
mysqldd      0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# /etc/init.d/mysqldd stop
Shutting down MySQL.141129 13:54:25 mysqld_safe mysqld from pid file /usr/local/mysql/data/svr110.tarena.com.pid ended
                                                         [确定]
+Done                  /usr/local/mysql/bin/mysqld_safe --user=mysql
# /etc/init.d/mysqldd restart
MySQL server PID file could not be found!                  [失败]
Starting MySQL..                                           [确定]
四:安装源码php
1:安装扩展
# tar -zxf mhash-0.9.9.9.tar.gz
# tar -zxf libiconv-1.13.tar.gz
# tar -zxf libmcrypt-2.5.8.tar.gz
libiconv-1.13.tar.gz    libiconv-1.13   mhash-0.9.9.9mhash-0.9.9.9.tar.gz
libmcrypt-2.5.8    libmcrypt-2.5.8.tar.gz
2:编译安装
# cd mhash-0.9.9.9
# ./configure
# make && make install
# cd libiconv-1.13
# ./configure
# make && make install
# cd libmcrypt-2.5.8
# ./configure
# make && make install
# cd libltdl/
# ./configure   --with-gmetad --enable-gexec --enable-ltdl-install
# make && make install
3:解压php软件包
# tar -zxf php-5.4.9.tar.gz
php-5.4.9            php-5.4.9.tar.gz
# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/lib/
/usr/local/mysql/include/
# ln -sv /usr/local/lib/libmcrypt*   /usr/lib/
# ln -sv /usr/local/lib/libmhash.*    /usr/lib/
# ln -sv /usr/local/lib/libiconv.*    /usr/lib/
# ldconfig
4:编辑php运行脚本
# cd php-5.4.9
# vim php.sh
./configure --prefix=/usr/local/php5nginx --with-config-file-path=/usr/local/php5nginx/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-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
5:运行脚本及编译安装
# sh php.sh
如果提示configure: error: Cannot find ldap libraries in /usr/lib.错误请执行
cp -frp /usr/lib64/libldap* /usr/lib/
# make ZEND_EXTRA_LIBS='-liconv'
# make
# make install
6:创建主配置文件,并创建测试文件
# cp php.ini-production /usr/local/php5nginx/etc/php.ini
# vim /usr/local/nginx/html/test.php
# ./configure --enable-fpm
7:客户机测试
http://192.168.6.110/test.php    无法显示其内容
五:编译安装nginx + Fast-cgi
1:配置fpm
# cd /usr/local/php5nginx/etc/
# cp php-fpm.conf.default php-fpm.conf
2:启动fpm服务
cd   php-5.4.9/sapi/fpm
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
netstat-utnalp | grep :9000
3:修改nginx主配置文件
vim   nginx.conf
http{
   server    {
       location    /   {
             root   html;
             index   index.phpindex.html;
       }

       location ~ \.php$ {
            root         html;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_indexindex.php;
         fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
         include      fastcgi_params;
         }
   }
}
vim    fastcgi_params
fastcgi_paramSCRIPT_FILENAME      $document_root$fastcgi_script_name;
4:重新加载配置文件
kill-HUP`cat/usr/local/ngin/logs/nginx.pid`
5:进行本地回环测试
elinks   --dump http://localhost/test.php
6:测试php能否连接到mysql数据库服务器上
servicemysqlddstatus
mysql-hlocalhost   -uroot -p123

# cat linkdb.php
<?php
$linkdb=mysql_connect("localhost","root","123");
if($linkdb){
   echo "ok";
}else{
   echo "no";
};

?>
# elinks--dump http://localhost/linkdb.php   
                           ok
六:lnmp+memcached搭建
1、在nginx服务器本机运行memcached服务使用500m物理内存做网站数据缓存
2:解压软件包
tar-zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
3:进行编译安装
./configure
make
make install
echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent.conf
ldconfig -v
tar -zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make
make install
4:配置memcached服务
/usr/local/bin/memcached -u root -m 500m -n 10 -f2-d
netstat -utnalp | grep :11211
5:安装php连接memcached服务连接工具
# /usr/local/php5nginx/bin/phpize Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
6:进行编译及安装
./configure    --with-php-config=/usr/local/php5nginx/bin/php-config
--enable-memcache
make
# make install
Installing shared extensions:   /usr/local/php5nginx/lib/php/extensions/no-debug-non-zts-20100525/
7:修改php主配置文件
vimphp.ini
extension_dir = "/usr/local/php5nginx/lib/php/extensions/no-debug-no   n-zts-20100525/"
extension= "memcache.so"
8:重新启动服务
/etc/init.d/php-fpm stop
/etc/init.d/php-fpm start
9:修改nginx主配置文件
vimnginx.conf
server   {
location / {
            root   html;
            indexindex.php index.html index.htm;
            set$memcached_key$uri;
            memcached_pass 127.0.0.1:11211;
            default_type text/html;
            error_page 404 @fallback;
      }

      location @fallback {
         root   html;
         indexindex.php index.html index.htm;
      }
   location ~ \.php$ {
            root         html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_indexindex.php;
            fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
            include      fastcgi_params;
      }
}
10:重新加载配置文件
kill-HUP`cat/usr/local/ngin/logs/nginx.pid`
11:客户机进行测试
# elinks --dump http://localhost/likdb.php

页: [1]
查看完整版本: LNMP+memcached平台的搭建