20230726部署 react和go项目
1.把项目克隆到服务器的特定位置。
2.安装postgres nodejs
sudo apt-get install postgresql-15
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package postgresql-15
用普通的apt无法安装,尝试更新:
sudo apt update
然后继续安装,还是无法安装:
查看Ubuntu的版本:
lsb_release -r
Release: 18.04
可能是版本太低,无法安装postgres15,那么尝试使用docker进行安装postgres15:
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
可以看到目前没有启动docker的image
查看docker:
which docker
/usr/bin/docker
查看docker compose:
which docker compose
/usr/bin/docker
/usr/bin/compose
查看是否已经配置好了docker compose:
opt# ls
0219.sql 0219_2.sql app coding_tools containerd docker-compose.yml docker_folder td-agent-bit
打开编辑docker-compose.yml,发现仅配置了一个mysql的文件,进行修改:
启动:
docker-compose up -d
Pulling postgres (postgres:15)...
15: Pulling from library/postgres
faef57eae888: Pull complete
a33c10a72186: Pull complete
d662a43776d2: Pull complete
a3ba86413420: Pull complete
a627f37e9916: Pull complete
424bade69494: Pull complete
dd8d4fcd466b: Pull complete
03d0efeea592: Pull complete
4f27e1518a67: Pull complete
0c8ac8b8eb90: Pull complete
c08e79653ad2: Pull complete
d5724e8c22af: Pull complete
3db4aa0d2013: Pull complete
Digest: sha256:362a63cb1e864195ea2bc29b5066bdb222bc9a4461bfaff2418f63a06e56bce0
Status: Downloaded newer image for postgres:15
Creating opt_postgres_1 ...
Creating opt_postgres_1 ... done
查看启动的image:
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec234edbb90c postgres:15 "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp opt_postgres_1
进入docker postgres 创建数据库,和一些表数据:
sudo docker exec -it ec23 /bin/bash
root@ec234edbb90c:/# su postgres
postgres@ec234edbb90c:/$ psql
psql (15.3 (Debian 15.3-1.pgdg120+1))
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+------------+------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(3 rows)
postgres=# \c
You are now connected to database "postgres" as user "postgres".
postgres=# create database dongtaipaifang;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
----------------+----------+----------+------------+------------+------------+-----------------+-----------------------
dongtaipaifang | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(4 rows)
postgres-# \c dongtaipaifang;
You are now connected to database "dongtaipaifang" as user "postgres".
dongtaipaifang-# \d
List of relations
Schema | Name | Type | Owner
--------+------------------------------------+----------+----------
public | calculation_plans | table | postgres
public | calculation_plans_id_seq | sequence | postgres
public | calculation_plans_materials | table | postgres
public | calculation_plans_materials_id_seq | sequence | postgres
public | calculation_result_details | table | postgres
public | calculation_result_details_id_seq | sequence | postgres
public | calculation_results | table | postgres
public | calculation_results_id_seq | sequence | postgres
public | calculation_templates | table | postgres
public | calculation_templates_id_seq | sequence | postgres
public | history_login_logs | table | postgres
public | history_login_logs_id_seq | sequence | postgres
public | materials | table | postgres
public | materials_id_seq | sequence | postgres
public | users | table | postgres
public | users_id_seq | sequence | postgres
public | verification_codes | table | postgres
public | verification_codes_id_seq | sequence | postgres
dongtaipaifang=# insert into users(login, password, mobile, is_admin, active) values('admin', 'admin', '19921221992', true, true);
INSERT 0 1
dongtaipaifang=# insert into calculation_templates(name, explain, algorithm_name, initial_discharge_rate, initial_filling_amount, operating_discharge_rate, maintenance_discharge_rate, maintenance_filling_rate, annual_maintenance_rate, scrap_discharge_rate) values('消防-普通', '消防领域的普通模版', '消防', 1, 2, 3, 4, 5, 6, 7);
INSERT 0 1
dongtaipaifang=# insert into calculation_templates(name, explain, algorithm_name, initial_discharge_rate, initial_filling_amount, operating_discharge_rate, maintenance_discharge_rate, maintenance_filling_rate, annual_maintenance_rate, scrap_discharge_rate) values('空调制冷', '空调制冷领域的模版', '制冷', 1, 2, 3, 4, 5, 6, 7);
INSERT 0 1
3.安装go1.18.3:(此处省略,使用wegt直接安装即可)
4.nginx install
sudo apt install nginx
进入nginx的目录,进行配置文件:
cd /etc/nginx/
root@ali-anquan-2:/etc/nginx# ls
conf.d fastcgi.conf koi-utf mime.types modules-enabled proxy_params sites-available snippets win-utf
dhparam.pem fastcgi_params koi-win modules-available nginx.conf scgi_params sites-enabled uwsgi_params
/etc/nginx/sites-enabled# ls
(这里会显示已经配置好的以域名命名的文件)
停止nginx:
sudo nginx -s stop
启动nginx:
sudo nginx