Last active
October 17, 2021 05:45
-
-
Save gavinwhyte/73b045ad5441abc1f4265fece8893978 to your computer and use it in GitHub Desktop.
brewbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Create User | |
Create user brewai | |
```bash | |
adduser brewai | |
``` | |
Password: | |
Grant root access | |
```bash | |
usermod -aG sudo brewai | |
``` | |
No password for sudo | |
```bash | |
echo "$USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers | |
``` | |
Logout and then | |
```bash | |
ssh brewai@ | |
``` | |
password: | |
### Prepare machine | |
```bash | |
sudo apt-get update | |
sudo apt -y upgrade | |
sudo apt -y install build-essential unzip | |
``` | |
As default python version is 3.8 and pytorch only works on 3.7. We use anaconda which can specify the right python version. | |
```bash | |
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh | |
bash Anaconda3-2021.05-Linux-x86_64.sh | |
``` | |
Install nginx and supervisor | |
```bash | |
sudo apt -y install nginx | |
sudo apt -y install supervisor | |
``` | |
### Install mongodb | |
```bash | |
sudo apt-get install gnupg | |
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - | |
``` | |
This is for ubuntu 20 only, other versions of ubuntu please refer to | |
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ | |
```bash | |
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list | |
``` | |
Then | |
```bash | |
sudo apt-get update | |
sudo apt-get install -y mongodb-org | |
``` | |
Create username and password | |
```mongodb | |
use brewai | |
db.users.insert({'uid':'admin','pwd':'pbkdf2:sha256:150000$g7DcUjwd$c073e01fd2754f1acbac5eede9da7a921b92195d68eb1e6559f4003e7a7e1ccf'}) | |
``` | |
username: | |
password: | |
### Prepare brewui and brewcore | |
git clone the repo | |
```bash | |
git clone https://andyzengbrew@github.com/gavinwhyte/brewui_flask.git | |
mv brewui_flask/ brewui | |
cd brewui/app/static/ | |
mkdir cache | |
``` | |
creat the virtual env | |
```bash | |
cd brewui | |
conda create --name brewui python=3.7 | |
conda activate brewui | |
pip install --no-cache-dir -r requirements.txt | |
``` | |
git clone the repo | |
```bash | |
git clone https://andyzengbrew@github.com/gavinwhyte/brewcore.git | |
``` | |
creat the virtual env | |
```bash | |
cd brewcore | |
conda create --name brewcore python=3.7 | |
conda activate brewcore | |
pip install --no-cache-dir -r requirements.txt | |
``` | |
create folders for logs and data | |
```bash | |
cd ~/ | |
mkdir logs | |
mkdir data | |
``` | |
### Setup web service | |
Setup supervisor | |
```bash | |
cd /etc/supervisor/conf.d/ | |
sudo vi flask.conf | |
``` | |
Add in content as below | |
```bash | |
[program:flask] | |
command=/home/brewai/anaconda3/envs/brewui/bin/gunicorn run:app -c /home/brewai/brewui/conf/gunicorn.conf | |
directory=/home/brewai/brewui/ | |
user=brewai | |
autostart=true | |
autorestart=true | |
stdout_logfile=/home/brewai/logs/gunicorn_supervisor.log | |
``` | |
Start supervisor | |
```bash | |
sudo service supervisor start | |
sudo supervisorctl reread | |
sudo supervisorctl update | |
sudo supervisorctl start flask | |
``` | |
Config nginx | |
```bash | |
cd /etc/nginx/sites-available/ | |
sudo vi brewai | |
``` | |
Write the below content | |
```bash | |
server { | |
listen 80; | |
server_name demo.brewai.com; | |
location / { | |
proxy_pass http://127.0.0.1:8000; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
client_max_body_size 500M; | |
} | |
``` | |
Link it | |
```bash | |
sudo ln -sf /etc/nginx/sites-available/brewai /etc/nginx/sites-enabled/default | |
sudo service nginx restart | |
``` | |
### Setup ssl | |
```bash | |
sudo apt -y install certbot python3-certbot-nginx | |
sudo certbot --nginx -d demo.brewai.com | |
``` | |
### Launch brewai_train and brewai_predict | |
```bash | |
nohup /home/brewai/anaconda3/envs/brewcore/bin/python /home/brewai/brewcore/brewai_train.py > /home/brewai/logs/brewai_train.log 2>&1 & | |
nohup /home/brewai/anaconda3/envs/brewcore/bin/python /home/brewai/brewcore/brewai_predict.py > /home/brewai/logs/brewai_predict.log 2>&1 & | |
``` | |
or | |
```bash | |
nohup /home/brewai/anaconda3/envs/brewcore/bin/python /home/brewai/brewcore/brewai_backend.py > /home/brewai/logs/brewai_backend.log 2>&1 & | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment