Ich möchte eine .NET Core MVC-Website von einer AWS Amazon Linux AMI -Instanz aus ausführen.
Hier sind die Schritte, die ich bisher gemacht habe:
Sudo yum update -y
Sudo yum install libunwind -y
Sudo yum install gettext -y
curl -sSL https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview1/scripts/obtain/dotnet-install.sh | bash /dev/stdin --version 1.0.0-preview1-002702 --install-dir ~/dotnet
Sudo ln -s ~/dotnet/dotnet /usr/local/bin
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
source /home/ec2-user/.dnx/dnvm/dnvm.sh
dnvm upgrade -r coreclr
Sudo yum install automake libtool wget -y
wget http://dist.libuv.org/dist/v1.8.0/libuv-v1.8.0.tar.gz
tar -zxf libuv-v1.8.0.tar.gz
cd libuv-v1.8.0
Sudo sh autogen.sh
Sudo ./configure
Sudo make
Sudo make check
Sudo make install
Sudo ln -s /usr/lib64/libdl.so.2 /usr/lib64/libdl
Sudo ln -s /usr/local/lib/libuv.so.1.0.0 /usr/lib64/libuv.so
verwendet zu werden.Sudo yum install git -y
mkdir director-name
cd directory-name
git config user.name "myUserName"
git config user.email "myEmail"
git clone https://github.com/username/repositoryname.git
klonencd solution-name/src/web-project-name
.dotnet restore
dotnet build
dotnet run
ausführenAn dieser Stelle sehe ich im Terminal Folgendes:
Jetzt hören auf: http: // localhost: 5000
Ich versuche, die AWS-DNS/IP mit Port 5000 am Ende zu markieren (http: // aws-ip-or-dns: 5000), bekomme aber keine Antwort.
Ich weiß, dass Docker und Mono Werkzeuge sind, die ich verwenden kann, aber ich würde diesen Ansatz lieber zur Wirkung bringen.
Die zum Installieren von .NET Core, DNVM und DNX verwendeten Skripts sind eine Kombination der Anweisungen von CentOS und Ubuntu aus den folgenden Links:
Haftungsausschluss Ich bin nicht so erfahren mit Linux. Man kann sagen, ich verstehe einige Befehle nicht, die ich ausführen möchte. Aber ich bin hier um zu lernen!
Frage: Was muss ich tun, um eine .NET Core-Webanwendung mit einer AWS Amazon Linux-Umgebung zu erstellen?
(Meine Vermutung: Ich habe etwas mit dem Einrichten des HTTP-Servers vermisst)
Ich brauche mehr Reputation, um mehr als zwei Links zu veröffentlichen. Wenn also jemand BEARBEITEN möchte, würde ich das zu schätzen wissen.
Die Antwort von @ user326608 hat es fast geschafft, aber ich werde die Schritte hinzufügen, die ich jetzt nach der Veröffentlichung von .NET Core 1.0.0 benutze.
Sudo yum update -y
Sudo yum install libunwind -y
curl -sSL -o dotnet.tar.gz https://go.Microsoft.com/fwlink/?LinkID=809131
herunter.Sudo mkdir -p /opt/dotnet && Sudo tar zxf dotnet.tar.gz -C /opt/dotnet
Sudo ln -s /opt/dotnet/dotnet /usr/local/bin
Sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 5000
Sudo yum install git -y
git config --global user.name "myUserName"
konfigurierengit config --global user.email "[email protected]"
konfigurierenmkdir /var/coreapp
cd /var/coreapp
verschiebengit clone https://github.com/myUsername/myRepository.git
abrufenSudo chown -R ec2-user /var/coreapp
cd /var/coreapp/solution-name/src/web-project-name
dotnet restore
wieder her, erstellen Sie dotnet build
und führen Sie ihn im Hintergrund aus Nohup dotnet run > /dev/null 2>&1 &
.Diese Lösung funktioniert jetzt gut für mich. Ich habe ein verwandtes Post , das versucht, ein Bootstrap-Skript User Data zu erstellen, um dies noch einfacher zu machen.
Für alle, die das obige Update für das Update für Microsoft.NETCore.App 1.0.1 September 2016 durchführen müssen, funktionierten die Anweisungen https://www.Microsoft.com/net/core#centos für mich:
curl -sSL -o dotnet.tar.gz https://go.Microsoft.com/fwlink/?LinkID=827529
Sudo mkdir -p /opt/dotnet && Sudo tar zxf dotnet.tar.gz -C /opt/dotnet
Sudo rm /usr/local/bin/dotnet
Sudo ln -s /opt/dotnet/dotnet /usr/local/bin
Das anschließende Ausführen von dotnet --info
ergibt:
.NET Command Line Tools (1.0.0-preview2-003131)
Product Information:
Version: 1.0.0-preview2-003131
Commit SHA-1 hash: 635cf40e58
Runtime Environment:
OS Name: amzn
OS Version: 2016.09
OS Platform: Linux
RID: amzn.2016.09-x64
Danach habe ich meinen project.lock.json
gelöscht und einen dotnet restore
ausgeführt.
Ich konnte keinen dotnet run
direkt zum Laufen bringen, da meine RID nicht bekannt war, aber die Verwendung einer Dockerfile
mit Microsoft/dotnet:onbuild
und dieser Abschnitt in meinem project.json
hat funktioniert:
"runtimes": {
"debian.8-x64" : {}
},
Wenn Sie Opswork (oder Chef) verwenden, können Sie das folgende Chefrezept https://supermarket.chef.io/cookbooks/dotnetcore verwenden, um einen Dotnet-Core unter AWS Linux zu installieren. Es wird davon ausgegangen, dass Sie die ZIP-Datei hochgeladen haben Datei mit dotnet publish-Datei in einen S3-Bucket.
Die Schicht json hat JSON, das den Kurznamen der App hat, z.
{
myapp {}
}
# The recipe to install
# 1) Figure which App needs to be installed using JSON in Opsworks layer
# 2) Get the Zip file from S3 and Unzip into /usr/bin/myapp/publish
# 3) Create bash file to start
# 4) Start the app
apps = search(:aws_opsworks_app)
apps.sort_by { |v| v["shortname"] }.each do |app|
appname = app["shortname"]
app_source = app["app_source"]
bucket, remote_path = OpsWorks::SCM::S3.parse_uri("#{app_source['url']}")
filename = remote_path.split("/")[-1]
extn = File.extname filename
if (!node["#{appname}"].nil? && extn == '.Zip')
apppath = "/usr/bin/#{appname}"
dotnetapp = app["environment"]["dotnetapp"]
aspnetcore_environment = app["environment"]["aspnetcore_environment"]
Chef::Log.info("App dotnet Name:#{app[:environment][:dotnetapp]}")
Chef::Log.info("Enviroment:#{aspnetcore_environment}")
app_checkout = ::File.join(Chef::Config["file_cache_path"], app["shortname"])
package = "#{app_checkout}/#{filename}"
# Use https://github.com/awslabs/opsworks-windows-demo-cookbooks or any s3_file recipe to download the Zip file
# if you copy the opsworks-windows-cookbooks you will to modify the recipe a little to work on aws linux
opsworks_scm_checkout app["shortname"] do
destination app_checkout
repository app_source["url"]
user app_source["user"]
password app_source["password"]
type app_source["type"]
ssh_key app_source["ssh_key"]
revision app_source["revision"]
end
directory "#{apppath}" do
end
execute 'unzip package' do
command "unzip -o #{app_checkout}/#{filename} -d #{apppath}"
end
# create a sysvint sh file to manage dotnet service
initd_directory = "/etc/init.d"
intd_file = File.join(initd_directory, app["shortname"])
template intd_file do
mode "744"
source 'file.sh.erb'
variables(
:service_name => app["shortname"],
:dotnetapp => "#{dotnetapp}",
:apppath => "#{apppath}/publish"
)
end
execute "start service #{dotnetapp}" do
command ".#{initd_directory}/#{appname} start"
environment ({"ASPNETCORE_ENVIRONMENT" => "#{aspnetcore_environment}"})
end
Chef::Log.info("End Install #{appname}")
end
end
# The ERB Template:
#!/bin/bash
#
# description: <%= @service_name %>
#
# Get function from functions library
. /etc/init.d/functions
#
# Start the service <%= @service_name %>
#
start() {
initlog -c "echo -n Starting dotnet <%= @service_name %> server: "
cd <%= @apppath %>
Nohup dotnet <%= @dotnetapp %> /dev/null 2>&1 &
### Create the lock file ###
touch /var/lock/subsys/<%= @service_name %>
success $"<%= @service_name %> server startup"
echo
}
# Restart the service <%= @service_name %>
stop() {
initlog -c "echo -n Stopping dotnet <%= @service_name %> server: "
killproc dotnet
### Now, delete the lock file ###
rm -f /var/lock/subsys/<%= @service_name %>
echo
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status dotnet
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Wenn Sie Ihre AWS-Instanz im VPC-Modus ausführen und keine Sicherheitsgruppe hat, die besagt, dass die eingehende Regel "All Traffic" und "Source" "Anywhere" hat, oder wenn diese Regel "Benutzerdefiniert TCP" lautet, Port ist 5000 und Source ist "Anywhere". Anschließend können Sie keine Verbindung zu diesem Port herstellen. Im VPC-Modus sind alle eingehenden Ports standardmäßig geschlossen, und Sie sollten sie explizit mit einigen vordefinierten oder eigenen Sicherheitsgruppen zulassen.