CentOS 下部署 ASP.NET Core環境

來源:互聯網
上載者:User

標籤:htm   viso   html   listen   ati   stdout   sha   nal   進程啟動   

一、安裝dotnet

1.下載運行環境

https://www.microsoft.com/net/download/linux

下載Runtime:https://go.microsoft.com/fwlink/?LinkID=825888

 

  1. 安裝dotnet Runtime

>yum install libunwind libicu

> mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet

> ln -s /opt/dotnet/dotnet /usr/local/bin

安裝步驟:https://www.microsoft.com/net/core#linuxcentos

 

安裝成功,此時執行dotnet 命令即可驗證。

 

  1. 上傳完整檔案至指定目錄:

/root/data/wwwroot/testweb/

並解壓檔案。

  1. 啟動網站

dotnet testweb.dll

註:這裡只是測試啟動,線上環境需要佈建服務進程啟動,後文介紹。

 

二 安裝Nginx

1.安裝nginx

下載nginx: http://nginx.org/download/nginx-1.8.0.tar.gz

安裝參考:http://blog.csdn.net/yuanchao99/article/details/46357173

 

2.編譯nginx:

>./configure --prefix=/usr/local/nginx --with-http_sub_module  --http-log-path=/usr/local/nginx/logs/access.log --error-log-path=/usr/local/nginx/logs/error.log --pid-path=/usr/local/nginx/pid/nginx.pid --lock-path=/usr/local/nginx/lock/nginx.lock --with-http_ssl_module

>make && make check && make install

 

3.啟動nginx

>nginx

 

4.配置nginx

>cd /usr/local/nginx/conf

>vi nginx.conf

添加如下配置內容:

server {

        listen       80;

        server_name  www.aspdotnet.com;#網站請求網域名稱

 

        #charset koi8-r;

 

        access_log  logs/testweb.access.log;#日誌儲存路徑

 

        location / {

            root   /root/data/wwwroot/testweb;#網站部署目錄

 

            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;

        }

5.儲存並退出配置。

6.重新載入nginx 配置:

           >nginx –s reload

 

三、安裝supervisor守護進程

1.

>yum install supervisor

安裝步驟參考:

http://mp.weixin.qq.com/s?__biz=MzAwNTMxMzg1MA==&mid=2654068167&idx=2&sn=bc7a4f722b8fabbb45499f8146ad5100&chksm=80dbf992b7ac708442ef86d22522a9315e7c2c5468faa48dc84439c94b3bf626a6bd178d4c55&mpshare=1&scene=23&srcid=1120Z3xuNaIGA28ttfWP3KXm#rd

2配置

>mkdir /etc/supervisor

>echo_supervisord_conf > /etc/supervisor/supervisord.conf

3. 修改supervisord.conf檔案

將檔案尾部的配置,修改為:

[include]

files = conf.d/*.conf

4. 建立設定檔

       > vi /etc/supervisor/conf.d/testweb.conf

編輯如下內容:

[program:testweb]

command=/usr/local/bin/dotnet /root/data/wwwroot/testweb/testweb.dll

directory=/root/data/wwwroot/testweb/

autostart=true

autorestart=true

stderr_logfile=/root/data/wwwroot/logs/testweb.err.log

stdout_logfile=/root/data/wwwroot/logs/testweb.out.log

environment=ASPNETCORE_ENVIRONMENT=Production

user=root

stopsignal=INT

 

5. 啟動網站

supervisord -c /etc/supervisor/supervisord.conf

 

註:每次修改配置後要執行supervisorctl reload 重新載入更新配置。

不過執行命令是要定位到目錄/etc/supervisor 下再執行服務命令。

 

supervisor 命令:

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,載入最新的設定檔,並按新的配置啟動、管理所有進程。

參考:http://blog.haohtml.com/archives/15145

 

6.查看服務進程是否正常啟動

ps -ef | grep testweb

 

OK! 到這裡網站已經啟動運行了。

 

CentOS 下部署 ASP.NET Core環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.