2020年10月6日星期二

centos7安装Mongodb4.2.9版本及php扩展

访问Mongodb官网https://www.mongodb.com/try/download/community,右侧有选择项,这里选择centos7+tgz+4.2.9选择项。

[root@guangzhou src]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz--2020-09-29 15:01:18-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz正在解析主机 fastdl.mongodb.org (fastdl.mongodb.org)... 204.246.164.124, 204.246.164.81, 204.246.164.16, ...正在连接 fastdl.mongodb.org (fastdl.mongodb.org)|204.246.164.124|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:132776427 (127M) [application/gzip]正在保存至: "mongodb-linux-x86_64-rhel70-4.2.9.tgz"100%[========================================================================================>] 132,776,427 9.48MB/s 用时 14s2020-09-29 15:01:33 (9.37 MB/s) - 已保存 "mongodb-linux-x86_64-rhel70-4.2.9.tgz" [132776427/132776427])[root@guangzhou src]# tar zxvf mongodb-linux-x86_64-rhel70-4.2.9.tgz[root@guangzhou src]# mv mongodb-linux-x86_64-rhel70-4.2.9 /usr/local/mongodb[root@guangzhou src]# cd /usr/local/mongodb/[root@guangzhou mongodb]# mkdir -p ./data/db[root@guangzhou mongodb]# mkdir log[root@guangzhou mongodb]# mv log logs[root@guangzhou mongodb]# touch ./logs/mongodb.log

新建配置文件:

[root@guangzhou mongodb]# vim mongodb.conf#端口号port=27017#db目录dbpath=/usr/local/mongodb/data/db#日志目录logpath=//usr/local/mongodb/logs/mongodb.log#后台fork=true#日志输出logappend=true#允许远程IP连接bind_ip=0.0.0.0

 

启动mongodb:

[root@guangzhou mongodb]# ./bin/mongod --config mongodb.confabout to fork child process, waiting until server is ready for connections.forked process: 17024child process started successfully, parent exiting

 

连接mongodb:

[root@guangzhou mongodb]# ./bin/mongoMongoDB shell version v4.2.9connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodbImplicit session: session { "id" : UUID("2e0543e1-1f66-44cf-bfd3-3af38f6abe80") }MongoDB server version: 4.2.9Server has startup warnings:2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten]2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten] **   See http://dochub.mongodb.org/core/prodnotes-filesystem2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] **   Read and write access to data and configuration is unrestricted.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] **  We suggest setting it to 'never'2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] **  We suggest setting it to 'never'2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 100001 files. Number of processes should be at least 50000.5 : 0.5 times number of files.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]---Enable MongoDB's free cloud-based monitoring service, which will then receive and displaymetrics about your deployment (disk utilization, CPU, operation statistics, etc).The monitoring data will be available on a MongoDB website with a unique URL accessible to youand anyone you share the URL with. MongoDB may use this information to make productimprovements and to suggest MongoDB products and deployment options to you.To enable free monitoring, run the following command: db.enableFreeMonitoring()To permanently disable this reminder, run the following command: db.disableFreeMonitoring()---#选择数据库> use adminswitched to db admin> show databases;admin 0.000GBconfig 0.000GBlocal 0.000GB
#创建root用户> db.createUser({user:"root",pwd:"freedom",roles:[{role:"userAdminAnyDatabase",db:"admin"},"readWriteAnyDatabase"]})Successfully added user: { "user" : "root", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" }, "readWriteAnyDatabase" ]}

 

断开重联链接输入验证信息:

[root@guangzhou mongodb]# ./bin/mongo> use adminswitched to db admin> db.auth('root','freedom')1

 

配置service文件:

[root@guangzhou mongodb]# touch /usr/lib/systemd/system/mongod.service[Unit]Description=mongodbAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/conf/mongodb.confUser=rootGroup=rootPrivateTmp=trueRestart=alwaysRestartSec=1

 

重启systemd服务,启动mongodb:

[root@guangzhou mongodb]# chmod +x /usr/lib/systemd/system/mongod.service[root@guangzhou mongodb]# systemctl daemon-reload[root@guangzhou ~]# systemctl status mongod● mongod.service - mongodb Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled) Active: active (running) since 二 2020-09-29 15:44:53 CST; 5s ago Process: 25525 ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf (code=exited, status=0/SUCCESS) Main PID: 25527 (mongod) CGroup: /system.slice/mongod.service   └─25527 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf9月 29 15:44:52 guangzhou systemd[1]: Starting mongodb...9月 29 15:44:52 guangzhou mongod[25525]: about to fork child process, waiting until server is ready for connections.9月 29 15:44:52 guangzhou mongod[25525]: forked process: 255279月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting9月 29 15:44:53 guangzhou systemd[1]: Started mongodb.[root@guangzhou ~]# systemctl stop mongod[root@guangzhou ~]# systemctl status mongod● mongod.service - mongodb Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled) Active: inactive (dead)9月 29 15:33:54 guangzhou systemd[1]: Unit mongod.service entered failed state.9月 29 15:33:54 guangzhou systemd[1]: mongod.service failed.9月 29 15:44:52 guangzhou systemd[1]: Starting mongodb...9月 29 15:44:52 guangzhou mongod[25525]: about to fork child process, waiting until server is ready for connections.9月 29 15:44:52 guangzhou mongod[25525]: forked process: 255279月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting9月 29 15:44:53 guangzhou systemd[1]: Started mongodb.9月 29 15:45:04 guangzhou systemd[1]: Stopping mongodb...9月 29 15:45:04 guangzhou mongod[25625]: killing process with pid: 255279月 29 15:45:05 guangzhou systemd[1]: Stopped mongodb.

 客户端快捷方式创建:

[root@guangzhou mongodb]# ln -s /usr/local/mongodb/bin/mongo /usr/local/bin/mongo[root@guangzhou mongodb]# mongo -versionMongoDB shell version v4.2.9git version: 06402114114ffc5146fd4b55402c96f1dc9ec4b5OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013allocator: tcmallocmodules: nonebuild environment:distmod: rhel70distarch: x86_64target_arch: x86_64

 开机启动mongodb:   systemctl enable mongod

手动启动mongodb:systemctl start mongod

停止mongodb:   systemctl stop mongod

查看运行状态:  systemctl status mongod

 

安装Mongodb的php扩展:

[root@guangzhou src]# wget https://pecl.php.net/get/mongodb-1.7.4.tgz[root@guangzhou src]# tar -zxvf mongodb-1.7.4.tgz && cd mongodb-1.7.4/[root@guangzhou mongodb-1.7.4]# /usr/local/php/bin/phpize[root@guangzhou mongodb-1.7.4]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@guangzhou mongodb-1.7.4]# make && make install[root@guangzhou mongodb-1.7.4]# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/总用量 36028-rwxr-xr-x 1 root root 602416 1月 30 2020 amqp.so-rwxr-xr-x 1 root root 377328 12月 1 2019 curl.so-rwxr-xr-x 1 root root 892016 12月 20 2019 event.so-rwxr-xr-x 1 root root 2754408 7月 26 19:12 intl.so-rwxr-xr-x 1 root root 5779432 10月 5 17:15 mongodb.so-rwxr-xr-x 1 root root 658504 12月 1 2019 mysqli.so-rwxr-xr-x 1 root root 4238372 11月 26 2019 opcache.a-rwxr-xr-x 1 root root 2292240 11月 26 2019 opcache.so-rwxr-xr-x 1 root root 2554184 12月 21 2019 redis.so-rwxr-xr-x 1 root root 15008632 12月 1 2019 swoole.so-rwxr-xr-x 1 root root 1712352 9月 23 18:27 swoole_tracker.so[root@guangzhou mongodb-1.7.4]# vim /etc/php.ini#新增配置extension=mongodb.so[root@guangzhou mongodb-1.7.4]# php --ri mongodbmongodbMongoDB support => enabledMongoDB extension version => 1.7.4MongoDB extension stability => stablelibbson bundled version => 1.16.2libmongoc bundled version => 1.16.2libmongoc SSL => enabledlibmongoc SSL library => OpenSSLlibmongoc crypto => enabledlibmongoc crypto library => libcryptolibmongoc crypto system profile => disabledlibmongoc SASL => disabledlibmongoc ICU => disabledlibmongoc compression => enabledlibmongoc compression snappy => disabledlibmongoc compression zlib => enabledlibmongocrypt bundled version => 1.0.3libmongocrypt crypto => enabledlibmongocrypt crypto library => libcryptoDirective => Local Value => Master Valuemongodb.debug => no value => no value

 

原文转载:http://www.shaoqun.com/a/479844.html

好东东网:https://www.ikjzd.com/w/1238

中国邮政邮乐网:https://www.ikjzd.com/w/1776

笨鸟海淘:https://www.ikjzd.com/w/1550


访问Mongodb官网https://www.mongodb.com/try/download/community,右侧有选择项,这里选择centos7+tgz+4.2.9选择项。[root@guangzhousrc]#wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz--2020-09-2915:0
亚马逊礼品卡:https://www.ikjzd.com/w/1090.html
拍怕:https://www.ikjzd.com/w/2205
超值装-亚马逊关键词-全网关键词查询工具大全:https://www.ikjzd.com/tl/98646
12国买家谈判技巧风格大总结!:https://www.ikjzd.com/home/130746
国务院:中小微企业三项社保免征5个月!:https://www.ikjzd.com/home/116177

没有评论:

发表评论