分享

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

 悦光阴 2021-07-10

访问Mongodb官网https://www./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 用时 14s

2020-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.conf
about to fork child process, waiting until server is ready for connections.
forked process: 17024
child process started successfully, parent exiting

 

连接mongodb:

[root@guangzhou mongodb]# ./bin/mongo
MongoDB shell version v4.2.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2e0543e1-1f66-44cf-bfd3-3af38f6abe80") }
MongoDB server version: 4.2.9
Server 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 engine
2020-09-29T15:03:49.377+0800 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-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 display
metrics 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 you
and anyone you share the URL with. MongoDB may use this information to make product
improvements 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 admin
switched to db admin
> show databases;
admin   0.000GB
config  0.000GB
local   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 admin
switched to db admin
> db.auth('root','freedom')
1

 

配置service文件:

[root@guangzhou mongodb]# touch /usr/lib/systemd/system/mongod.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/conf/mongodb.conf
User=root
Group=root
PrivateTmp=true
Restart=always
RestartSec=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.conf

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: 25527
9月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting
9月 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: 25527
9月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting
9月 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: 25527
9月 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 -version
MongoDB shell version v4.2.9
git version: 06402114114ffc5146fd4b55402c96f1dc9ec4b5
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_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 mongodb

mongodb

MongoDB support => enabled
MongoDB extension version => 1.7.4
MongoDB extension stability => stable
libbson bundled version => 1.16.2
libmongoc bundled version => 1.16.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
libmongocrypt bundled version => 1.0.3
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto

Directive => Local Value => Master Value
mongodb.debug => no value => no value

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多