lnmp 用mongo

发布时间:2020-05-13 23:26:46 作者:北极苍雪
来源:网络 阅读:720

本操作是针对与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++


//下载各个安装包

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

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

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

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

jpegsrchttp://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());

}


?>







[root@test001 ~]# 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




[root@test002 /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

[root@test002 /]# 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个包的那个稳定版的

[root@test001 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


推荐阅读:
  1. CentOS7部署LNMP+Mongodb环境
  2. nginx监控及lnmp架构

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mongodb nm

上一篇:预防域名dns劫持和解决

下一篇:在Android Studio中给应用创建签名

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》