Nano Server速記

入門參考https://docs.microsoft.com/zh-cn/windows-server/get-started/nano-server-quick-start html

一、建立VHD python

Import-module .\NanoServerImageGenerator.psm1 -Verbose shell

New-NanoServerImage -Edition Standard -DeploymentType Guest -MediaPath j:\ -BasePath d:\vm\nano -TargetPath d:\vm\nano\nano.vhd -ComputerName Nano -Package Microsoft-NanoServer-IIS-Package –EnableRemoteManagementPort json

               

二、使用VHD建立虛擬機(在其它操做系統上也能夠應用此鏡像,如WIN8.1) windows

三、遠程管理 app

A、鏈接 框架

Set-Item WSMan:\localhost\Client\TrustedHosts "10.168.1.125" tcp

Enter-PSSession -ComputerName "10.168.1.125" -Credential "administrator" 網站

               

B、共享文件夾 ui

參考https://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-2_5-nano_server_on_core.html

               

mkdir c:\temp

(啓用文件共享沒什麼效果)netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=yes

net share ShareTemp=c:\temp /GRANT:EVERYONE`,FULL

               

C、開端口

參考http://www.pstips.net/manage-firewall-using-powershell.html

               

New-NetFirewallRule -Name "MyService" -DisplayName "個人服務" -Protocol TCP -LocalPort 80,8080,3413-3420 -Action Allow -Enabled True

               

               

D、安裝NET CORE

參考https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script

./dotnet-install.ps1 -Channel 2.0 -InstallDir C:\cli

若是提示錯誤

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

             

IIS

參考 https://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-2_5-nano_server_on_core.html

下載安裝腳本,執行命令

             

             

自服務

參考https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1

Cmd /c sc create MyService binPath= "c:\temp\publish\WebApplication2.exe" start= auto

Cmd /c sc start MyService

(使用獨立發佈,安裝了2.0框架,在CENTOS中安裝了2.1,獨立發佈出現DLL的版本簽名不一致,最終使用框架依賴發佈)

public class Program

{

public static void Main(string[] args)

{

// BuildWebHost(args).Run();

CreateWebHostBuilder(args).RunAsService();

}

             

public static IWebHost BuildWebHost(string[] args)

//WebHost.CreateDefaultBuilder(args)

// .UseStartup<Startup>()

// .Build();

{

//在IIS啓動

var config = new ConfigurationBuilder()

.SetBasePath(Directory.GetCurrentDirectory())

.AddJsonFile("hosting.json", optional: true)

.Build();

return new WebHostBuilder()

.UseConfiguration(config)

.UseKestrel()

.UseContentRoot(Directory.GetCurrentDirectory())

.UseIISIntegration()

.UseStartup<Startup>()

.Build();

}

             

public static IWebHost CreateWebHostBuilder(string[] args)

{

//以服務形式啓動

var pathToExe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

var pathToContentRoot = Path.GetDirectoryName(pathToExe);

             

var config = new ConfigurationBuilder()

.SetBasePath(pathToContentRoot)

.AddJsonFile("hosting.json", optional: true)

.Build();

             

return new WebHostBuilder()

.UseConfiguration(config)

.UseKestrel()

.UseContentRoot(pathToContentRoot)

.UseStartup<Startup>().Build();

}

             

}

             

         

Linux下安裝NETCORE

#netcor 安裝腳本

#vi /etc/sysconfig/network-scripts/ifcfg-eth0 (可能不是這個名字),將onboot=no修改成yes

ip addr

service network restart

ip addr

     

#使用CRT登陸方便複製

su

     

yum -y install net-tools

ifconfig

mkdir /opt/dotnet

cd /opt/dotnet

     

yum -y install wget

yum -y install icu

     

wget -c https://dot.net/v1/dotnet-install.sh

     

chmod +x dotnet-install.sh

./dotnet-install.sh -Channel 2.1 -InstallDir /opt/dotnet

export PATH=$PATH:/opt/dotnet

./dotnet --info

     

yum -y install zip unzip

yum -y install lrzsz

     

#部署網站

mkdir /app

cd /app

mkdir BandServer

     

#使用rz指令上傳網站壓縮包,使用unzip解壓,注意壓縮包的相對目錄

#unzip publish.zip

#添加防火牆

firewall-cmd --zone=public --add-port=3415/tcp --permanent

firewall-cmd --reload

     

#啓動網站觀察是否工做正常

dotnet BandServer.dll

     

     

#配置守護進程

     

yum -y install python-setuptools

easy_install supervisor

supervisord --version

     

echo_supervisord_conf > /etc/supervisord.conf

     

#編輯supervisord.conf在末尾添加應用(以下,記得去除#)

# [program:bandserver]

# directory=/app/BandServer

# command=/opt/dotnet/dotnet BandServer.dll

# autostart=true

# autorestart=true

# stderr_logfile=/var/log/bandserver.err.log

# stdout_logfile=/var/log/bandserver.out.log

# user=root

# stopsignal=INT

# redirect_stderr=true

     

     

#設置爲開機執行

# vi /etc/rc.local

#添加 supervisord -c /etc/supervisord.conf

#chmod +x /etc/rc.local

systemctl enable rc-local

#手動啓動守護

supervisord -c /etc/supervisord.conf

supervisorctl start all

supervisorctl status

     

#重啓

# reboot

相關文章
相關標籤/搜索