我想从AWS Amazon Linux AMI 实例运行.NET Core MVC网站。
到目前为止,我采取了以下步骤:
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
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
cd solution-name/src/web-project-name
。dotnet restore
dotnet build
dotnet run
此时我在终端中看到以下内容:
现在收听:http:// localhost:5000
我尝试使用端口5000标记的AWS DNS / IP(http:// aws-ip-or-dns:5000),但没有得到响应。
我知道 Docker 和 Mono 是我可以使用的工具,但我宁愿让这种方法发挥作用。
我用来安装.NET Core,DNVM和DNX的脚本是这些链接中CentOS和Ubuntu方向的一些组合:
声明 我不熟悉Linux。可以说我不理解我正在运行的一些命令。但是,我在这里学习!
问题: 要获取运行AWS Amazon Linux环境的模板.NET Core Web应用程序,我需要做什么?
(我的猜测是设置HTTP服务器时缺少一些东西)
我需要更多的声望来发布两个以上的链接,所以如果有人想编辑,我会很感激。
答案 0 :(得分:5)
来自@ user326608的答案几乎可以实现,但我将在.NET Core 1.0.0发布后添加我现在使用的步骤。
sudo yum update -y
sudo yum install libunwind -y
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131
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"
git config --global user.email "myGitEmail@something.com"
mkdir /var/coreapp
cd /var/coreapp
git clone https://github.com/myUsername/myRepository.git
sudo chown -R ec2-user /var/coreapp
cd /var/coreapp/solution-name/src/web-project-name
dotnet restore
,构建dotnet build
,然后在后台运行nohup dotnet run > /dev/null 2>&1 &
此解决方案现在对我很有用。我有一个related post尝试创建一个用户数据引导脚本,试图让这更容易。
答案 1 :(得分:1)
对于需要更新上述Microsoft.NETCore.App 1.0.1 2016年9月更新的任何人,https://www.microsoft.com/net/core#centos说明适用于我:
$ mkvirtualenv mysite
ERROR: virtualenvwrapper could not find virtualenv in your path
随后运行sudo apt install virtualenv
给出:
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
之后我删除了dotnet --info
并运行了.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
。
我无法让project.lock.json
直接工作,因为我的RID未知,但使用dotnet restore
dotnet run
并且我Dockerfile
中的此部分工作了:
microsoft/dotnet:onbuild
答案 2 :(得分:0)
如果您正在以VPC模式运行AWS实例,并且您没有安全组说明其入站规则具有“所有流量”且源为“任意位置”或者如果它表示“自定义TCP规则”,则端口是5000并且Source是“Anywhere”然后它将不允许您连接到该端口。 在VPC模式下,默认情况下关闭所有传入端口,您应该明确允许它们使用某些预定义或您自己的安全组。
答案 3 :(得分:0)
如果您使用Opswork(或Chef),您可以使用以下Chef配方https://supermarket.chef.io/cookbooks/dotnetcore在AWS Linux上安装dotnet核心,假设您已使用dotnet发布文件将压缩文件上载到S3存储桶。
图层json的JSON具有app短名称,例如
{
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