centos7.2 开发 部署 .net core

1、centos7.2 安装 nginx
官方文档:http://nginx.org/en/linux_packages.html#mainline

创建nginx.repo 文件

Pre-Built Packages for Stable version

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1
Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “5”, “6”, or “7”, for 5.x, 6.x, or 7.x versions, respectively.

执行以下命令:

vi /etc/yum.repos.d/nginx.repo

将下面内容复制到文件中,说明:我的系统是centos,版本是7.2,,不同的版本请根据上面的英文提示,进行替换
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1


同目录下创建nginx_signing.key文件

vi /etc/yum.repos.d/nginx_signing.key

将以下内容复制到文件中,保存

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.22 (GNU/Linux)

mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH
W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I
QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE
fDR+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt
97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5
XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg
a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoAhsDBgsJCAcDAgYV
CAIJCgsEFgIDAQIeAQIXgAUCV2K1+AUJGB4fQQAKCRCr9b2Ce9m/YloaB/9XGrol
kocm7l/tsVjaBQCteXKuwsm4XhCuAQ6YAwA1L1UheGOG/aa2xJvrXE8X32tgcTjr
KoYoXWcdxaFjlXGTt6jV85qRguUzvMOxxSEM2Dn115etN9piPl0Zz+4rkx8+2vJG
F+eMlruPXg/zd88NvyLq5gGHEsFRBMVufYmHtNfcp4okC1klWiRIRSdp4QY1wdrN
1O+/oCTl8Bzy6hcHjLIq3aoumcLxMjtBoclc/5OTioLDwSDfVx7rWyfRhcBzVbwD
oe/PD08AoAA6fxXvWjSxy+dGhEaXoTHjkCbz/l6NxrK3JFyauDgU4K4MytsZ1HDi
MgMW8hZXxszoICTTiQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S
YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx
JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/
Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk
RS0UtnB9HPpxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J
SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf
Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6
cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f
YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y
Va3l3WuB+rgKjsQ=
=EWWI
-----END PGP PUBLIC KEY BLOCK-----


执行以下命令:
rpm --import nginx_signing.key

然后安装nginx

yum install nginx

输入:systemctl start nginx 来启动nginx。

输入:systemctl enable nginx 来设置nginx的开机启动(linux宕机、重启会自动运行nginx不需要连上去输入命令)。

命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(开放80端口)

命令:systemctl restart firewalld(重启防火墙以使配置即时生效)

测试nginx是否可以访问。

http://192.168.1.41 (本机地址)

2、配置nginx对ASP.NET Core应用的转发
修改 /etc/nginx/conf.d/default.conf 文件。
将文件内容替换为(将192.168.1.41替换成自己的IP):

upstream myserver {

server 192.168.1.41:5000;

}

server {
listen 80;
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;
}
}

执行:nginx –s reload 使其即时生效

3、安装Supervisor

yum install python-setuptools

easy_install supervisor

 

4、配置Supervisor

mkdir /etc/supervisor

echo_supervisord_conf > /etc/supervisor/supervisord.conf

修改supervisord.conf文件,将文件尾部的配置

;[include]
;files = relative/directory/*.ini

替换为:


[include]
files = conf.d/*.conf

 

如果服务已启动,修改配置文件可用“supervisorctl reload”命令来使其生效

 

5、新建.net core web 测试程序

 mkdir coreweb

cd coreweb

dotnet new -t web

6、配置对ASP.NET Core应用的守护

创建一个 coreweb.conf文件,内容大致如下

[program:coreweb]
command=dotnet run
directory=/root/coreweb/
autostart=true
autorestart=unexpected
startsecs=20
startretries=3
stderr_logfile=/var/log/coreweb.err.log
stdout_logfile=/var/log/coreweb.out.log
environment=ASPNETCORE_ENVIRONMENT=Production
;user=root;
stopsignal=INT

 

将文件拷贝至:/etc/supervisor/conf.d/coreweb.conf

 

运行supervisord,查看是否生效

 

supervisord -c /etc/supervisor/supervisord.conf

 

ps -ef | grep coreweb.dll

如果存在dotnet core.dll 进程则代表运行成功,这时候在使用浏览器进行访问。

至此关于ASP.NET Core应用程序的守护即配置完成。

7、配置Supervisor开机启动

新建一个“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

 

将文件拷贝至:“/usr/lib/systemd/system/supervisord.service”

 

执行命令:systemctl enable supervisord

执行命令:systemctl is-enabled supervisord #来验证是否为开机启动

 

Supervisord安装完成后有两个可用的命令行supervisor和supervisorctl,命令使用解释如下:

  • supervisord,初始启动Supervisord,启动、管理配置中设置的进程。
  • supervisorctl stop programxxx,停止某一个进程(programxxx),programxxx为[program:blogdemon]里配置的值,这个示例就是blogdemon。
  • supervisorctl start programxxx,启动某个进程
  • supervisorctl restart programxxx,重启某个进程
  • supervisorctl stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
  • supervisorctl reload,载入最新的配置文件,并按新的配置启动、管理所有进程。

https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/12.3.md

更多参考:http://www.iitshare.com/supervisord-manage-process.html

 

参考资料:http://www.cnblogs.com/ants/p/5732337.html

 

posted @ 2017-01-23 16:15  AutoHome7390  阅读(1163)  评论(0编辑  收藏  举报