设为首页 收藏本站
查看: 1084|回复: 0

[经验分享] 记录成功配置 centos + nginx + .net core 2.0

[复制链接]

尚未签到

发表于 2017-11-22 21:34:13 | 显示全部楼层 |阅读模式
用到的软件如下


  • xshell
  • xftp
  • vs2017.3
  • centos 7.3 64位

安装环境:
  .net core 2.0 可以在以下版本linux 下运行


  • Red Hat Enterprise Linux 7 x64
  • CentOS 7 x64
  • Oracle Linux 7 x64
  • Fedora 25, 26 x64
  • Debian 9, 8.7+ x64
  • Ubuntu 17.04, 16.04, 14.04 x64
  • Linux Mint 18, 17 x64
  • openSUSE 42.2+ x64
  • SUSE Enterprise Linux (SLES) 12 SP2+ x64

实验用到的环境
  aliyun centos 7.3 64位

安装.net core 2.0 依赖的组件


  • deltarpm
  • epel-release
  • unzip
  • libunwind
  • gettext
  • libcurl-devel
  • openssl-devel
  • zlib
  • libicu-devel
  直接yum安装这些组件



yum install deltarpm epel-release unzip libunwind gettext libcurl-devel openssl-devel zlib libicu-devel


安装.net core 2.0



sudo dnf install libunwind libicu
curl -sSL -o dotnet.tar.gz https://aka.ms/dotnet-sdk-2.0.0-linux-x64
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
dotnet --help

  在命令 dotnet --help 看到下面信息就安装.net core 2.0成功了



[iyunv@iZ6r8lfyydxll0Z ~]# dotnet --help
.NET Command Line Tools (2.0.0)
Usage: dotnet [runtime-options] [path-to-application]
Usage: dotnet [sdk-options] [command] [arguments] [command-options]
path-to-application:
The path to an application .dll file to execute.
SDK commands:
new              Initialize .NET projects.
restore          Restore dependencies specified in the .NET project.
run              Compiles and immediately executes a .NET project.
build            Builds a .NET project.
publish          Publishes a .NET project for deployment (including the runtime).
test             Runs unit tests using the test runner specified in the project.
pack             Creates a NuGet package.
migrate          Migrates a project.json based project to a msbuild based project.
clean            Clean build output(s).
sln              Modify solution (SLN) files.
add              Add reference to the project.
remove           Remove reference from the project.
list             List reference in the project.
nuget            Provides additional NuGet commands.
msbuild          Runs Microsoft Build Engine (MSBuild).
vstest           Runs Microsoft Test Execution Command Line Tool.
Common options:
-v|--verbosity        Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
-h|--help             Show help.
Run 'dotnet COMMAND --help' for more information on a command.
sdk-options:
--version        Display .NET Core SDK version.
--info           Display .NET Core information.
-d|--diagnostics Enable diagnostic output.
runtime-options:
--additionalprobingpath <path>    Path containing probing policy and assemblies to probe for.
--fx-version <version>            Version of the installed Shared Framework to use to run the application.
--roll-forward-on-no-candidate-fx Roll forward on no candidate shared framework is enabled.
--additional-deps <path>          Path to additonal deps.json file.

  使用VS2017.3  新建一个.net core 2.0 的测试代码
  可以从此地址下载:http://files.cnblogs.com/files/fun5/webcore.zip
  使用xftp 把生成好的程序 (webcore\webcore\bin\Debug\netcoreapp2.0\publish下的文件)上传到 /home/test 目录下
  执行命令



cd /home/test
dotnet webcore.dll & 
  可以看到 已经运行起来了,localhost:5000

安装配置nginx



yum install nginx

配置nginx.conf



    server {
listen 80;
server_name  test.fun5.cn;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}




执行 nginx -s reload

  访问 nginx 绑定的域名可以看到网站可以跑起来了 http://test.fun5.cn/

配置守护进程


  安装Supervisor




yum install supervisor

  Supervisor配置文件,创建一个ini 配置文件 webcore.ini



[program:webcore]
command=dotnet webcore.dll
directory=/home/test
environment=ASPNETCORE__ENVIRONMENT=Production
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3
stderr_logfile=/var/log/webcore.err.log  
stdout_logfile=/var/log/webcore.out.log

  创建好之后,使用 xftp 上次到 /etc/supervisord.d 目录下
  最后启动



supervisord  -c /etc/supervisord.conf

  
如果想要supervisord开机自启动
  # 编辑启动文件
vi /etc/rc.local
# 在新行添加要执行的命令
supervisord  -c /etc/supervisord.conf
常用命令
# 查看所有action
supervisorctl help
  # 控制所有进程
supervisorctl start all
supervisorctl stop all
supervisorctl restart all
  # 控制目标进程
supervisorctl stop shadowsocks
supervisorctl start shadowsocks
supervisorctl restart shadowsocks
  结束!
  参考资料
  https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction
  https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites?tabs=netcore2x

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-409663-1-1.html 上篇帖子: linux下的高效代码搜索工具-ack 下篇帖子: 从sys/power/state分析并实现S3C2416的睡眠和唤醒
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表