入門參考https://docs.microsoft.com/zh-cn/windows-server/get-started/nano-server-quick-start 1、創建VHD Import-module .\NanoServerImageGenerator.psm1 -Verbose... ...
入門參考https://docs.microsoft.com/zh-cn/windows-server/get-started/nano-server-quick-start
1、創建VHD
Import-module .\NanoServerImageGenerator.psm1 -Verbose
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
2、使用VHD創建虛擬機(在其它操作系統上也可以應用此鏡像,如WIN8.1)
3、遠程管理
A、連接
Set-Item WSMan:\localhost\Client\TrustedHosts "10.168.1.125"
Enter-PSSession -ComputerName "10.168.1.125" -Credential "administrator"
B、共用文件夾
參考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 |