linux部署.net5项目

Linux(CentOS7.0)部署.Net5项目

第一步:安装.NET运行环境

sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
sudo yum install dotnet-sdk-5.0 
sudo yum install aspnetcore-runtime-5.0 

第二步:安装Jexus(Jexus Web Server 官网)

curl https://jexus.org/release/x64/install.sh|sh  

说明:

1、执行上面的命令记录用root权限,详细说明到官网查;

2、安装完用“ jws -v ”查看版本,查得到说明安装成功;

3、默认安装到:/usr/jexus;

4、/usr/jexus/siteconf中是网站的配置 ,一个网站一个配置文件

5 、启动文件/usr/jexus/jws 后面接启动参数 start|restart|stop

第三步:复制.net项目代码到/var/www/zndl/目录下,并修改连接参数

mkdir -p /var/www/zndl
通过远程终端软件finalshell或者xftp将代码上传到上面创建的目录中

vim /var/www/zndl/appsettings.json
前面部分省略,找到数据库连接部分并修改,修改对应用户名密码
    "DbType": "MySql",
    // 如果采用容器化部署Service 要写成mysql的服务名,否则写地址
    "SqlConnection": "Server=127.0.0.1;Port=3306;Database=newssystem;Uid=root;Pwd=root;CharSet=utf8;pooling=true;SslMode=None;Allow User Variables=true;Convert Zero Datetime=True;Allow Zero Datetime=True;"
    // Mysql数据库链接字符串,请保持后面的属性别少。经过测试,mysql版本需要5.7或以上
  },

第四步:本地安装数据库,导入数据库文件

安装数据库容器

[root@localhost ~]# docker pull mysql:5.7
[root@localhost ~]# mkdir /docker/mysql/mysql.conf.d -pv
[root@localhost ~]# mkdir /docker/mysql/conf.d -p
[root@localhost ~]# mkdir /docker/mysql/data
[root@localhost ~]# vim /docker/mysql/mysql.conf.d/mysqld.cnf
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1 

[root@localhost ~]# vim /docker/mysql/conf.d/mysql.cnf
[mysql]
default-character-set=utf8

#确认3306没有被占用
[root@localhost ~]# docker run -it -d -p 3306:3306 -v
/docker/mysql/mysql.conf.d/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v
/docker/mysql/conf.d/mysql.cnf:/etc/mysql/conf.d/mysql.cnf -v
/docker/mysql/data/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD="root" mysql:5.7 


导入项目数据库文件

#提前创建数据库用于导入
[root@localhost ~]# mysql -uroot -proot
mysql> create database newssystem CharSet=utf8 ;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye

#导入数据库,导入如果出现问题
[ERR] 1273 - Unknown collation: 'utf8mb4_0900_ai_ci'
报错原因:
生成转储文件的数据库版本为8.0,要导入sql文件的数据库版本为5.6,因为是高版本导入到低版本,引起1273错误

解决方法:
打开zndl.sql文件,将文件中的所有
utf8mb4_0900_ai_ci替换为utf8_general_ci
utf8mb4替换为utf8
保存后再次运行sql文件,运行成功

[root@localhost ~]# 
[root@localhost ~]# mysql -uroot -proot newssystem < zndl.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.

测试数据库是否能够连接

#使用数据库远程软件Dbeaver测试是否能连接数据库,如果出现报错:Mysql host '192.168.1.1' is not allowed to connect to this mysql server,是因为只能本地连接,所以我们需要修改连接方式


1. 改表法。
可能是你的帐号不允许从远程登陆,只能在localhost。登录安装的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql> use mysql;

mysql> update user set host = '%' where user = 'root';

mysql> select host, user from user;


2. 授权法。

例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

mysql> FLUSH   PRIVILEGES;

第五步:配置网站配置,启动jexus服务
配置网站配置文件

[root@localhost ~]# vim /usr/jexus/siteconf/default
######################
# Web Site: Default 
########################################

port=8080  #对外暴露的端口,注意是否被占用
root=/ /var/www/zndl/    #网站目录,
hosts=*    #OR your.com,*.your.com 多个域名逗号分隔

# User=www-data

# AspNet.Workers=4       # Set the number of asp.net worker processes. Defauit is 1.
# AspNet.MaxCpuTime=3600 # Cpu time used by each worker process
# AspNet.MaxMemory=256   # Memory used by each working process

# addr=0.0.0.0
# CheckQuery=false
NoLog=true

# AppHost.Port=5000
# AppHost={cmd=dotnet /usr/local/x/app.dll; root=/usr/local/x; port=5000}
AppHost={
    root=/var/www/zndl/;  
    cmd=dotnet /var/www/zndl/CoreCms.Net.Web.Admin.dll; #启动文件,不知道启动文件是啥去问开发
    port=5000;
}

# NoFile=/index.aspx
# Keep_Alive=false
# UseGZIP=false

# UseHttps=true
# ssl.certificate=/x/xxx.crt  #or pem
# ssl.certificatekey=/x/xxx.key
# ssl.protocol=TLSv1.0 TLSv1.1 TLSv1.2
# ssl.ciphers=ECDHE-RSA-AES256-GCM-SHA384:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE 
# ResponseHandler.Add=Strict-Transport-Security:max-age=15768000  #for HSTS

# DenyFrom=192.168.0.233, 192.168.1.*, 192.168.2.0/24
# AllowFrom=192.168.*.*
# DenyDirs=~/cgi, ~/upfiles
# indexes=myindex.aspx

# Deny asp ...
# rewrite=^/.+?\.(asp|cgi|pl|sh|bash|dll)(\?.*|)$  /.deny->$1

# Reproxy:
# reproxy=/bbs/ http://192.168.1.112/bbs/
# host.Redirect=abc.com www.abc.com  301
# ResponseHandler.Add=myKey:myValue

ResponseHandler.Add=X-Frame-Options:SAMEORIGIN

# Jexus php fastcgi address is '/var/run/jexus/phpsvr'
#######################################################
# fastcgi.add=php|socket:/var/run/jexus/phpsvr

# php-fpm listen address is '127.0.0.1:9000'
############################################
# fastcgi.add=php|tcp:127.0.0.1:9000

启动jexus服务,就可以去浏览器访问了IP:8080

/usr/jexus/./jws start

常见报错

服务启动后会在.net项目zndl目录下生成一个日志目录,我的是叫App_Data,此为.net项目日志目录,如果网页访问失败,查看错误日志

比如出现如下报错

#如果出现报错Mysql Table doesn't exist
[root@localhost ~]# vim /docker/mysql/mysql.conf.d/mysqld.cnf
#在[mysqld]栏下添加
lower_case_table_names=1  #添加此项(0:大小写敏感;1:大小写不敏感)
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值