威势网络,为您的企业和团队注入互联网活力!
服务热线:138-9741-0341

CentOS 7.6部署WinsMVC WEB程序

发布日期:2022/8/30 作者: 浏览:963

今天的试验任务是将开发的项目成功部署到CentOS 7.6上面去。

项目概况:

用.NETCORE 6.0 MVC开发

编译发布选项


发布输出以后长上面这样

在来看看我们的主机环境,操作系统:CentOS 7.6

CentOS是一款流行的开源Linux发行版,是RHEL(Red Hat Enterprise Linux)源代码经过再编译而成。

登录我们今天的主机看看

[root@VM-4-11-centos ~]# uname -a
Linux VM-4-11-centos 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-11-centos ~]# 


然后我们将项目通过WinSCP上传到主机上去,然后运行一下,结果报错,也很正常,因为数据库还没有部署

我们将数据库部署上去,然后将域名证书也部署上去,再给上666的权限,重新运行一下

进程成功启动了,浏览器访问无任何问题,部署成功。很简单,不是吗?


CentOS 8.0 64bit

[root@VM-4-11-centos publish]# uname -a
Linux VM-4-11-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-11-centos publish]# lsof -i:443
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
hlw     4716 root  275u  IPv4  41723      0t0  TCP *:https (LISTEN)
[root@VM-4-11-centos publish]# 

部署过程大同小异,可以正常执行

CentOS 8.2 64bit 下部署会失败,因为CentOS官方不支持.NET6.0 请记住这个版本


[root@VM-4-11-centos data]#cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core) 
[root@VM-4-11-centos data]# 
[root@VM-4-11-centos data]# uname -a
Linux VM-4-11-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@VM-4-11-centos data]# 

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.7 initialized 'DBContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite:6.0.5' with options: None
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (12ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT EXISTS (
          SELECT 1
          FROM "Category" AS "c")
fail: Microsoft.EntityFrameworkCore.Query[10100]
      An exception occurred while iterating over the results of a query for context type 'WinsMVC.Data.DBContext'.
      Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: Category'.
         at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)

经过一阵疯狂的搜索,找到以下答案


The SQLite provider for EntityFramework will not create the database or add missing tables automatically for you. You can call dbContext.Database.EnsureCreatedAsync() to make EF create the database file if it does not exist. It will then also create all the required tables. However, if the file already exists, it will not modify it.

If you want to add additional tables to your database at a later time, you should consider using migrations which allow you to evolve your database schema over time while providing means to migrate from older versions of a database to the current schema.

If you have migrations set up, you can call dbContext.Database.EnsureMigratedAsync() to apply pending migrations to the database and make sure that the database matches the model you expect.

You can also create the database or apply migrations using the dotnet ef command line utility.

经过简单的调试发现,CentOS8.2下面数据库连接字符串Configuration.GetConnectionString("db")返回的路径为空,引起代码异常。如果校准成绝对路径,同样报错。CentOS8.2不支持.NET Core, SQLLITE数据库用起来看来还是有点麻烦,用PG可能会解决问题?以后再试



下拉加载更多评论
最新评论
暂无!