Windows Server 2012

Trabalhar com ferramentas Microsoft é uma aventura. Mas uma aventura tipo pesadelo, tipo Assalto à 13ª esquadra, do Carpenter, ou algo do género.

Trabalho com Linux há mais de 20 anos, e raramente tenho problemas destes. Aquilo que se aprende em administração de sistemas Linux, dura anos, ou décadas: as mudanças radicais são raras. Em Windows, ao invés, mudam sempre que sai um sistema novo.

Estou a configurar um Windows Server 2012 R2, e é diferente do que eu tinha antes, o 2008. Aliás, é sempre tudo completamente diferente. Está tudo, sempre, em sítios diferentes… O que vale é que na net@ respondem a estas dúvidas todas, porque milhares já as tiveram.

Ao tentar ativar o IIS, deu erros de instalação, sem mensagens detalhadas. Dizia apenas que falhou. Eis o que aconteceu. Consultei um site na net@ que explicava que parâmetros devia ativar. Selecionei-os todos e premi o botão “Install”. Deu erro. Voltei ao início e tentei instalar um item de cada vez, para tentar perceber qual deles tinha gerado o erro: já não deu erro e consegui instalar todos.

A solução para ativar o IIS, tirei-a daqui: Enabling IIS and required IIS components on Windows Server 2012/2012 R2. Os passos são os seguintes:

  1. Open Server Manager and click Manage > Add Roles and Features. Click Next.
  2. Select Role-based or feature-based installation and click Next.
  3. Select the appropriate server. The local server is selected by default. Click Next.
  4. Enable Web Server (IIS) and click Next.
  5. No additional features are necessary to install the Web Adaptor, so click Next.
  6. On the Web Server Role (IIS) dialog box, click Next.
  7. On the Select role services dialog box, verify that the web server components listed below are enabled. Click Next.
  8. Verify that your settings are correct and click Install.
  9. When the installation completes, click Close to exit the wizard.

Como esta máquina vai correr como máquina virtual, em modo headless, preciso de aceder a ela através do Remote Desktop Connection. Também aí deu erro. Depois de configurar o servidor, para aceitar ligações, de configurar a firewall desse servidor, assim como as firewalls de dois gateways Linux que estão pelo meio, ao ligar-me obtive o erro seguinte: “Remote Desktop Authentication Error Has Occurred. The function requested is not supported”. Impenetrável. Mas vá lá, na TecNet tinham uma solução. Funciona, mas é uma solução de brincadeira. Configuramos tudo o que é necessário e que está nos manuais, e depois, se queremos que o sistema funcione, temos que dar o chupa-chupa ao cão.

Neste caso, foi necessário, na máquina local (o cliente), autorizar o próprio protocolo do RDC, pois este é vulnerável a determinado tipo de ataques! Fantástico. A Microsoft usa um protocolo vulnerável e, em vez de o corrigir, inativa-o. Segue a solução

Correr: gpedit.msc
Ir a Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Encryption Oracle Remediation
Abrir - Encryption Oracle Remediation, escolher Enable, alterar Protection Level para Vulnerable e premir Apply.

Aproveito e deixo aqui – para não me esquecer e poder configurar as firewalls do Linux – informação sobre os portos que é necessário abrir para aceder ao SQL Server da Microsoft: Configure the Windows Firewall to Allow SQL Server Access.

SQL Server default instance: 1433, em TCP
SQL Server named instances (é necessário fixar): 1434, em UDP
Dedicated Admin Connection: 1434, em TCP
SQL Server Browser service: 1434, em UDP
SQL Server instance running over HTTP(S): 80 ou 443, em TCP
Service Broker (confirmar com query): 4022, em TCP
Database Mirroring (confirmar com query): 5022 ou 7022, em TCP
Replication: 1433, em TCP
Transact-SQL debugger: 135, em TCP

Fica também o aviso de que é muito provável que a instalação Custom do SQLServer Express pendure. Depois de 2 horas à espera num ecrã parado, num aparente fim de instalação, fui à net@ e vi muitas queixas de pessoal que quis fazer instalações personalizadas. Vou tentar a instalação Basic e depois acrescento itens um a um. Que perda de tempo. Grande Microsoft.
(…)
E assim foi: a instalação Basic demorou 5 minutos. Os outros itens demoraram um pouco mais, alguns também emperraram e não me deram oportunidade de configurar tudo o que queria. Mas eu também não espero muito mais do que isto da Microsoft.
(..)
E isto é uma saga. Na documentação da Microsoft, dizem que o SQL Server corre no porto 1433. Configurei as firewalls todas para deixarem passar os pacotes para este porto, mas não conseguia comunicar com o SQL Server. Afinal o servidor está a escutar um porto dinâmico, e, além disso, nem sequer tem o protocolo TCP ativo.
Ainda precisei das configurações que encontrei neste artigo – Configuring a SQL Server for Remote Connections – para conseguir pôr o SQL Server acessível remotamente. Fica aqui um resumo, com alguns erros corrigidos (as figuras terão que as ver no site original):

A. Enabling Remote Connections on the Instance of SQL Server

First, you will ned to enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.

1) Open & Login SQL Management Studio. Right-click on the server name in the Object Explorer and select “Properties” to access the Server Properties Window.

2) In the left pane of the Server Properties Window, select “Connections” and under “Remote Server Connections”, check the box next to “Allow remote connections to this server.” Click OK.

B. Configure SQL Server to Listen on Static Port

1) Open the SQL Server Configuration Manager and click on “SQL Server Services” in the left pane.

2) In the center, you will see a column that lists the Process ID for each running service. Look for the Process ID in the row for the SQL Server. Identify the port that the PID is listening on by typing the following into a command prompt: netstat -ano | find /i “PID-Number_of_SQL-Server”. In the example based on figure 3, you would type the following into the command prompt: netstat –ano | find /I “NUMBER”. For an example, please see Figure 4 below.

3) By default, the TCP/IP protocol is disabled and must be enabled. If you do not enable the TCP/IP protocol, there will be no results from the command executed in step 2. To enable the TCP/IP protocol, go to the SQL Server Configuration manager and click on “SQL Server Network Configuration”. Right click on the “TCP/IP” protocol and select “Enable”.

4) Restart the SQL Server service and identify the Process ID assigned to the SQL Service.

5) In the command prompt, execute the following command: netstate –ano | find /i “PROCESSID”. In the example below, the command would be: netstate –ano | find /i “NUMBER”. Results should be seen as below in Figure 7.

6) Return to the SQL Server Configuration Manager. Click on “SQL Server Network Configuration” in the left pane and right-click the “TCP/IP” protocol and select “Properties”. Go to the “IP Addresses” tab and scroll down to the IPALL section. Remove the value for TCP Dynamic Ports (leaving it blank) and enter the port 1433 for TCP port.

7) Restart the SQL Server Service, identify the new process ID assigned to the SQL service. In the command prompt, execute the following command: netstate – ano | find /i “3948”. Results should be displayed as shown in Figure 9 below.

8) The SQL Express is now configured to listen on standard port 1433.

C. Turn On the SQL Server Browser Service

1) Open the SQL Server Configuration Manager. Click on “SQL Server Services” in the left pane and right click on “SQL Server Browser Service” and click “Properties”.

2) In the SQL Server Browser Properties Window, click on the “Service” tab. Under the “Start Mode” option, change the start type to “Automatic”. Click “Apply”.

3) In the SQL Server Browser Properties Window, click on the “Log On” tab. Click the “Start” button to start the SQL Browser Service.

4) In the SQL Server Browser, confirm that the service is running as shown in figure 13.

Note: According to SQL Server Hardening best practices, the SQL Server Browser service should be disabled. This service is typically not required. The SQL Server Browser service responds to requests for SQL Server resources and redirects the caller to the correct port. Keeping the Browser service disabled will remove the redirector as an attack vector, helping to obscure the correct entry ways into your SQL Server components.

D. Configure the Firewall to Allow Network Traffic Related to SQL Server and the SQL Server Browser Service

In Windows Firewall, four exceptions must be configured to allow access to the SQL Server.

1) A port exception for TCP Port 1433. In the new Inbound Rule Wizard dialoag, use the following information to create a port exception:

Select “Port”
Select “TCP” and specify port “1433”
Allow the connection
Choose all three profiles (Domain, Private, and Public)
Name the rule “SQL – TCP 1433”

2) A port exception for UDP Port 1434. Click the New Inbound Rule Wizard dialog and use the following information to create another port exception:

Select “Port”
Select “UDP” and specify port “1434”
Allow the connection
Choose all three profiles (Domain, Private, and Public)
Name the rule “SQL – UDP 1434”

3) A program exception for exe. Click the New Inbound Rule Wizard dialog and use the following information to create a program exception:

Select “Program”
Click “Browse” to select “sqlserver.exe” in the following location:

C:\Program Files\Microsoft SQL Server\MSSQL11.\MSSQL\Binn\sqlservr.exe where is the name of your SQL instance.

Allow the connection
Choose all three profiles (Domain, Private, and Public)
Name the rule “SQl – Sqlservr.exe”

4) A program exception for exe. Click the New Inbound Rule Wizard dialog and use the following information to create another program exception:

Select “Program”
Click “Browse” to select sqlbrowser.exe. By default, it is located in the following location:

C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe

Allow the connection
Choose all three profiles (Domain, Private, and Public)
Name the rule “SQL – sqlbrowser.exe”


Entretanto, por duas vezes não consegui desligar o IIS usando o IIS Manager. Tenho andado a fazer alterações na configuração e já tive que desligá-lo várias vezes. Isto nunca me aconteceu com o Apache, com o qual trabalho há mais de 15 anos. O Apache desliga-se sempre. O IIS neste Windows 2012, com o qual trabalho há 2 dias, já vai em 2 vezes que se recusa a desligar-se. Tive que desligar a máquina. Entretanto, disseram-me para experimentar desligá-lo na linha de comando para ver se recebo alguma informação sobre o problema. O comando é o seguinte:

net stop iisadmin /y


Publicado

em

por

Etiquetas:

Comentários

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *