SQL Server no Linux – The first steps
Posted by Marcos Freccia
Hi everyone,
I might confess that today was actually the very first time that took some courage and created a Linux machine with SQL Server vNext on it. I was a bit curious to see how it was working and to find out how easy it is to install SQL. My knowledge on Linux is near to zero, so I had first to do some searches (mainly in the SQL Server docs and blog posts) the actual steps that was needed to finally connect to an instance running on Linux. Therefore, I hope that I can help someone that is also struggling on this subject 🙂
In all my tests I am using an Azure Virtual Machine, all the steps here described are for this scenario.
PS: Portuguese version below
1 – Create a new Azure Virtual Machine. As you can see in the below image, the OS that I decided to use is Red Hat Enterprise Linux 7.2. In the future it will be available Ubuntu and/or SUSE.
2 – Here it is just a basic window where you have to fill up all the information to create your Azure VM. Something that I noticed here is that you can upload a SSH certificate, so your connection is even more secure to the Azure Environment.
3 – In my case I selected the option “Provide a password”, and then this becomes as simple as Windows, you have to provide an user and password. In this next screen, I am only leaving it available the SSH endpoint, so I can later connect to my machine
3) Right after your Virtual Machine is created, you may want to connect to it and make sure that SQL Server is then properly running. Now the fun part begins 🙂 To acomplish that task you need to install a tool that provide you the bridge to the Linux Machine. In my case I am using Putty, which is a tool to communicate with Linux..
To install in a Windows machine, is quite easy. Next –> Next –> Finish
4) In your Azure console, you may need to get the public IP of your VM.
Open up Putty that you have just installed and then provide the host name (or IP Address). This is where your Public IP will go. If you are trying to connect from a very controlled network you may advise your network team to open up the TCP Port 22, and it should also be allowed in the Azure Endpoint. Now, just click in Open.
Right after you clicked on Open, the below message will show up.
It is basically saying that your key is not cached and then it asks if you trust in the host that you want to connect. Then, just click YES.
5) Now you have to login into your VM. Provide your credentials.
Done! You have successfully connected to a Linux VM on Azure.
6) The very first thing that I did was to verify the SQL Server Service state. To do that, typed the following command:
systemctl status mssql-server
As you can see the SQL Service is not online, because we still need to complete a few configurations. To do so, type the following command:
sudo /opt/mssql/bin/sqlservr-setup
Note: In the screen I only typed Y, but the correct is “YES”. Don’t forget also the provide the SA password, becaue this is first user that you have to use in the first connection that you do.
Now you have a fully running SQL Server.
7) To start up the SQL Service, type the following command:
sudo /opt/mssql/bin/sqlservr-setup –-start-service
Once again, we validate the Service Status and guarantee that SQL Server is running.
Some other commands that may be useful to start and stop the SQL Server Services.
sudo systemctl stop mssql-server
sudo systemctl start mssql-server
sudo systemctl restart mssql-server
8) To connect on the instance, you have to install SQLCMD. This is necessary if you want to connect to the instance from the same host SQL Server is installed.
You need to be in super user mode. Type the following command.
sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
To exit the super user mode
exit
Execute the following command.
sudo yum install mssql-tools
During the installation, it will be prompted a few questios and all you have to do is accept them all. Sometimes you might have to use Y or YES. If everything goes well, you will see the below screen.
To connect, type the following command.
sqlcmd -S myserver -U sa
9) Now you may ask. What do I need to do, to connect remotely? First, in the Azure console, you need to create an Endpoint to SQL Server.
You can control the ports used. If you want to change (which I recommend), all you have to do is modify the created Endpoint. After the setup is completed, open Management Studio.
Done! You have successfully connected to a SQL Server running on Linux…
Those are all the documentations that I have used to create this tutorial.
https://www.microsoft.com/en-us/sql-server/sql-server-vnext-including-Linux
https://docs.microsoft.com/pt-br/sql/linux/sql-server-linux-setup-red-hat
https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-ssh-from-windows
https://docs.microsoft.com/pt-br/sql/linux/sql-server-linux-setup-tools#RHEL
I hope you guys enjoyed! If you have any feedback, use the comments area, I would love to hear from you.
Regards,
Marcos Freccia
Data Platform MVP
_________________________________________________________________________________________________________________________________________________
Olá pessoal,
Confesso que hoje foi realmente a primeira vez que criei uma máquina Linux com o SQL Server vNext. Estava curioso para ver como funcionava e realmente é fácil ou não instalar o SQL Server. Meu conhecimento em Linux é realmente zero, então tive que pesquisar através das documentações como realizar todas as ações que eu precisava para então conectar em uma instancia rodando linux. Se alguem de vocês também precisar realizar algumas dessas operações, espero que essa postagem possa ajudar.
O que eu sinto falta em muitas documentações ou postagens é a falta de clareza nas informações ali passadas, então aqui será realmente um passo-a-passo.
Em meus testes estou usando uma VM no Azure, então os passos aqui são todos voltados para esse cenário.
1) Criar uma máquina Linux no Azure. Como podem ver na imagem abaixo o sistema operacional disponível é o Red Hat Enterprise Linux 7.2, ou seja, no Azure ainda não está disponível Ubuntu ou SUSE (Em Breve)
É importante lembrar que cada distribuição do Linux possuí diferentes comandos.
2) Criar as configurações da sua máquina. Algo que notei nesse passo é que você tem a possibilidade de realizar o upload de um certificado SSH para conexão. Não sei como essa opção funciona, então fico devendo maiores explicações sobre isso.
No meu caso selecionei a opção “Provide a password” e ai é tão simples como em Windows, forneça um usuário e uma senha. Nessa segunda tela estou deixando apenas o endpoint SSH habilitado para então realizar a conexão com a máquina.
3) Feito a criação da máquina você precisa realizar uma conexão e garantir que o SQL Server está propriamente instalado, configurado e principalmente rodando normalmente. Para isso, eu instalei a ferramenta Putty que é o utilitario para comunicação com máquinas Linux.
A instalação aqui é bem simples. Next –> Next –> Finish
4) A máquina estando no ar, você precisa pegar o IP publico dela.
Abra o utilitário do PuTTY que você acabou de instalar e então preencha o campo Host Name (or IP Address) com o IP que você pegou na console do Azure. Deixei aqui um aviso que a Porta 22 precisa estar liberada nos Endpoints do Azure. Feito tudo isso é só clicar em Open.
Logo após você clicar em Open essa mensagem irá aparecer.
Basicamente a mesma está informando que a chave não está em cache nos registros e então pergunta se você confia no host. Apenas clique em YES.
5) A seguir as informações de logon serão requisitadas.
Pronto! Você está agora conectado na máquina virtual Linux.
6) A primeira coisa que fiz após esse passo foi verificar o status do serviço do SQL Server executando o seguinte comando:
systemctl status mssql-server
Como podem notar o serviço não está online, pois precisamos finalizar as configurações. Para isso execute o seguinte comando:
sudo /opt/mssql/bin/sqlservr-setup
Nota: Na imagem apenas digito Y, mas o correto é “YES”. Não esqueça também de fornecer a senha do usuário SA, pois é ele que você irá utilizar para realizar as primeiras conexões na instancia.
Pronto SQL Server configurado.
7) Para iniciar o serviço do SQL Server digite o seguinte comando:
sudo /opt/mssql/bin/sqlservr-setup –-start-service
Verificando mais uma vez o status do serviço do SQL vemos que ele realmente está online.
Outros comandos que podem ser utilizados para iniciar e parar os serviços do SQL Server.
sudo systemctl stop mssql-server
sudo systemctl start mssql-server
sudo systemctl restart mssql-server
8) Para conectar na instancia do SQL Server você precisa instalar o utilitário SQLCMD. Isso serve se você estiver conectado na propria máquina virtual.
Você precisará estar em modo super usuário. Para entrar nesse modo execute.
sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
saia do modo super usuário
exit
Execute o seguinte comando
sudo yum install mssql-tools
Durante essa instalação o shell irá pedir algumas vezes para você aceitar os termos, e ai dependendo você terá que preencher com Y ou y ou YES. Porém não se preocupe, é bem explicito que você precisa tomar uma ação. Se tudo ocorrer bem, você deverá ver a tela abaixo.
Para conectar basta executar o seguinte comando.
sqlcmd -S myserver -U sa
9) Mas para conectar remotamente? Primeiro na console do Azure você precisa liberar o Endpoint do SQL Server.
Se você desejar pode mudar a porta publica para um outro número de preferencia. Assim que a console finalizar a configuração é só utilizar o SQL Server Management Studio.
Pronto! Você está conectado em uma instancia de SQL Server rodando em Linux..
Segue também as varias documentações que utilizei para chegar no resultado final.
https://www.microsoft.com/en-us/sql-server/sql-server-vnext-including-Linux
https://docs.microsoft.com/pt-br/sql/linux/sql-server-linux-setup-red-hat
https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-ssh-from-windows
https://docs.microsoft.com/pt-br/sql/linux/sql-server-linux-setup-tools#RHEL
Espero que vocês gostem dessa postagem, apesar de ela ter ficado um pouco grande
Abraços e um ótimo 2017 a todos vocês!
Marcos Freccia
Data Platform MVP
About Marcos Freccia
MVP em SQL Server (Data Plataform) , especialista em SQL Server, e atualmente trabalhando com Microsoft Azure!Posted on January 2, 2017, in Administração, SQL Server, SQL Server no Linux, VirtualPass and tagged how to install sql server on linux, Instalação SQL Server no Linux, Linux, sql server 2017 linux, SQL Server no Linux, SQL Server on Linux, SQL Server vNext Linux. Bookmark the permalink. 2 Comments.
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Pingback: The most read posts of May – 2017 | Freccia's Blog
Pingback: The most read posts of July – 2017 | Freccia's Blog