| 1 |
|
| 2 |
yum install firewalld -y |
| 3 |
systemctl start firewalld |
| 4 |
systemctl enable firewalld |
| 5 |
firewall-cmd --permanent --zone=public --add-interface=eth0 |
| 6 |
firewall-cmd --permanent --add-service=http --add-service=https --zone=public |
| 7 |
firewall-cmd --reload |
| 8 |
|
| 9 |
# Just for nginx testing... |
| 10 |
|
| 11 |
cat > /srv/robots.txt << EOF |
| 12 |
User-agent: ia_archiver |
| 13 |
Disallow: / |
| 14 |
EOF |
| 15 |
|
| 16 |
yum install epel-release -y |
| 17 |
yum install supervisor -y |
| 18 |
|
| 19 |
cat > /etc/supervisord.d/sample.ini << EOF |
| 20 |
[program:sample] |
| 21 |
command=/usr/bin/dotnet /srv/sample/bin/Debug/netcoreapp1.0/publish/sample.dll |
| 22 |
directory=/srv/sample |
| 23 |
autostart=true |
| 24 |
autorestart=true |
| 25 |
stderr_logfile=/var/log/sample.err.log |
| 26 |
stdout_logfile=/var/log/sample.out.log |
| 27 |
environment=ASPNETCORE_ENVIRONMENT=Production |
| 28 |
user=nginx |
| 29 |
stopsignal=INT |
| 30 |
EOF |
| 31 |
|
| 32 |
# App |
| 33 |
|
| 34 |
yum install libunwind libicu -y |
| 35 |
curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131 |
| 36 |
mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet |
| 37 |
ln -s /opt/dotnet/dotnet /usr/bin |
| 38 |
|
| 39 |
cd /srv |
| 40 |
mkdir sample |
| 41 |
cd sample |
| 42 |
|
| 43 |
cat > project.json << EOF |
| 44 |
{ |
| 45 |
"version": "1.0.0-*", |
| 46 |
"buildOptions": { |
| 47 |
"debugType": "portable", |
| 48 |
"emitEntryPoint": true |
| 49 |
}, |
| 50 |
"dependencies": {}, |
| 51 |
"frameworks": { |
| 52 |
"netcoreapp1.0": { |
| 53 |
"dependencies": { |
| 54 |
"Microsoft.NETCore.App": { |
| 55 |
"type": "platform", |
| 56 |
"version": "1.0.0" |
| 57 |
}, |
| 58 |
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0" |
| 59 |
}, |
| 60 |
"imports": "dnxcore50" |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
EOF |
| 65 |
|
| 66 |
cat > Startup.cs << EOF |
| 67 |
using System; |
| 68 |
using Microsoft.AspNetCore.Builder; |
| 69 |
using Microsoft.AspNetCore.Hosting; |
| 70 |
using Microsoft.AspNetCore.Http; |
| 71 |
namespace sample |
| 72 |
{ |
| 73 |
public class Startup |
| 74 |
{ |
| 75 |
public void Configure(IApplicationBuilder app) |
| 76 |
{ |
| 77 |
app.Run(context => |
| 78 |
{ |
| 79 |
return context.Response.WriteAsync("This verbose monstrosity works."); |
| 80 |
}); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
EOF |
| 85 |
|
| 86 |
cat > Program.cs << EOF |
| 87 |
using System; |
| 88 |
using Microsoft.AspNetCore.Hosting; |
| 89 |
namespace sample |
| 90 |
{ |
| 91 |
public class Program |
| 92 |
{ |
| 93 |
public static void Main(string[] args) |
| 94 |
{ |
| 95 |
var host = new WebHostBuilder() |
| 96 |
.UseUrls("http://unix:/srv/sample/run.sock") |
| 97 |
.UseKestrel() |
| 98 |
.UseStartup() |
| 99 |
.Build(); |
| 100 |
host.Run(); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
EOF |
| 105 |
|
| 106 |
dotnet restore |
| 107 |
dotnet publish |
| 108 |
|
| 109 |
#Nginx |
| 110 |
|
| 111 |
cat > /etc/yum.repos.d/nginx.repo << EOF |
| 112 |
[nginx] |
| 113 |
name=nginx repo |
| 114 |
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/ |
| 115 |
gpgcheck=0 |
| 116 |
enabled=1 |
| 117 |
EOF |
| 118 |
|
| 119 |
yum install -y nginx |
| 120 |
|
| 121 |
export PUBLIC_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
| 122 |
|
| 123 |
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled |
| 124 |
cat > /etc/nginx/conf.d/webapi.conf << EOF |
| 125 |
server { |
| 126 |
listen $PUBLIC_IP:80; |
| 127 |
|
| 128 |
location /robots.txt { |
| 129 |
alias /srv/robots.txt; |
| 130 |
} |
| 131 |
|
| 132 |
location / { |
| 133 |
proxy_pass http://unix:/srv/sample/run.sock; |
| 134 |
|
| 135 |
proxy_redirect off; |
| 136 |
proxy_set_header Host \$host; |
| 137 |
proxy_set_header X-Real-IP \$remote_addr; |
| 138 |
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; |
| 139 |
proxy_set_header X-Forwarded-Host \$server_name; |
| 140 |
} |
| 141 |
} |
| 142 |
EOF |
| 143 |
|
| 144 |
chown -R nginx:nginx /srv |
| 145 |
restorecon -R -v /srv |
| 146 |
|
| 147 |
systemctl start supervisord |
| 148 |
systemctl enable supervisord |
| 149 |
|
| 150 |
systemctl start nginx |
| 151 |
systemctl enable nginx |
| 152 |
|