首页 > 代码库 > LNMMP平台搭建
LNMMP平台搭建
拓扑
1) Nginx及的编译及安装
参考Nginx基本使用一文,同时在编译时一定要加入
2) 编译安装MariaDB
#添加用户 useradd -r mysql #安装并提供配置文件和启动脚本 tar xvf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/ cd /usr/local/ ln -s mariadb-10.0.10-linux-x86_64/ mysql mkdir /etc/mysql scp support-files/my-large.cnf /etc/mysql/my.cnf scp support-files/mysql.server /etc/init.d/mysqld #更改目录权限 chown -R nginx.mysql ./* chown -R mysql.mysql data #初始化数据库 scripts/mysql_install_db #启动服务并提供具有权限的用户 MariaDB [(none)]> grant all on *.* to ‘test‘@‘172.16.21.%‘ identified by ‘123456‘; Query OK, 0 rows affected (0.05 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec)
3) 编译安装php
#解决依赖关系 yum install bzip2-devel libmcrypt-devel libcurl-devel #解压并安装php tar xf php-5.4.26.tar.bz2 -C /usr/local/src/ cd /usr/local/src/php-5.4.26/ ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/local/libxml --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 make && make install #提供脚本启动文件和配置文件 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/src/php-5.4.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #启动服务 service php-fpm start Starting php-fpm done ss -tnl |grep 9000 LISTEN 0 128 127.0.0.1:9000 *:*
4) 为php提供xcache加速
[root@stu21 ~]# tar xf xcache-3.1.0.tar.bz2 -C /usr/local/src [root@stu21 ~]# cd /usr/local/src/xcache-3.1.0 [root@stu21 xcache-3.1.0]# /usr/local/php/bin/phpize [root@stu21 xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config [root@stu21 xcache-3.1.0]# make && make install [root@stu21 xcache-3.1.0]# mkdir /etc/php.d [root@stu21 xcache-3.1.0]# cp xcache.ini /etc/php.d/ [root@stu21 xcache-3.1.0]# service php-fpm restaret
5) 配置nginx为php的反向代理
编辑nginx配置文件,开启如下选项
index index.php index.html index.htm; #在index选项后加入index.php 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; }
编辑/etc/nginx/fastcgi_params文件
[root@lab1 xcache-3.1.0]# cat /etc/nginx/fastcgi_params 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; #提供php测试页面 [root@lab1 html]# cat index.php <?php phpinfo(); ?> #访问测试
#而且xcache已经成功安装
6) 安装memcached
[root@lab3 ~]# tar xvf memcached-1.4.15.tar.gz -C /usr/local/src/ [root@lab3 ~]# cd /usr/local/src/memcached-1.4.15 [root@lab3 memcached-1.4.15]# ls aclocal.m4 COPYING memcached_dtrace.d solaris_priv.c assoc.c daemon.c memcached.h stats.c assoc.h depcomp memcached.spec stats.h AUTHORS doc missing t cache.c hash.c NEWS testapp.c cache.h hash.h protocol_binary.h thread.c ChangeLog install-sh README.md timedrun.c compile items.c sasl_defs.c trace.h config.guess items.h sasl_defs.h util.c config.h.in m4 scripts util.h config.sub Makefile.am sizes.c version.m4 configure Makefile.in slabs.c configure.ac memcached.c slabs.h [root@lab3 memcached-1.4.15]# ./configure --prefix=/usr/local/memcached [root@lab3 memcached-1.4.15]#make && make install #安装后配置 [root@lab3 memcached-1.4.15]# echo "export PATH=/usr/local/memcached/bin:$PATH" > /etc/profile.d/memcache.sh [root@lab3 memcached-1.4.15]# . /etc/profile.d/memcache.sh [root@lab3 memcached-1.4.15]# echo "MANPATH /usr/local/memcached/share/man" >> /etc/man.config [root@lab3 memcached-1.4.15]# ln -s include/memcached /usr/include/memcache [root@lab3 memcached-1.4.15]# useradd -r memcached [root@lab3 memcached-1.4.15]# memcached -u memcached
6)为php安装memached模块
[root@lab1 php]# tar xf memcache-2.2.7.tgz -C /usr/local/src/ [root@lab1 php]# cd /usr/local/src/memcache-2.2.7/ [root@lab1 memcache-2.2.7]# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@lab1 memcache-2.2.7]# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache #在php的配置文件php.ini中加入如下内容 extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so #添加测试页面memtest.php [root@lab1 memcache-2.2.7]# cat /usr/local/nginx/html/memtest.php <?php $mem = new memcache; $mem->connect("172.16.21.103", 11211) or die("Could not connect"); $version = $mem->getVersion(); echo "Server‘s version: ".$version."<br/>\n"; $mem->set(‘hellokey‘, ‘Hello World‘, 0, 600) or die("Failed to save data at the memcached server"); echo "Store data in the cache (data will expire in 600 seconds)<br/>\n"; $get_result = $mem->get(‘hellokey‘); echo "$get_result is from memcached server."; ?>
#访问结果如下:
#在memcached查看如下
[root@lab3 ~]# telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is ‘^]‘. get hellokey VALUE hellokey 0 11 Hello World END
此时,我们的LNMMP已经搭建完成
LNMMP平台搭建
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。