lnmp 用mongo

本操作是针对与centos7.2 进行的安装服务,和环境配置,用mongodb代替mysql进行的lnmp安装

---------------------------------------------------------------------------------------

php

----------------------------------------------------------------------------------------

//添加用户

useradd -M -s /sbin/nologin php

//安装编译工具及库文件

yum install -y zlib-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel curl curl-devel

yum install -y openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel libmcrypt

yum install -y libmcrypt-devel yasm yasm-devel

yum install -y gcc+ gcc-c++

//下载各个安装包

libpng http://downloads.sourceforge.net/libpng/libpng-1.6.16.tar.xz

gd https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

tiff http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

freetype http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz

jpegsrc http://www.ijg.org/files/jpegsrc.v9a.tar.gz

//安装tiff

./configure --prefix=/usr/local/tiff --enable-shared

make && make install

//安装libpng

cd libpng-1.6.16

./configure --prefix=/usr/local/libpng --enable-shared

make && make install

//安装freetype

cd freetype-2.4.0

./configure --prefix=/usr/local/freetype

make && make install

//安装jpeg

cd jpeg-v9a

./configure --prefix=/usr/local/jpeg --enable-shared

make && make install

//安装libgd

cd libgd-2.1.0

./configure \

--prefix=/usr/local/libgd \

--enable-shared \

--with-jpeg=/usr/local/jpeg \

--with-png=/usr/local/libpng \

--with-freetype=/usr/local/freetype \

--with-fontconfig=/usr/local/freetype \

--with-xpm=/usr/ \

--with-tiff=/usr/local/tiff

make && make install

//安装php的准备(只有64位机器才用得到)

cp -frp /usr/lib64/libltdl.so* /usr/lib/

cp -frp /usr/lib64/libXpm.so* /usr/lib/

//安装php

export LD_LIBRARY_PATH=/usr/local/libgd/lib

cd php-5.6.16

./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-mysql-sock=/tmp/mysqld.sock \

--with-pdo-mysql=mysqlnd \

--with-png-dir=/usr/local/libpng \

--with-gd \

--with-jpeg-dir=/usr/local/jpeg \

--with-freetype-dir=/usr/local/freetype \

--with-xpm-dir=/usr/ \

--with-mcrypt \

--with-zlib \

--with-iconv \

--enable-libxml \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--enable-opcache \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--enable-ftp \

--enable-gd-native-ttf \

--with-openssl \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--without-pear \

--with-gettext \

--enable-session \

--with-curl \

--enable-ctype \

--disable-ipv6 \

--disable-short-tags

make && make install

//后续处理

cp php.ini-production /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

vi /usr/local/php/etc/php-fpm.conf

pid = run/php-fpm.pid //去除左侧分号

进行以下设置:

这个默认是在/usr/loccal/php/etc/php-fpm.d/www.php-fpm.conf

user = php

group = php

pid = run/php-fpm.pid //去除左侧分号

wq!

//添加开机启动

cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php

chmod +x /etc/rc.d/init.d/php

chkconfig php on

---------------------------------------------------------------------

*****************yum 安装nginx 或者编译安装nginx

---------------------------------------------------------------------

http://www.nginx.org   在 downloads里面的底部有个一个文件可以写进.repo的那种

弄好之后直接yum安装,

nginx如果是编译安装的话,在你下载网络源的那一页有./configure 后面的参数,或者自行找文档

php 和  nginx 链接好

sudo yum install -y mongodb-enterprise   这个大概会安装10个软件包,有5个是以前yun源指定,这里我还没写,

剩下的5个应该是支持mongod某些特性的软件包

这5个包是:mongodb-enterprise,

mongodb-enterprise-server,

mongodb-enterprise-shell,

mongodb-enterprise-mongos,

mongodb-enterprise-tools

11个包是:

(1/11): cyrus-sasl-gssapi-2.1.26-19.2.el7.x86_64.rpm                                       |  41 kB  00:00:00

(2/11): lm_sensors-libs-3.3.4-11.el7.x86_64.rpm                                            |  40 kB  00:00:00

(3/11): cyrus-sasl-plain-2.1.26-19.2.el7.x86_64.rpm                                        |  38 kB  00:00:00

(4/11): mongodb-enterprise-3.2.1-1.el7.x86_64.rpm                                          | 5.9 kB  00:00:02

(5/11): mongodb-enterprise-mongos-3.2.1-1.el7.x86_64.rpm                                   | 5.4 MB  00:01:06

(6/11): mongodb-enterprise-shell-3.2.1-1.el7.x86_64.rpm                                    | 7.0 MB  00:01:14

(7/11): net-snmp-5.7.2-24.el7.x86_64.rpm                                                   | 321 kB  00:00:00

(8/11): net-snmp-agent-libs-5.7.2-24.el7.x86_64.rpm                                        | 702 kB  00:00:00

(9/11): net-snmp-libs-5.7.2-24.el7.x86_64.rpm                                              | 747 kB  00:00:00

(10/11): mongodb-enterprise-server-3.2.1-1.el7.x86_64.rpm                                  |  12 MB  00:02:19

(11/11): mongodb-enterprise-tools-3.2.1-1.el7.x86_64.rpm

-------------------------------

*********mongodb3.2

--------------------------------

首先先要看一下有没有mysql安装这,rpm -qa | grep mysql

yum remove mysql-libs*

yum install perl cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \

lm_sensors net-snmp openssl popt rpm-libs tcp_wrappers zlib

yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \

net-snmp openssl

yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs \

lm_sensors-libs net-snmp-agent-libs net-snmp openssl rpm-libs \

tcp_wrappers-libs

mongd32.repo   (这个会更好点儿)  企业版,收费的

[mongodb-enterprise]

name=MongoDB Enterprise Repository

baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/

gpgcheck=0

enabled=1

另一个这个会安装5个包    社区版

[mongodb-org-3.2]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/

gpgcheck=0

enabled=1

((((如果要是删除mongodb    sudo yum erase $(rpm -qa | grep mongodb-enterprise)

sudo rm -r /var/log/mongodb

sudo rm -r /var/lib/mongo

)))))))

*********重头戏,这里,需要php与mongod连接的时候,需要有驱动http://www.cnblogs.com/chengmo/archive/2010/06/28/1766959.html

cd /usr/local/php/

wget  http://pear.php.net/go-pear.phar

bin/php go-pear.phar  按照导向选择安装位置,这里保持默认即可   ,这样之后就有了pecl命令了,在php的bin下面

bin/pecl install mongodb

vim etc/php.ini   写入extension=mongodb.so

要重启一下php-fpm 就可以了

这个是测试php与mongod是否连通的 (一个连通,一个插入数据)

<?php

$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

var_dump($manager);

?>

<?php

$bulk = new MongoDB\Driver\BulkWrite();

$bulk->insert([‘_id‘ => 1, ‘x‘ => 1]);

$bulk->insert([‘_id‘ => 2, ‘x‘ => 2]);

$bulk->update([‘x‘ => 2], [‘$set‘ => [‘x‘ => 1]], [‘multi‘ => false, ‘upsert‘ => false]);

$bulk->update([‘x‘ => 3], [‘$set‘ => [‘x‘ => 3]], [‘multi‘ => false, ‘upsert‘ => true]);

$bulk->update([‘_id‘ => 3], [‘$set‘ => [‘x‘ => 3]], [‘multi‘ => false, ‘upsert‘ => true]);

$bulk->insert([‘_id‘ => 4, ‘x‘ => 2]);

$bulk->delete([‘x‘ => 1], [‘limit‘ => 1]);

$manager = new MongoDB\Driver\Manager(‘mongodb://localhost:27017‘);

$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);

$result = $manager->executeBulkWrite(‘db.collection‘, $bulk, $writeConcern);

printf("Inserted %d document(s)\n", $result->getInsertedCount());

printf("Matched  %d document(s)\n", $result->getMatchedCount());

printf("Updated  %d document(s)\n", $result->getModifiedCount());

printf("Upserted %d document(s)\n", $result->getUpsertedCount());

printf("Deleted  %d document(s)\n", $result->getDeletedCount());

foreach ($result->getUpsertedIds() as $index => $id) {

printf(‘upsertedId[%d]: ‘, $index);

var_dump($id);

}

/* If the WriteConcern could not be fulfilled */

if ($writeConcernError = $result->getWriteConcernError()) {

printf("%s (%d): %s\n", $writeConcernError->getMessage(), $writeConcernError->getCode(), var_export($writeConcernError->getInfo(), true));

}

/* If a write could not happen at all */

foreach ($result->getWriteErrors() as $writeError) {

printf("Operation#%d: %s (%d)\n", $writeError->getIndex(), $writeError->getMessage(), $writeError->getCode());

}

?>

[[email protected] ~]# cat /lib/systemd/system/php-fpm.service

[Install]

WantedBy=multi-user.target

[Unit]

Description=The PHP FastCGI Process Manager

After=syslog.target network.target

[Service]

Type=forking

PIDFile=/usr/local/php/var/run/php-fpm.pid

ExecStart=/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf

ExecReload=/bin/kill -USR2 $MAINPID

[[email protected] /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

[[email protected] /]# echo never > /sys/kernel/mm/transparent_hugepage/defrag

vi /usr/lib/systemd/system/nginx.service

[Unit]

Desciption=nginx

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStart=/usr/local/nginx/sbin/nginx

ExecStop=/usr/local/nginx/sbin/nginx -s stop

ExecReload=/usr/local/nginx/sbin/nginx -s reload

[Install]

WantedBy=multi-user.target

//开机启动

systemctl enable nginx

接下来是mongod的开机自启动,这个是安装了11个包的那个稳定版的

[[email protected] web]# cat /lib/systemd/system/mongod.service

# Automatically generated by systemd-sysv-generator

[Unit]

Documentation=man:systemd-sysv-generator(8)

SourcePath=/etc/rc.d/init.d/mongod

Description=SYSV: Mongo is a scalable, document-oriented database.

Before=runlevel3.target runlevel5.target shutdown.target

After=network-online.target network.service

Conflicts=shutdown.target

[Service]

Type=forking

Restart=no

TimeoutSec=5min

IgnoreSIGPIPE=no

KillMode=process

GuessMainPID=no

RemainAfterExit=no

PIDFile=/var/run/mongodb/mongod.pid

ExecStart=/etc/rc.d/init.d/mongod start

ExecStop=/etc/rc.d/init.d/mongod stop

ExecReload=/etc/rc.d/init.d/mongod reload

时间: 2025-01-15 22:23:14

lnmp 用mongo的相关文章

php扩展的安装及连接mongo测试

系统:centos6.5 mongodb版本:Current Stable Release (3.0.6) 先到官网下载mongodb https://www.mongodb.org/downloads 选择linux下的RHEL6版本,根据系统确定. 我这里下载的文件名为mongodb-linux-x86_64-rhel62-3.0.5 的二进制文件包 把上面的文件放到/mydata下 解压为mongo文件夹 [[email protected] mydata]# tar zxvf mongo

CentOS下Web服务器环境搭建LNMP一键安装包

时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp-2.5 更新时间:20140822 MD5值:5CA8E1688BA6830CF05357068C384A1A 安装说明:请保证服务器能够正常上网.yum命令可以正常使用! 1.wget http://www.osyunwei.com/lnmp/lnmp-2.5.tar.gz #下载,需要先执行yum install wget安装下载工具 2.tar

CentOS7.1编译安装LNMP

系统CentOS7.1链接 http://mirrors.sohu.com/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso   md5值: d07ab3e615c66a8b2e9a50f4852e6a77  CentOS-7-x86_64-Minimal-1503-01.iso 系统为最小化安装,版本号: nginx:1.6.3 mysql:5.5.37 php:5.3.28 下面shell,没有多的版本判断设置,可

Mac下用brew搭建LNMP和LAMP开发环境

Mac下搭建lamp开发环境很容易,有xampp和mamp现成的集成环境.但是集成环境对于经常需要自定义一些配置的开发者来说会非常麻烦,而且Mac本身自带apache和php,在brew的帮助下非常容易手动搭建,可控性很高 Brew brew对于mac,就像apt-get对于ubuntu,安装软件的好帮手,不能方便更多- brew的安装方式如下: ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

Docker学习笔记——Mongo Dockerfile及容器运行

1.创建项目目录mongo,在目录下上传下载的Mongodb安装文件及mongo.conf配置文件,创建Dockerfile文件,项目结构如下: mongo - Dockerfile - mongo.conf - mongodb-linux-x86_64-3.4.9.tgz - data - logs Dockerfile内容如下: # mongo # SOURCE_IMAGE FROM centos # MAINTAINER_INFO MAINTAINER bluemooder [email 

linux运维、架构之路-Lnmp架构部署

一.Lnmp架构原理 二. Lnmp架构软件安装 1.Nginx安装脚本 #!/bin/bash useradd -s /sbin/nologin -M www mkdir -p /server/tools/ cd /server/tools/ wget http://nginx.org/download/nginx-1.10.3.tar.gz tar xf nginx-1.10.3.tar.gz yum install pcre-devel openssl-devel -y cd /home/

lnmp脚本

#!/bin/bash#Function: Install LNMP#Author: wang#Date: 20170809 nginx_install(){useradd www -u 509 -s /bin/bash -mmkdir -p /opt/server/nginx/temp #Install the make GCCyum -y install gcc gcc-c++ automake autoconf libtool make #Installing PCRE library (

LNMP编译安装遇到问题归总

LNMP编译安装遇到问题归总 1.错误:configure: error: freetype-config not found. 解决:yum install freetype-devel 2.错误:configure: error: libevent >= 1.4.11 could not be found  解决:yum -y install libevent libevent-devel 3.错误:configure: error: Please reinstall the mysql d

Python实现一键安装部署LNMP环境

最近一直在学Python,东西比较多,时间持续的也比较长,为了能够学以致用,想到了原来写过的shell一键安装部署LNMP脚本,既然shell能写,Python也一定能写,就用学到的知识写了下面这个版本,这可能并不是最优版本,等学到更多东西的时候再进行优化升级! 环境介绍: Python 2.6.6 Centos 6.5 nginx 1.10.1 mysql 5.6.34 php 5.3.3 代码如下: #!/bin/env python import os import sys def ent