设为首页 收藏本站
查看: 1243|回复: 0

LNMP+memcached平台的搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-16 10:28:51 | 显示全部楼层 |阅读模式
实验01:LNMP平台的搭建
实验目标:nginx可以解析php
实验步骤:
一:环境准备
1:准备搭建环境,创建用户
[iyunv@svr110 ~]# useradd www
[iyunv@svr110 ~]# useradd mysql
2:将原有的http网站服务停止并删除原有mysql的主配置文件,停掉mysql服务
3:解压软件包
[iyunv@svr110 ~]# unzip lnmp+memcached.zip
lnmp+memcached               lnmp+memcached.zip
二:安装源码nginx软件包
1:解压软件包
[iyunv@svr110 ~]# cd lnmp+memcached
[iyunv@svr110 lnmp+memcached]# tar -zxf nginx-1.2.0.tar.gz
[iyunv@svr110 lnmp+memcached]# cd nginx-1.2.0
2:编写运行的脚本
[iyunv@svr110 nginx-1.2.0]# 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:运行脚本进行编译及安装
[iyunv@svr110 nginx-1.2.0]# sh nginx.sh
[iyunv@svr110 nginx-1.2.0]# make && make install
4:启动服务,测试
[iyunv@svr110 nginx-1.2.0]# /usr/local/nginx/sbin/nginx
[iyunv@svr110 nginx-1.2.0]# elinks --dump http://127.0.0.1
                               Welcome to nginx!
三:安装源码的mysql软件包
1:解压软件包
[iyunv@svr110 lnmp+memcached]# tar -zxf cmake-2.8.10.2.tar.gz
2:编译安装
[iyunv@svr110 lnmp+memcached]# cd cmake-2.8.10.2
[iyunv@svr110 cmake-2.8.10.2]# ./bootstrap --prefix=/usr/local/cmake
[iyunv@svr110 cmake-2.8.10.2]# make && make install
3:解压mysql软件包
[iyunv@svr110 lnmp+memcached]# tar -zxf mysql-5.5.13.tar.gz
4:编写mysql运行脚本
[iyunv@svr110 lnmp+memcached]# cd mysql-5.5.13
[iyunv@svr110 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:运行脚本,进行编译及安装
[iyunv@svr110 mysql-5.5.13]# sh mysql.sh
[iyunv@svr110 mysql-5.5.13]# make && make install
6:初始化授权库并建立主配置文件
[iyunv@svr110 mysql-5.5.13]# cd /usr/local/mysql/
[iyunv@svr110 mysql]# ./scripts/mysql_install_db --user=mysql
[iyunv@svr110 mysql]# cd /root/lnmp+memcached/mysql-5.5.13
[iyunv@svr110 mysql-5.5.13]# cd support-files/
[iyunv@svr110 support-files]# cp -p my-medium.cnf /etc/my.cnf
7:启动数据库服务,修改密码并测试
[iyunv@svr110 support-files]# /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文件
[iyunv@svr110 support-files]# /usr/local/mysql/bin/mysqladmin -hlocalhost -uroot password "123"
[iyunv@svr110 support-files]# netstat -auntp | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      17806/mysqld        
[iyunv@svr110 support-files]# pkill -9 mysqld
[1]+  已杀死               /usr/local/mysql/bin/mysqld_safe --user=mysql
[iyunv@svr110 support-files]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[iyunv@svr110 support-files]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
8:给源码mysql设置启动脚本
[iyunv@svr110 support-files]# cp -p mysql.server /etc/init.d/mysqldd
[iyunv@svr110 support-files]# chmod +x /etc/init.d/mysqldd
[iyunv@svr110 support-files]# chkconfig --add mysqldd
[iyunv@svr110 support-files]# chkconfig --list mysqldd
mysqldd        0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[iyunv@svr110 support-files]# /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
                                                           [确定]
[1]+  Done                    /usr/local/mysql/bin/mysqld_safe --user=mysql
[iyunv@svr110 support-files]# /etc/init.d/mysqldd restart
MySQL server PID file could not be found!                  [失败]
Starting MySQL..                                           [确定]
四:安装源码php
1:安装扩展
[iyunv@svr110 lnmp+memcached]# tar -zxf mhash-0.9.9.9.tar.gz
[iyunv@svr110 lnmp+memcached]# tar -zxf libiconv-1.13.tar.gz
[iyunv@svr110 lnmp+memcached]# tar -zxf libmcrypt-2.5.8.tar.gz
libiconv-1.13.tar.gz    libiconv-1.13     mhash-0.9.9.9  mhash-0.9.9.9.tar.gz
  libmcrypt-2.5.8    libmcrypt-2.5.8.tar.gz
2:编译安装
[iyunv@svr110 lnmp+memcached]# cd mhash-0.9.9.9
[iyunv@svr110 mhash-0.9.9.9]# ./configure
[iyunv@svr110 mhash-0.9.9.9]# make && make install
[iyunv@svr110 lnmp+memcached]# cd libiconv-1.13
[iyunv@svr110 libiconv-1.13]# ./configure
[iyunv@svr110 libiconv-1.13]# make && make install
[iyunv@svr110 lnmp+memcached]# cd libmcrypt-2.5.8
[iyunv@svr110 libmcrypt-2.5.8]# ./configure
[iyunv@svr110 libmcrypt-2.5.8]# make && make install
[iyunv@svr110 libmcrypt-2.5.8]# cd libltdl/
[iyunv@svr110 libltdl]# ./configure   --with-gmetad --enable-gexec --enable-ltdl-install
[iyunv@svr110 libltdl]# make && make install
3:解压php软件包
[iyunv@svr110 lnmp+memcached]# tar -zxf php-5.4.9.tar.gz
php-5.4.9            php-5.4.9.tar.gz
[iyunv@svr110 lnmp+memcached]# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/lib/
/usr/local/mysql/include/
[iyunv@svr110 lnmp+memcached]# ln -sv /usr/local/lib/libmcrypt*     /usr/lib/
[iyunv@svr110 lnmp+memcached]# ln -sv /usr/local/lib/libmhash.*    /usr/lib/
[iyunv@svr110 lnmp+memcached]# ln -sv /usr/local/lib/libiconv.*    /usr/lib/
[iyunv@svr110 lnmp+memcached]# ldconfig
4:编辑php运行脚本
[iyunv@svr110 lnmp+memcached]# cd php-5.4.9
[iyunv@svr110 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:运行脚本及编译安装
[iyunv@svr110 php-5.4.9]# sh php.sh
如果提示configure: error: Cannot find ldap libraries in /usr/lib.错误请执行
cp -frp /usr/lib64/libldap* /usr/lib/
[iyunv@svr110 php-5.4.9]# make ZEND_EXTRA_LIBS='-liconv'
[iyunv@svr110 php-5.4.9]# make
[iyunv@svr110 php-5.4.9]# make install
6:创建主配置文件,并创建测试文件
[iyunv@svr110 php-5.4.9]# cp php.ini-production /usr/local/php5nginx/etc/php.ini
[iyunv@svr110 php-5.4.9]# vim /usr/local/nginx/html/test.php
[iyunv@svr110 etc]# ./configure --enable-fpm
7:客户机测试
http://192.168.6.110/test.php    无法显示其内容
五:编译安装nginx + Fast-cgi
1:配置fpm
[iyunv@svr110 php-5.4.9]# cd /usr/local/php5nginx/etc/
[iyunv@svr110 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.php  index.html;
       }

       location ~ \.php$ {
            root           html;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
           include        fastcgi_params;
         }
   }
}
vim    fastcgi_params
fastcgi_param  SCRIPT_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数据库服务器上
service  mysqldd  status
mysql  -hlocalhost   -uroot -p123

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

?>
[iyunv@svr110 html]# 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 -f  2  -d
netstat -utnalp | grep :11211
5:安装php连接memcached服务连接工具
[iyunv@svr110 memcache-2.2.5]# /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
[iyunv@svr110 memcache-2.2.5]# make install
Installing shared extensions:     /usr/local/php5nginx/lib/php/extensions/no-debug-non-zts-20100525/
7:修改php主配置文件
vim  php.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主配置文件
vim  nginx.conf
server   {
location / {
            root   html;
            index  index.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;
           index  index.php index.html index.htm;
        }
     location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
}
10:重新加载配置文件
kill  -HUP  `cat  /usr/local/ngin/logs/nginx.pid`
11:客户机进行测试
[iyunv@svr100 php-5.4.9]# elinks --dump http://localhost/likdb.php


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-217648-1-1.html 上篇帖子: centos操作系统搭建Lamp环境(apache php mysql) 下篇帖子: linux单机LAMP环境搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表