环境要求
- centos8
- nodejs(7.6+)
- mongodb(2.6+)
安装nodejs
有一个前期:确保你的yum是可以用的!
yum module list nodejs
sudo yum module install nodejs
node --version
npm -v
[root@localhost ~]# sudo yum module install nodejs
Last metadata expiration check: 0:00:20 ago on Tue 18 May 2021 09:28:34 PM EDT.
Error: Problems in request:
missing groups or modules: nodejs
[root@localhost ~]# npm -v
-bash: npm: command not found
[root@localhost ~]# yum module list nodejs
CentOS Linux 8 - AppStream 2.0 MB/s | 6.3 MB 00:03
CentOS Linux 8 - BaseOS 538 kB/s | 2.3 MB 00:04
CentOS Linux 8 - Extras 8.0 kB/s | 9.6 kB 00:01
CentOS Linux 8 - AppStream
Name Stream Profiles Summary
nodejs 10 [d] common [d], development, minimal, s2i Javascript runtime
nodejs 12 common [d], development, minimal, s2i Javascript runtime
nodejs 14 common [d], development, minimal, s2i Javascript runtime
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@localhost ~]# sudo yum module install nodejs
Last metadata expiration check: 0:01:42 ago on Tue 18 May 2021 09:40:47 PM EDT.
Dependencies resolved.
===============================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================
Installing group/module packages:
nodejs x86_64 1:10.24.0-1.module_el8.3.0+717+fa496f1d appstream 8.8 M
npm x86_64 1:6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d appstream 3.7 M
Installing weak dependencies:
nodejs-full-i18n x86_64 1:10.24.0-1.module_el8.3.0+717+fa496f1d appstream 7.3 M
Installing module profiles:
nodejs/common
Enabling module streams:
nodejs 10
Transaction Summary
===============================================================================================================================================================
Install 3 Packages
Total download size: 20 M
Installed size: 71 M
Is this ok [y/N]: y
Is this ok [y/N]: y
Downloading Packages:
[MIRROR] nodejs-full-i18n-10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64.rpm: Curl error (7): Couldn't connect to server for http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/nodejs-full-i18n-10.24.0-1.module_el8.3.0%2b717%2bfa496f1d.x86_64.rpm [Failed to connect to mirror.centos.org port 80: Connection refused]
(1/3): npm-6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d.x86_64.rpm 174 kB/s | 3.7 MB 00:21
[MIRROR] nodejs-10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64.rpm: Curl error (28): Timeout was reached for http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/nodejs-10.24.0-1.module_el8.3.0%2b717%2bfa496f1d.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] nodejs-full-i18n-10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64.rpm: Curl error (28): Timeout was reached for http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/nodejs-full-i18n-10.24.0-1.module_el8.3.0%2b717%2bfa496f1d.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
(2/3): nodejs-10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64.rpm 87 kB/s | 8.8 MB 01:44
(3/3): nodejs-full-i18n-10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64.rpm 69 kB/s | 7.3 MB 01:48
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 188 kB/s | 20 MB 01:48
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d.x86_64 1/1
Preparing : 1/1
Installing : nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 1/3
Installing : npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d.x86_64 2/3
Installing : nodejs-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 3/3
Running scriptlet: nodejs-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 3/3
Verifying : nodejs-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 1/3
Verifying : nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 2/3
Verifying : npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d.x86_64 3/3
Installed products updated.
Installed:
nodejs-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64 nodejs-full-i18n-1:10.24.0-1.module_el8.3.0+717+fa496f1d.x86_64
npm-1:6.14.11-1.10.24.0.1.module_el8.3.0+717+fa496f1d.x86_64
Complete!
[root@localhost ~]# node -v
v10.24.0
[root@localhost ~]# npm -v
6.14.11
安装MongoDB
1.在/etc/yum.repo.d目录中创建一个回购文件,以在CentOS 8服务器中安装MongoDB yum存储库。
2.使用yum命令安装
sudo yum install -y mongodb-org #安装命令
MongoDB Repository 10 kB/s | 22 kB 00:02
Dependencies resolved.
===============================================================================================================================================================
Package Architecture Version Repository Size
===============================================================================================================================================================
Installing:
mongodb-org x86_64 4.4.6-1.el8 mongodb-org-4.4 11 k
Installing dependencies:
cyrus-sasl x86_64 2.1.27-5.el8 baseos 96 k
mongodb-database-tools x86_64 100.3.1-1 mongodb-org-4.4 54 M
mongodb-org-database-tools-extra x86_64 4.4.6-1.el8 mongodb-org-4.4 23 k
mongodb-org-mongos x86_64 4.4.6-1.el8 mongodb-org-4.4 17 M
mongodb-org-server x86_64 4.4.6-1.el8 mongodb-org-4.4 22 M
mongodb-org-shell x86_64 4.4.6-1.el8 mongodb-org-4.4 14 M
mongodb-org-tools x86_64 4.4.6-1.el8 mongodb-org-4.4 11 k
python3-pip noarch 9.0.3-18.el8 appstream 20 k
python3-setuptools noarch 39.2.0-6.el8 baseos 163 k
python36 x86_64 3.6.8-2.module_el8.3.0+562+e162826a appstream 19 k
Enabling module streams:
python36 3.6
Transaction Summary
===============================================================================================================================================================
Install 11 Packages
Total download size: 106 M
Installed size: 342 M
Downloading Packages:
(1/11): python3-pip-9.0.3-18.el8.noarch.rpm 75 kB/s | 20 kB 00:00
(2/11): python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64.rpm 71 kB/s | 19 kB 00:00
(3/11): cyrus-sasl-2.1.27-5.el8.x86_64.rpm 283 kB/s | 96 kB 00:00
(4/11): python3-setuptools-39.2.0-6.el8.noarch.rpm 613 kB/s | 163 kB 00:00
(5/11): mongodb-org-4.4.6-1.el8.x86_64.rpm 14 kB/s | 11 kB 00:00
(6/11): mongodb-org-database-tools-extra-4.4.6-1.el8.x86_64.rpm 29 kB/s | 23 kB 00:00
(7/11): mongodb-org-mongos-4.4.6-1.el8.x86_64.rpm 604 kB/s | 17 MB 00:28
(8/11): mongodb-org-server-4.4.6-1.el8.x86_64.rpm 553 kB/s | 22 MB 00:40
(9/11): mongodb-org-tools-4.4.6-1.el8.x86_64.rpm 40 kB/s | 11 kB 00:00
(10/11): mongodb-org-shell-4.4.6-1.el8.x86_64.rpm 759 kB/s | 14 MB 00:18
(11/11): mongodb-database-tools-100.3.1.x86_64.rpm 1.1 MB/s | 54 MB 00:48
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.2 MB/s | 106 MB 00:48
warning: /var/cache/dnf/mongodb-org-4.4-cef71e585db45e10/packages/mongodb-database-tools-100.3.1.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 90cfb1f5: NOKEY
MongoDB Repository 1.5 kB/s | 1.6 kB 00:01
Importing GPG key 0x90CFB1F5:
Userid : "MongoDB 4.4 Release Signing Key <packaging@mongodb.com>"
Fingerprint: 2069 1EEC 3521 6C63 CAF6 6CE1 6564 08E3 90CF B1F5
From : https://www.mongodb.org/static/pgp/server-4.4.asc
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mongodb-org-shell-4.4.6-1.el8.x86_64 1/11
Running scriptlet: mongodb-org-server-4.4.6-1.el8.x86_64 2/11
Installing : mongodb-org-server-4.4.6-1.el8.x86_64 2/11
Running scriptlet: mongodb-org-server-4.4.6-1.el8.x86_64 2/11
Created symlink /etc/systemd/system/multi-user.target.wants/mongod.service → /usr/lib/systemd/system/mongod.service.
Installing : mongodb-org-mongos-4.4.6-1.el8.x86_64 3/11
Installing : python3-setuptools-39.2.0-6.el8.noarch 4/11
Installing : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 5/11
Running scriptlet: python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 5/11
Installing : python3-pip-9.0.3-18.el8.noarch 6/11
Installing : mongodb-org-database-tools-extra-4.4.6-1.el8.x86_64 7/11
Running scriptlet: cyrus-sasl-2.1.27-5.el8.x86_64 8/11
Installing : cyrus-sasl-2.1.27-5.el8.x86_64 8/11
Running scriptlet: cyrus-sasl-2.1.27-5.el8.x86_64 8/11
Running scriptlet: mongodb-database-tools-100.3.1-1.x86_64 9/11
Installing : mongodb-database-tools-100.3.1-1.x86_64 9/11
Running scriptlet: mongodb-database-tools-100.3.1-1.x86_64 9/11
Installing : mongodb-org-tools-4.4.6-1.el8.x86_64 10/11
Installing : mongodb-org-4.4.6-1.el8.x86_64 11/11
Running scriptlet: mongodb-org-4.4.6-1.el8.x86_64 11/11
Verifying : python3-pip-9.0.3-18.el8.noarch 1/11
Verifying : python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64 2/11
Verifying : cyrus-sasl-2.1.27-5.el8.x86_64 3/11
Verifying : python3-setuptools-39.2.0-6.el8.noarch 4/11
Verifying : mongodb-database-tools-100.3.1-1.x86_64 5/11
Verifying : mongodb-org-4.4.6-1.el8.x86_64 6/11
Verifying : mongodb-org-database-tools-extra-4.4.6-1.el8.x86_64 7/11
Verifying : mongodb-org-mongos-4.4.6-1.el8.x86_64 8/11
Verifying : mongodb-org-server-4.4.6-1.el8.x86_64 9/11
Verifying : mongodb-org-shell-4.4.6-1.el8.x86_64 10/11
Verifying : mongodb-org-tools-4.4.6-1.el8.x86_64 11/11
Installed products updated.
Installed:
cyrus-sasl-2.1.27-5.el8.x86_64 mongodb-database-tools-100.3.1-1.x86_64 mongodb-org-4.4.6-1.el8.x86_64
mongodb-org-database-tools-extra-4.4.6-1.el8.x86_64 mongodb-org-mongos-4.4.6-1.el8.x86_64 mongodb-org-server-4.4.6-1.el8.x86_64
mongodb-org-shell-4.4.6-1.el8.x86_64 mongodb-org-tools-4.4.6-1.el8.x86_64 python3-pip-9.0.3-18.el8.noarch
python3-setuptools-39.2.0-6.el8.noarch python36-3.6.8-2.module_el8.3.0+562+e162826a.x86_64
Complete!
3.启动MongoDB
[root@localhost yum.repos.d]# service mongod start
Redirecting to /bin/systemctl start mongod.service
[root@localhost yum.repos.d]# service mongod status
Redirecting to /bin/systemctl status mongod.service
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-05-18 22:31:47 EDT; 8s ago
Docs: https://docs.mongodb.org/manual
4.容许MongoDB 外部访问
mongodb的配置文件是 /etc/mongod.conf
如果要开放远程访问需要修改该文件的 bindIp值为: 0.0.0.0
vim /etc/mongod.conf
修改后重新启动
service mongod restart
安装yapi
[root@localhost yum.repos.d]# npm install -g yapi-cli --registry https://registry.npm.taobao.org
npm WARN deprecated axios@0.16.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
npm WARN deprecated bson@1.0.9: Fixed a critical issue with BSON serialization documented in CVE-2019-2391, see https://bit.ly/2KcpXdo for more details
/usr/local/bin/yapi -> /usr/local/lib/node_modules/yapi-cli/bin/yapi-cli
/usr/local/bin/yapi-cli -> /usr/local/lib/node_modules/yapi-cli/bin/yapi-cli
+ yapi-cli@1.5.0
added 257 packages from 126 contributors in 12.685s
[root@localhost yum.repos.d]# yapi server
在浏览器打开 http://0.0.0.0:9090 访问。非本地服务器,请将 0.0.0.0 替换成指定的域名或ip
然后可视化配置
然后启动yapi
cd /home/work/yapi/
node vendors/server/app.js
log: -------------------------------------swaggerSyncUtils constructor-----------------------------------------------
log: 服务已启动,请打开下面链接访问:
http://127.0.0.1:3000/
log: mongodb load success...
(node:27905) DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
安装pm2设置后台启动
npm install -g pm2
pm2 start /home/work/yapi/vendors/server/app.js
pm2 list
pm2 stop /home/work/yapi/vendors/server/app.js