linux+asp.net core+nginx+sql server
Linux Disibutaion:Ubuntu 16.04.1 LTS
Web Server:Nginx、Kestrel
- 安装.net core
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 sudo apt-get update #Install .NET Core SDK #由于我本地VS安装的.Net Core版本为:dotnet-dev-1.0.0-preview2-003131,所以在linux中安装的.Net Core需要保持一致 sudo apt-get install dotnet-dev-1.0.0-preview2-003131
- 安装npm,gulp,bower
sudo apt-get install npm sudo npm install gulp -g sudo npm install bower -g
- 安装nginx
#安装nginx sudo apt-get install nginx -y #启动nginx sudo service nginx start
因为要使用nginx做asp.net core网站的反向代理,我们需要修改nginx的默认配置文件/etc/nginx/sites-available/default ,将以下内容替换默认配置:
server { listen 80; location / { 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; } }
保存推出,执行如下命令:
#检查nginx配置是否zhengque sudo nginx -t #重新加载nginx配置 sudo nginx -s reload
- 安装supervisor
我们部署的网站并不会自己启动并运行,这里我们就需要用到supervisor这个工具,保证网站的启动和持续运行。
#安装supervisor sudo apt-get install supervisor
配置supervisor,进入目录(/etc/supervisor/conf.d/),新建配置文件hwapp.conf,将如下内容复制到文件中
[program:hwapp] command=/usr/bin/dotnet /var/hwapp/hwapp.dll --server.urls:http://*:5000 directory=/var/hwapp autostart=true autorestart=true stderr_logfile=/var/log/hwapp.err.log stdout_logfile=/var/log/hwapp.out.log environment=ASPNETCORE_ENVIRONMENT=Production user=www-data stopsignal=INT
启动supervisor
sudo service supervisor start
- 安装sql server
Import the public repository GPG keys:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
注册Microsoft SQL Server Ubuntu存储库:
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
安装SQL Server
sudo apt-get update sudo apt-get install -y mssql-server
配置SQL Server
sudo /opt/mssql/bin/sqlservr-setup
验证SQL Server是否启动
systemctl status mssql-server
安装sqlcmd工具
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list sudo apt-get update sudo apt-get install mssql-tools
到此,我们的环境都准备好了,可以在linux上操作SQL Server
我这里在本地VS写了一个asp.net core的demo,去操作安装在linux上的sqlserver。
上图首页上的数据就是从数据库中取出的,见下图:
QQ群:150417854