.net core 2.0部署到CentOS7系统
1、Nginx的安裝(重啟Nginx命令: systemctl restart nginx)
輸入命令(?根據提示輸入Y 即可):?
? ? ? ? ? sudo yum install epel-release?
? ? ? ? ? sudo yum install nginx
? ? ? ? ??sudo systemctl start nginx
?還需要輸入關閉防火墻命令:
? ? ? ? ?sudo firewall-cmd --permanent --zone=public --add-service=http
? sudo firewall-cmd --permanent --zone=public --add-service=https
? sudo firewall-cmd --reload
配置防火墻
命令:firewall-cmd --zone=public --add-port=80/tcp --permanent(開放80端口)
命令:systemctl restart firewalld(重啟防火墻以使配置即時生效)
完成之后可以在Windows的瀏覽器中輸入上面的IP訪問了
2、如果輸入dotnet CoreDemo.dll出現報錯,運行命令: sudo yum install dotnet-sdk-2.1.3切換版本
在CentOS中使用命令: curl http://localhost:5000沒有出現錯誤則成功
?
3、修改Nginx配置來實現局域網訪問
進入/etc/nginx/ 修改其中的nginx.conf文件
將其中的server段替換成下面的配置
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;
?}
}
最后使用命令:?systemctl restart nginx?重啟Nginx
輸入之后發現出現502 Bad GateWay.....
這個問題發現是因為Linux保護機制所導致,我們需要將nginx添加至Linux的白名單
輸入以下命令:
yum install policycoreutils-python
sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp
再嘗試訪問
4、配置將Nginx改為自啟動:
使用命令:?systemctl enable nginx.service 或者?systemctl enable nginx
使用命令:?systemctl is-enabled nginx?來確認是否設置成功
5、配置守護服務(Supervisor)
我們需要有一個程序來監聽ASP.NET Core 應用程序的狀況。在應用程序停止運行的時候立即重新啟動。這邊我們用到了Supervisor這個工具,Supervisor使用Python開發的。
安裝Supervisor
yum install python-setuptools
easy_install supervisor
配置Supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
修改supervisord.conf文件,將文件尾部的配置
修改為
修改配置文件可用“supervisorctl reload”命令來使其生效
遇到的錯誤
* Starting Supervisor daemon manager...
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
...fail!
解決辦法
find / -name supervisor.sock
unlink /***/supervisor.sock
6、配置對ASP.NET Core應用的守護
創建一個 Core.Web.conf文件,內容大致如下
[program:Core.Web]
command=dotnet Core.Web.dll ;
directory=/home/netcore/ ; #發布目錄 ;
autorestart=true ;
autostart=true ;
stderr_logfile=/var/log/core.web.err.log ;
stdout_logfile=/var/log/core.web.out.log ;
environment=ASPNETCORE_ENVIRONMENT=Production ;
user=root ;
stopsignal=INT ;
startsecs=1 ;
將文件拷貝至:“/etc/supervisor/conf.d/Core.Web.conf”下
運行supervisord,查看是否生效
[root@bogon ~]# supervisord -c /etc/supervisor/supervisord.conf
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
[root@bogon ~]# find / -name supervisor.sock
/tmp/supervisor.sock
[root@bogon ~]# unlink /***/supervisor.sock
[root@bogon ~]# supervisord -c /etc/supervisor/supervisord.conf
[root@bogon ~]# ps -ef | grep Core.Web
root 24817 1296 0 11:07 pts/0 00:00:02 dotnet Core.Web.dll
root 35113 24513 0 11:40 pts/1 00:00:00 grep --color=auto Core.Web
?
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
[root@bogon ~]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
執行命令:systemctl is-enabled supervisord #來驗證是否為開機啟動
[root@bogon ~]# systemctl is-enabled supervisord
enabled
附件:點擊下載
?參考:
https://www.cnblogs.com/Leo_wl/p/5734988.html
https://www.cnblogs.com/zuqing/p/8231957.html
https://www.cnblogs.com/firesnow/archive/2013/03/19/2969734.html
https://www.cnblogs.com/Hai--D/p/5820718.html
?
supervisord?
[root@izj6cc2th4yjgg36bu9203z supervisor]# supervisorctl reload
error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib64/python2.7/socket.py line: 224
[root@izj6cc2th4yjgg36bu9203z supervisor]# supervisord
/usr/lib/python2.7/site-packages/supervisor-3.3.4-py2.7.egg/supervisor/options.py:461: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
[root@izj6cc2th4yjgg36bu9203z supervisor]# supervisorctl reload
Restarted supervisord
轉載于:https://www.cnblogs.com/OnlyDreams/p/8391535.html
總結
以上是生活随笔為你收集整理的.net core 2.0部署到CentOS7系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux学习—vim大全
- 下一篇: 绕月飞行维生系统进展如何?美国人准备好了