From f3b8a6cd99b23c96fcc6494deb01eadfdf1602a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=A2=A6=E6=B6=B5?= <3234558314@qq.com> Date: Mon, 6 Jan 2025 09:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...42\346\225\260\346\215\256\345\272\223.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "\351\231\210\346\242\246\346\266\265/20250103\346\233\264\346\215\242\346\225\260\346\215\256\345\272\223.md" diff --git "a/\351\231\210\346\242\246\346\266\265/20250103\346\233\264\346\215\242\346\225\260\346\215\256\345\272\223.md" "b/\351\231\210\346\242\246\346\266\265/20250103\346\233\264\346\215\242\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000..e2b14fb --- /dev/null +++ "b/\351\231\210\346\242\246\346\266\265/20250103\346\233\264\346\215\242\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,62 @@ +## 更换数据库,为了能更好的部署在云服务器上(Linux操作系统) +为了能更好的部署在云服务器上(Linux操作系统) + +1. 安装好数据库 + - 在Debian上安装PostgreSQL数据库 + 1) apt install -y postgresql-common + 2) /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh + 3) apt -y install postgresql + - 确认有没有安装好 + - 查看状态:systemctl status postgresql + - 设置高强度密码 + 1) 进入密码设置:su postgres + 2) 切换后进入:psql + 3) \password + 4) 设置密码 + 5) 退出:exit或者\q,切换回root:su root + - 设置允许远程访问数据库 +为了允许远程访问PostgreSQL数据库,你需要修改配置文件postgresql.conf和pg_hba.conf。 +打开postgresql.conf文件: +bash +sudo nano /etc/postgresql/12/main/postgresql.conf + +找到listen_addresses行,并将其修改为: +conf +listen_addresses = '*' + +打开pg_hba.conf文件: +bash +sudo nano /etc/postgresql/12/main/pg_hba.conf + +在文件的末尾添加以下行,以允许所有IP地址访问数据库: +conf +host all all 0.0.0.0/0 md5 +保存并关闭文件后,重启PostgreSQL服务: +bash +sudo systemctl restart postgresql + + - 可以通过以下命令来设置高强度密码: +bash +sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'your-strong-password';" +将your-strong-password替换为你选择的密码。 + +2. 更换数据库驱动(配合ORM工具),并且重新生成迁移文件 + - 移除原来的数据库驱动:Microsoft.EntityFrameworkCore.SqlServer。命令如下:dotnet remove package Microsoft.EntityFrameworkCore.SqlServer + - 安装新的数据库驱动:Npgsql.EntityFrameworkCore.Postgresql。命令如下:dotnet add package Npgsql.EntityFrameworkCore.Postgresql + - 更新数据库上下文的一些配置 + ```CS + var conString =$"server=t1.lcann.cn;database=ScoreDb;uid=postgres;pwd=qq@112358@"; + optionsBuilder.UseNpgsql(conString); + ``` + - 重新生成迁移文件 + - 同步迁移文件 + +## 部署在网站上 +1. 打包:dotnet publish +2. 上传:scp -r ./* root@XXXX.lcann.cn:/var/www/XXXX.lcann.cn +3. 借助**pm2**工具 +4. 反向代理 + +## 区别 +- ORM工具:类似Microsoft.EntityFrameworkCore +- 数据库驱动:类似Microsoft.EntityFrameworkCore.SqlServer \ No newline at end of file -- Gitee