CentOS 下部署 ASP.NET Core環境

1、安裝dotnethtml

1.下載運行環境linux

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

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

 

  1. 安裝dotnet Runtime

>yum install libunwind libicucentos

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

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

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

 

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

 

  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

 

3、安裝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安裝完成後有兩個可用的命令行supervisorsupervisorctl,命令使用解釋以下:

supervisord,初始啓動Supervisord,啓動、管理配置中設置的進程。

supervisorctl stop programxxx,中止某一個進程(programxxx)programxxx[program:blogdemon]裏配置的值,這個示例就是blogdemon

supervisorctl start programxxx,啓動某個進程

supervisorctl restart programxxx,重啓某個進程

supervisorctl stop all,中止所有進程,注:startrestartstop都不會載入最新的配置文件。

supervisorctl reload,載入最新的配置文件,並按新的配置啓動、管理全部進程。

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

 

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

ps -ef | grep testweb

 

OK! 到這裏站點已經啓動運行了。

相關文章
相關標籤/搜索