Deploy YApi in CentOS 7

Source: Internet
Author: User
Tags nodesource

Deploy YApi in CentOS 7

Where does YApi go to the mobile architecture group's open-source API management system? Previously, CrapApi on the Code cloud was used. However, since the original author has not updated and maintained for a long time, it is more powerful to hear the company's developers, so let me deploy it.

I. Preparations

1.1 Environment

Operating System: CentOS 7 (CentOS-7-x86_64-Minimal-1708)

Environment requirements:

  • Nodejs (7.6 +)
  • Mongodb (2.6 +)

2. Deploy nodejs

Deploy nodejs and select an even version as much as possible. Because the official maintenance time of the even version is long, 8.xis selected this time.

# Getting resources

curl -sL https://rpm.nodesource.com/setup_8.x | bash -

# Installation

yum install -y nodejs

# View the node version

node -v

# Viewing npm versions

npm -v

3. Deploy mongodb

The odd version of mongodb (for example, 3.5) is a development version. Therefore, choose to install v3.4.

3.1 Add a yum Source

# Modifying file mongodb-3.4.repo

vim /etc/yum.repos.d/mongodb-3.4.repo

Add the following content and save the wq.

[mongodb-org-3.4]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/RedHat/$releasever/mongodb-org/3.4/x86_64/gpgcheck= 0enabled=1

3.2 Installation

yum install -y mongodb-org

3.3 disable selinux

In the official tutorial, selinux has a negative impact on mongodb. Therefore, disable selinux.

# Modifying the config file

vim /etc/selinux/config

Change SELINUX = enforcing to SELINUX = disabled and save the wq.

# Restart the OS

reboot

3.4 disable Firewall

Because data migration is required, firewall is directly shut down.

# Disable and cancel startup

systemctl stop firewalldsystemctl disable firewalld

3.5 start

systemctl start mongod

4. Deploy YApi

4.1 Installation

npm install -g yapi-cli --registry https://registry.npm.taobao.orgyapi server 

As prompted, the browser accesses http: // IP address of the YApi server to be deployed: 9090.

 

After entering the information, click Start deployment ". (About 1 minute)

# Exit the current status

CTRL + C

4.2 modify configuration

Here we are not in a rush to start as prompted, and some parameters can be achieved by modifying the configuration.

# Modify config. json

vim /root/my-yapi/config.json

Modify the following content (the email address does not need to be 163) and wq is saved.

{"Port": "80", "adminAccount": "yizitadmin@yizit.cn", "db": {"servername": "127.0.0.1", "DATABASE": "yapi ", "port": "27017"}, "mail": {"enable": true, "host": "smtp.163.com", "port": 465, "from ": "163 mailbox that can be used to send emails", "auth": {"user": "163 mailbox", "pass": "password or authorization code corresponding to 163 mailbox "}}}

4.3 start

# Switch to the deployment directory

cd /root/my-yapi

# Start the service

node vendors/server/app.js

Because the configuration is modified, you can directly access http: // IP address/login for deploying the YApi server.

(Ps: Access http: // IP address used to deploy the YApi server: 4.2/login if no 3000 configuration is modified)

5. Deploying a Supervisor

The Supervisor is a daemon service and has some problems before there is no Daemon:

  1. The application is running in the subshell initiated by the current terminal. If the hangup signal is interrupted, the application exits. We cannot use a terminal for persistent connection in a long-term environment.
  2. After the server is restarted, you still need to manually connect to the server to start the service.
  3. Unexpected termination of the process. The response was obviously slow when humans discovered that the process was enabled again.

5.1 Installation

yum install python-setuptools -yeasy_install supervisor

5.2 modify configuration

# Create a directory/etc/supervisor

mkdir /etc/supervisor

# Create a supervisord. conf Template File

echo_supervisord_conf > /etc/supervisor/supervisord.conf

# Modifying the file supervisord. conf

vim /etc/supervisor/supervisord.conf

Add the following content and save the wq.

[include]files = conf.d/*.conf

�� If the service has been started, you can run the "supervisorctl reload" command to modify the configuration file to make it take effect)

# Create a directory/etc/supervisor/conf. d/

mkdir -p /etc/supervisor/conf.d/

# Modify the file YApi. conf

vim /etc/supervisor/conf.d/YApiGhost.conf

Add the following content and save the wq.

[Program: YApiGhost] command = node vendors/server/app. js; run the program's command directory =/root/my-yapi; command execution directory autorestart = true; Whether to automatically restart stderr_logfile =/var/log/YApiGhost when the program unexpectedly exits. err. log; Error log File stdout_logfile =/var/log/YApiGhost. out. log; Output log File environment = ASPNETCORE_ENVIRONMENT = Production; process environment variable user = root; Process Execution user identity stopsignal = INT

5.3 Start

# Start the daemon process according to supervisord. conf

supervisord -c /etc/supervisor/supervisord.conf

# View Processes

ps -ef | grep YApiGhost

If the YApiGhost process exists, the operation is successful.

5.4 set to boot

# Modifying file supervisord. service

vim /usr/lib/systemd/system/supervisord.service

Add the following content and save the wq.

[Unit]Description=Supervisor daemon[Service]Type=forkingExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.confExecStop=/usr/bin/supervisorctl shutdownExecReload=/usr/bin/supervisorctl reloadKillMode=processRestart=on-failureRestartSec=42s[Install]WantedBy=multi-user.target 

# Start startup

systemctl enable supervisord

References:

1. https://github.com/YMFE/yapi

2.

3. https://github.com/nodesource/distributions#rpm

5. https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.