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

源码包搭建LNMP+Memcached平台

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-5-28 08:39:26 | 显示全部楼层 |阅读模式
                      此实验在一台服务器上完成,IP为192.168.100.1

一.用源码包搭建LNMP网站运行平台
1.安装依赖包软件,停止rpm包apache和mysql服务
# yum -y groupinstall "Development libraries" "Development tools" "X Software Development"
# yum -y install gcc gcc-c++ make
# yum -y install openssl openssl-devel pcre pcre-devel
# service httpd stop;chkconfig httpd off
# service mysqld stop;chkconfig mysqld off

2.安装Nginx
# useradd -M -s /sbin/nologin nginx
# tar -zxvf nginx-1.2.0.tar.gz
# cd nginx-1.2.0
# ./configure \
--prefix=/usr/local/nginx \
--pid-path=/usr/local/nginx/nginx.pid \
--user=nginx --group=nginx \
--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

# make
# make install

3.启动nginx 服务
# /usr/local/nginx/sbin/nginx  -t
# /usr/local/nginx/sbin/nginx
# netstat -tunalp | grep :80
tcp 0 0 0.0.0.0:80  0.0.0.0:*  LISTEN  32428/nginx

4.在本机测试是否能访问
elinks --dump http://localhost

5.安装mysql(选用5.5.13版本的源码包安装,此版本需要cmake编译工具)

5.1安装cmake 编译工具
# tar -zxvf cmake-2.8.10.2.tar.gz
# cd cmake-2.8.10.2
# ./bootstrap --prefix=/usr/local/cmake
# make
# make  install
# /usr/local/cmake/bin/cmake --version
ncmake version 2.8.10.2

5.2安装源码包mysql
# mv /etc/my.cnf /etc/my.cnf.old
# useradd -M -s /sbin/nlogin mysql
# tar -zxvf mysql-5.5.13.tar.gz
# cd mysql-5.5.13
# /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

# make  
# make install

5.3初始化mysql授权库
# chown -R mysql:mysql /usr/local/mysql/
# cd /usr/local/mysql/
# ./scripts/mysql_install_db --user=mysql     //初始化mysql授权库         
# ls /usr/local/mysql/data/mysql             //产生授权库,则初始化成功

5.4创建主配置文件
# cd mysql-5.5.13
# cp support-files/my-medium.cnf /etc/my.cnf   

5.5添加为系统服务并启动源码数据库服务
# cd mysql-5.5.13
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# service mysqld start

5.6把源码mysql命令所在的路径添加到系统环境变量PATH里
# PATH=/usr/local/mysql/bin/:$PATH
# vim /etc/bashrc
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/
export PATH

5.7设置数据库管理员从本机登录的密码
# mysqladmin -uroot password "123456"   

5.8测试用数据库管理员root在本机登录
# mysql -uroot -p123456
# mysql>

5.9指定mysql库文件的位置   
# vim /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/mysql/lib/             //添加库文件的位置
# ldconfig -v                   //加载库文件

6.安装源码php
6.1安装php的扩展软件(mhash libiconv libmcrypt libltdl)
# tar -zxvf mhash-0.9.9.9.tar.gz   //哈希函数库
# cd mhash-0.9.9.9
# ./configure
# make
# make install

# tar -zxvf libiconv-1.13.tar.gz      //处理中文各种编码之间的转换
# cd libiconv-1.13
# ./configure
# make
# make install

# tar -zxvf libmcrypt-2.5.8.tar.gz     //提供加密功能的库文件
# cd libmcrypt-2.5.8
# ./configure
# make
# make install
# cd libltdl
# ./configure --with-gmetad --enable-gexec --enable-ltdl-install
# make
# make install


6.2指定扩展包库文件的位置
# ln -sv /usr/local/lib/libmcrypt* /usr/lib/
# ln -sv /usr/local/lib/libmhash.* /usr/lib/
# ldconfig -v

6.3安装源码包php
# tar -zxvf php-5.4.9.tar.gz
# cd php-5.4.9
# ./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 \

# make ZEND_EXTRA_LIBS='-liconv'
# make install

6.4创建php的主配置文件php.ini
# cd php-5.4.9
# cp php.ini-production /usr/local/php5nginx/etc/php.ini


二.整合Nginx和Fast-cgi               
1.配置Fast-cgi
# cd /usr/local/php5nginx/etc
# cp php-fpm.conf.default php-fpm.conf   //生成配置文件
# vim php-fpm.conf                    //根据需求编辑配置文件
……
listen = 127.0.0.1:9000        //默认监听9000端口
pm = dynamic
pm.max_children = 5      
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
……

2.启动php-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
# chkconfig --add php-fpm
# service php-fpm start
# netstat -utnlap | grep :9000

3.编辑nginx.conf文件
# vim /usr/local/nginx/conf/nginx.conf
……
    location / {
    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;
    }
……

4.编辑fastcgi_params文件
# vim /usr/local/nginx/conf/fastcgi_params
……
fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
……

5.重启nginx服务
# /usr/local/nginx/sbin/nginx -t  
# /usr/local/nginx/sbin/nginx -s stop
# /usr/local/nginx/sbin/nginx

6.测试nginx能否识别php网页
# vim /usr/local/nginx/html/test.php   //制作测试网页
<?php
    phpinfo( );
?>

浏览器访问 http://192.168.100.1/test.php      


7.测试php能否连接mysql数据库服务
# cd /usr/local/php5nginx/bin/
./php -m | grep --color mysql

# vim /usr/local/nginx/html/linkdb.php        //制作测试网页
<?php
    $link=mysql_connect("192.168.100.1","root","123456");
    if($link){
        echo "db link ok";
    }else{
       echo "db link no";
    }
?>

客户端访问 http://192.168.100.1/linkdb.php


三.LNMP+Memcached
1.在当前服务器上搭建memcached服务
1.1安装事件库程序
# tar -zxvf libevent-2.0.21-stable.tar.gz       //事件库
# cd libevent-2.0.21-stable
# ./configure
# make
# make install

1.2指定库文件位置
# echo /usr/local/lib/ > /etc/ld.so.conf.d/libevent.conf
# ldconfig -v

1.3安装memcached
# tar -zxvf memcached-1.4.5.tar.gz
# cd memcached-1.4.5
# ./configure
# make
# make install

1.4启动memcached服务
# /usr/local/bin/memcached -l 192.168.100.1 -u root -m 200 -c 200 -n 10 -f 2 -d -vvv
# netstat -tulnp | grep :11211


2.安装php连接memcached服务器的工具
2.1安装memcache
# tar -zxvf memcache-2.2.5.tgz
# cd  memcache-2.2.5
# /usr/local/php5nginx/bin/phpize
# ./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/           //提示模块存放目录


2.2编辑php程序的配置文件,指定模块的位置
# vim /usr/local/php5nginx/etc/php.ini
……
extension_dir = "/usr/local/php5nginx/lib/php/extensions/no-debug-non-zts-20100525/"
extension = memcache.so                      //加载模块         
……
2.3重启php-fpm
# service php-fpm restart

3.查看php是否支持memcached
# /usr/local/php5nginx/bin/php -m | grep --color memcache

4.测试php能从memcahed里存取数据。
# vim /usr/local/nginx/html/mem.php         //制作测试网页
<?php
    $memcache=new Memcache;                          //创建memcache对象
    $memcache->connect('192.168.100.1',11211) or die ('could not connect!!'); //连接    memcached服务器
    $memcache->set('key','jin');                      //定义变量
    $get_values=$memcache->get('key');               //获取变量值
    echo $get_values;
?>

客户端访问 http://192.168.100.1/mem.php   在网页上显示jin则表示测试成功

5.Nginx整合Memcached
当nginx服务器接收到访问.php文件时,先访问memcached服务器,在memcached服务器里没找到时,在到网站服务器上去找。

# vim /usr/local/nginx/conf/nginx.conf
Server {
server_name www.jinjianjun.com;                          //nginx服务器主机名
    location / {
......
    set $memcached_key $uri;                    //用uri路径定义变量
    memcached_pass 127.0.0.1:11211;           //把请求发给memcached服务器
    default_type text/html;
    error_page 404 @fallback;                 //请求跳转标记
    }
    location @fallback {
    proxy_pass http://servergroup;       //服务器组名,若转给某台nginx服务器,如本机也可写成proxy_pass http://192.168.100.1:80
    }
}

6.重启nginx服务
# ./sbin/nginx  -t
# ./sbin/nginx  -s  stop
# ./sbin/nginx

                   


运维网声明 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-19767-1-1.html 上篇帖子: LNMP基于fastcgi实现nginx,php,mysql的分离安装部署 下篇帖子: CentOS环境下yum安装LAMP(Linux+Apache+Mysql+php)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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