# How to deploy PingCAP KB

## Requirements
- required
  - MySQL Client (for migration)
  - MySQL Server
  - ElasticSearch Server
  - Node.js
  - Nginx
- optional
  - Kibana Server

## Prepare environment

Env: Ubuntu

```shell
# Install ES & Kibana
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.4-amd64.deb
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.13.4-amd64.deb
sudo dpkg -i elasticsearch-7.13.4-amd64.deb
sudo dpkg -i kibana-7.13.4-amd64.deb
sudo apt-get update
sudo apt-get install apt-transport-https kibana elasticsearch

# Install nginx
sudo apt-get install nginx

# Install elasticsearch smartcn plugin
sudo elasticsearch-plugin install analysis-smartcn
cd /usr/share/elasticsearch/
sudo bin/elasticsearch-plugin install analysis-smartcn

# Install node
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install 14
```

```nginx configuration
# /etc/nginx/nginx.conf
server {
        listen 80;
        server_name kb.pingcap.com;
        location / {
                root /home/ubuntu/kb/pingcap-knowledge-base-fe/dist;
                index index.html;
                autoindex on;
                set $fallback_file /index.html;
                if ($http_accept !~ text/html) {
                        set $fallback_file /null;
                }
                if ($uri ~ /$) {
                        set $fallback_file /null;
                }
                try_files $uri $fallback_file;
        }
        location /api/ {
                proxy_pass http://127.0.0.1:7001;
        }
        location /passport/ {
                proxy_pass http://127.0.0.1:7001;
        }
        location /devapi/ {
                proxy_pass http://127.0.0.1:7001;
        }
}
```
