Linux学习之十--.Net Core环境搭建以及Nginx的搭建
一、Centos7下.Net Core 环境安装:
链接:https://www.microsoft.com/net/core#linuxcentos
按照步骤来:
yum install libunwind libicu
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019
mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
ln -s /opt/dotnet/dotnet /usr/local/bin
就这样,.Net Core环境搭建好了,可以使用dotnet --version查看版本号。

可以把我们的.Net Core程序上传到服务器上,使用命令dotnet xxx.dll运行我们的程序。
二、使用Nginx代理转发
参考资料:https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
1.添加CentOS 7 EPEL存储库:
yum install epel-release
2.Nginx存储库安装在您的服务器上,使用以下yum命令安装Nginx:
yum install nginx
3.启用Nginx,设置开机启动
systemctl start nginx #启用Nginx systemctl enable nginx #设置开机启动
4.使用firewall或iptables开发80端口,这样就可以使用http://ip地址 访问,看到如下这个界面就说明Nginx服务开启成功!

5.配置转发规则:
修改配置,监听5000端口:路径为:/etc/nginx/nginx.conf,修改如下:
location/{
# 传递真实IP到后端
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:5000;
}

三、使用Supervisor守护进程
参考链接:http://www.cnblogs.com/savorboard/p/dotnetcore-supervisor.html
3.1安装Supervisor :
yum install python-setuptools easy_install supervisor mkdir /ect/supervisor #创建目录 echo_supervisord_conf > /etc/supervisor/supervisord.conf #配置文件
3.2配置Supervisor:
在/etc/supervisor/confg.d/(如果没有,就创建目录)下新建个名字为CManage.conf(名字xxx.conf就行)配置,
内容如下:
[program:CManage]
command=dotnet CManage.dll #要执行的命令
directory=/home/wwwroot #命令执行的目录
environment=ASPNETCORE__ENVIRONMENT=Production #环境变量
user=www-data #进程执行的用户身份
stopsignal=INT
autostart=true #是否自动启动
autorestart=true #是否自动重启
startsecs= #自动重启间隔
stderr_logfile=/var/log/CManage.err.log #标准错误日志
stdout_logfile=/var/log/CManage.out.log #标准输出日志
3.3配置完了之后,需要修改/etc/supervisor/supervisord.conf文件:
最底部的[include]修改为:
[include]
files = /etc/supervisor/conf.d/*.conf
然后需要把supervisord重新加载:
supervisord -c /etc/supervisor/supervisord.conf
3.4打开服务:
ps -ef | grep CManage

3.5Supervisor 的常用命令:
supervisorctl shutdown #关闭所有任务 supervisorctl stop|start program_name 开启或者停止任务 supervisorctl status #查看所有任务状态
3.6这时候Supervisor相关配置完了,设置开机启动,这样就不用每次重启服务器还需要启用守护进程了。
在/usr/lib/systemd/system/目录新建个supervisord.service文件,内容如下:
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon [Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s [Install]
WantedBy=multi-user.target
设置开机启动:
systemctl enable supervisord 设置为开机启动

四、Supervisor UI 管理台
Supervisor 默认给我们提供了一个图形界面来供我们管理进程和任务,我们可以修改配置文件/etc/supervisor/supervisord.conf,添加inet_http_server 节点:

然后就可以通过界面来查看运行的进程了:

Linux学习之十--.Net Core环境搭建以及Nginx的搭建的更多相关文章
- 学习笔记:CentOS7学习之十五: RAID磁盘阵列的原理与搭建
目录 学习笔记:CentOS7学习之十五: RAID磁盘阵列的原理与搭建 14.1 RAID概念 14.1.1 RAID几种常见的类型 14.1.2 RAID-0工作原理 14.1.3 RAID-1工 ...
- Linux学习之十四、管线命令
Linux学习之十四.管线命令 地址:http://vbird.dic.ksu.edu.tw/linux_basic/0320bash_6.php
- CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点
因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点 以下 ...
- Linux学习--第十天--bash脚本、用户自定义变量、环境变量、位置参数变量、预定义变量、标准输入输出、wc、history、dd、PS1
shell简介 分为两种c shell 和b shell b shell:sh.ksh.Bash.psh.zsh: (Bash和sh兼容,linux基本shell是Bash) c shell:csh. ...
- Linux学习之十五、基础正规表示法\延伸正规表示法
原文地址: http://vbird.dic.ksu.edu.tw/linux_basic/0330regularex_2.php 基础正规表示法 既然正规表示法是处理字串的一种表示方式,那么对字节排 ...
- linux学习(十)Shell中的控制语句
目录 1. 条件测试语句 1.1 test语句 1.2[]语句 1.3文件测试 1.4字符串测试 1.5数值测试 1.5逻辑操作符 @(Shell中的控制语句) 1. 条件测试语句 测试语句十Shel ...
- linux学习(十)find命令、Linux文件后缀名、Linux和windows文件互传
一.和find相关的几个搜索命令,了解即可. 1.1 which [root@iZ25lzba47vZ ~]# which ls alias ls='ls --color=auto' /usr/bin ...
- linux学习第十九天 (Linux就该这么学) 结课了
今天最后一天课程了,结课了,还有点舍不得那,在些也祝 李老师 事业蒸蒸日上,超来超好, 今天内容是部署了 LNMP 部署动态网站环境(linux +nginx+mysql+php) 安装文件挺别多, ...
- Linux学习5-CentOS安装Python3.6环境和pip3
前言 centos7 自带有 python,但是却是 python2 版本的 python,如果你想安装个python3怎么办呢? 如果直接删除python2的话,可能会引起其他的问题,因为有些东西是 ...
随机推荐
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Design Tic-Tac-Toe 设计井字棋游戏
Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the fol ...
- 字节流VS缓冲流
---恢复内容开始--- 字节流VS缓冲流 java.io包中的类大致可以分为:InputStream.OutputStream.Reader.Writer.InputStream/Reader可以理 ...
- MySQL字符串函数substring:字符串截取
MySQL 字符串截取函数:left(), right(), substring(), substring_index().还有 mid(), substr().其中,mid(), substr() ...
- [转]ExtJs入门之filefield:文件上传的配置+结合Ajax完美实现文件上传的asp.net示例
原文地址:http://www.stepday.com/topic/?459 作文一个ExtJs的入门汉子,学习起来的确是比较费劲的事情,不过如今在这样一个网络资源如此丰富的时代,依然不是那么难了的. ...
- git提示:Fatal:could not fetch refs from ....
在git服务器上新建项目提示: Fatal:could not fetch refs from git..... 百度搜索毫无头绪,最后FQgoogle,找到这篇文章http://www.voidcn ...
- c# String.Join 和 Distinct 方法 去除字符串中重复字符
1.在写程序中经常操作字符串,需要去重,以前我的用方式利用List集合和 contains去重复数据代码如下: string test="123,123,32,125,68,9565,432 ...
- Gc.Db之循序渐进
距离上次写Gc.Db框架已经有一段时间了,最近默默对框架代码已经做了不少优化和功能,且已经提交至nuget,大家如果想使用此框架,可以通过nuget搜索:Gc.Db进行下载和安装包. 本篇文章主要是介 ...
- ajax实现局部刷新
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- 【codeforces 148D】 Bag of mice
http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一 ...