#.net运行环境安装#
1、将 Microsoft 包签名密钥添加到受信任密钥列表,并添加 Microsoft 包存储库。
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
2、安装运行时
sudo yum install aspnetcore-runtime-5.0 -y
上述命令中的最后的5.0表示的是版本号,如果安装其他版本,修改对应的版本号即可。参考资料:https://dotnet.microsoft.com/download/dotnet-core
3、在配置好后,可以通过如下命令检查:
dotnet --info
4、运动程度测试
dotnet Api.dll --urls=http://*:8081
#防火墙开放端口#
1、查看端口开放情况
firewall-cmd --query-port=8088/tcp
2、增加开放端口
firewall-cmd --add-port=8088/tcp --permanent
3、重新加载防火墙配置
firewall-cmd --reload
#创建服务开机自动运行 net程序#
1、在/etc/systemd/system/目录下创建一个"*.service"服务,如"Api.service"
2、服务文件内容:
[Unit]
Description=Api
# After=network.target
[Service]
WorkingDirectory=/app/api/
#ExecStart 执行命令,注意"="后面一定要留一个空格
ExecStart= /usr/bin/dotnet /app/apiApi.dll --urls=http://*:8081
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=Api
# User=www-data
# Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
3、启动服务
sudo systemctl start api
4、停止服务
sudo systemctl stop api
5、设置开机启动
sudo systemctl enable api
6、查看状态
sudo systemctl status api
#安装 nginx#
1、安装先决条件
yum install -y yum-utils
2、创建文件 /etc/yum.repos.d/nginx.repo
内容:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、安装nginx
yum install -y nginx
4、开机启动
systemctl enable nginx
5、启动
nginx systemctl start nginx
6、切换到/etc/nginx/conf.d目录,修改default.conf文件内容,如下所示:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://0.0.0.0:5000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
7、重新加载配置
nginx -s reload
8、如果报”connect() to 192.168.99.13:8088 failed (13: Permission denied) while connecting to upstream“
关闭selinux
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config
9、nginx 的日志目录:/var/log/nginx/