Instalação do SpeedTest (OoklaServer) no Debian 11 Bullseye gerenciado pelo systemd
Neste tutorial iremos aprender a instalar o SpeedTest Server, porém vamos gerenciar o serviço dele pelo systemd, o que eu acho que já deveriam ter feito, ou a ookla já poderia disponibilizar isso via repositório. #FicaDicaOokla
Leia
– Requisitos do hardware do servidor Speedtest.
– Política de aceitação do servidor Speedtest
– Toda Documentação.
Configuração do DNS
No exemplo vou usar o subdomínio teste, no domínio remontti.com.br teste.remontti.com.br
, logo é necessário configurar seu subdomínio “teste” em seu DNS Server, NÃO USE subdomínio chamado speedtest pois você terá possivelmente seu pedido negado. Exemplo de entradas no DNS para IPv4 (A) e IPv6 (AAAA)
1 2 3 4 5 6 |
[...] teste A 45.80.50.2 AAAA 2804:f123:bebe:cafe::2 [...] |
Distribuição utilizada
Debian 11 Bullseye / Instalação Limpa
Pacotes necessários, não esqueça de virar root de forma correta su -
1 2 |
# su - # apt install vim wget unzip net-tools |
Vamos criar o diretório /usr/local/src/ooklaserver onde ira ficarnossa aplicação OoklaServer.
1 |
# mkdir /usr/local/src/ooklaserver |
Vamos baixar nosso script de instalação em /usr/local/src/ooklaserver e executar a instalação.
1 2 3 4 |
# cd /usr/local/src/ooklaserver # wget https://install.speedtest.net/ooklaserver/ooklaserver.sh # chmod +x ooklaserver.sh # ./ooklaserver.sh install |
Please confirm (y/n) > y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Server Platform is linux64 This will install the Ookla server for linux64 to the current folder. Please confirm (y/n) > y Checking Directory Structure Downloading Server Files % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5973k 100 5973k 0 0 22.3M 0 --:--:-- --:--:-- --:--:-- 22.2M Extracting Server Files OoklaServer OoklaServer.properties.default Starting OoklaServer Daemon Started (715) NOTE: We strongly recommend following instructions at https://www.ookla.com/support/a87011938/ to ensure your daemon starts automatically when the system reboots |
Neste momento o servidor ookla já iniciou, acesse em seu navegado http://sub.dominio:8080 e verifique se o mesmo esta rodando> OoklaServer – It worked!
Pare o serviço ooklaserver
1 |
# ./ooklaserver.sh stop |
1 2 3 4 5 6 7 8 9 |
Stopping OoklaServer Daemon (715) . . . . . . . . . . . . . . . . . . . . Additional OoklaServer processes running; stopping Stopping OoklaServer Daemon (715) . . . . . . . . . . . . . . . . . . . . Stopping OoklaServer Daemon (858) . Stopping OoklaServer Daemon (859) . Stopping OoklaServer Daemon (879) . . . . . . . . . . . . . . . . Lingering OoklaServer processes running; killing (715 964 965) |
Edite o arquivo de configuração OoklaServer
1 |
# vim /usr/local/src/ooklaserver/OoklaServer.properties |
Se você tem IPv6 (Espero que sim) descomente (remova o # da frente) a linha a baixo.
1 |
OoklaServer.useIPv6 = true |
Descomente a linha e inclua todos seus subidominios para seu domínio ex *.remontti.com.br
1 |
OoklaServer.allowedDomains = *.ookla.com, *.speedtest.net, *.remontti.com.br |
Se você desejar visualizar os logs descomente em “# Log to files”. Um arquivo em /usr/local/src/ooklaserver/ooklaserver.log será criado.
1 2 3 4 5 6 7 |
# Log to files # logging.loggers.app.name = Application logging.loggers.app.channel.class = FileChannel logging.loggers.app.channel.pattern = %Y-%m-%d %H:%M:%S [%P - %I] [%p] %t logging.loggers.app.channel.path = ${application.dir}/ooklaserver.log logging.loggers.app.level = information |
Sobreecreva OoklaServer.properties.default com o OoklaServer.properties, para em futuras atualizações (Ocorre automaticamente) ele use como base as suas configurações.
1 |
# cp /usr/local/src/ooklaserver/OoklaServer.properties /usr/local/src/ooklaserver/OoklaServer.properties.default |
Para que o Ooklaserver seja tratado como um serviço vamos configurar-lo no systemd.
1 |
# vim /lib/systemd/system/ooklaserver.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[Unit] Description=OoklaServer-SpeedTest After=network.target [Service] User=root Group=root Type=simple RemainAfterExit=yes WorkingDirectory=/usr/local/src/ooklaserver ExecStart=/usr/local/src/ooklaserver/ooklaserver.sh start ExecReload=/usr/local/src/ooklaserver/ooklaserver.sh restart ExecStop=/usr/local/src/ooklaserver/ooklaserver.sh stop TimeoutStartSec=60 TimeoutStopSec=300 [Install] WantedBy=multi-user.target Alias=speedtest.service |
Recarrege o daemon
1 |
# systemctl daemon-reload |
Verifique o status, nosso serviço ira estar disabled
1 |
# systemctl status ooklaserver |
1 2 3 |
● ooklaserver.service - OoklaServer-SpeedTest Loaded: loaded (/lib/systemd/system/ooklaserver.service; disabled; vendor preset: enabled) Active: inactive (dead) |
Vamos deixa-lo enable para subir com o boot do sistema.
1 |
# systemctl enable ooklaserver |
1 2 |
Created symlink /etc/systemd/system/speedtest.service → /lib/systemd/system/ooklaserver.service. Created symlink /etc/systemd/system/multi-user.target.wants/ooklaserver.service → /lib/systemd/system/ooklaserver.service. |
Verifique se ficou enabled
1 |
# systemctl status ooklaserver |
1 2 3 |
● ooklaserver.service - OoklaServer-SpeedTest Loaded: loaded (/lib/systemd/system/ooklaserver.service; enabled; vendor preset: enabled) Active: inactive (dead) |
Inicie o serviço e verifique seu status se o mesmo ficou active.
1 2 |
# systemctl start ooklaserver # systemctl status ooklaserver |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
● ooklaserver.service - OoklaServer-SpeedTest Loaded: loaded (/lib/systemd/system/ooklaserver.service; enabled; vendor preset: enabled) Active: active (exited) since Fri 2021-11-05 15:31:58 -03; 1s ago Process: 2408 ExecStart=/usr/local/src/ooklaserver/ooklaserver.sh start (code=exited, status=0/SUCCESS) Main PID: 2408 (code=exited, status=0/SUCCESS) Tasks: 47 (limit: 2312) Memory: 10.5M CPU: 185ms CGroup: /system.slice/ooklaserver.service ├─2416 ./OoklaServer --daemon --pidfile=/usr/local/src/ooklaserver/OoklaServer.pid └─2420 /usr/local/src/ooklaserver/OoklaServer --ward --parent-pidfile=OoklaServer.pid --server-id=d907db80a> nov 05 15:31:58 deb11 systemd[1]: Started OoklaServer-SpeedTest. nov 05 15:31:59 deb11 ooklaserver.sh[2408]: Starting OoklaServer nov 05 15:31:59 deb11 ooklaserver.sh[2408]: Daemon Started (2416) |
Se desejar reinicie o servidor para ver se o serviço ooklaserver carregou no boot!
1 |
# reboot |
Ao voltar verifique se o mesmo iniciou.
1 |
# systemctl status ooklaserver |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
● ooklaserver.service - OoklaServer-SpeedTest Loaded: loaded (/lib/systemd/system/ooklaserver.service; enabled; vendor preset: enabled) Active: active (exited) since Fri 2021-11-05 15:34:19 -03; 22s ago Process: 332 ExecStart=/usr/local/src/ooklaserver/ooklaserver.sh start (code=exited, status=0/SUCCESS) Main PID: 332 (code=exited, status=0/SUCCESS) Tasks: 50 (limit: 2312) Memory: 18.3M CPU: 157ms CGroup: /system.slice/ooklaserver.service ├─390 ./OoklaServer --daemon --pidfile=/usr/local/src/ooklaserver/OoklaServer.pid └─404 /usr/local/src/ooklaserver/OoklaServer --ward --parent-pidfile=OoklaServer.pid --server-id=da57142421> nov 05 15:34:19 deb11 systemd[1]: Started OoklaServer-SpeedTest. nov 05 15:34:20 deb11 ooklaserver.sh[332]: Starting OoklaServer nov 05 15:34:20 deb11 ooklaserver.sh[332]: Daemon Started (390) |
Certifique-se acessando em seu navegador http://sub.dominio:8080.
O serviço ooklaserver tem um alias com o nome speedtest, então se quiser usar systemctl status speedtest
também funiona. 😉
1 |
# systemctl status speedtest |
Para verificar a versão use:
1 |
# /usr/local/src/ooklaserver/OoklaServer -v |
Se você realizar o teste agora https://www.ookla.com/pt/host-tester você encontrará 1 erros:
É que você não tem certificado válido, a OoklaServer fala que você pode usar o certifica automatico que ela ira gerar, ao fazer o registro. Nota: Este processo automatizado só começa depois que o servidor foi registrado e revisado por Ookla . Você pode ler aqui mais sobre.
Solução para o certificado
Vamos instalar o Certbot, que irá gerar os certificados com o Let’s Encrypt.
1 |
# apt install certbot |
Geramos o certificado para teste.remontti.com.br, lembrando que seu servidor DNS deve estar apontando para o IP Publivo do seu servidor para poder gerar o certificado sem erro.
1 |
# certbot certonly --standalone |
Reponda: email (null@remontti.com.br), Y, N, Seu Domínio
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): null@remontti.com.br <<<<<<<<<<<<<<<<<<<<< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server. Do you agree? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y <<<<<<<<<<<<<<<<<<<<< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: N <<<<<<<<<<<<<<<<<<<<< Account registered. Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel): teste.remontti.com.br <<<<<<<<<<<<<<<<<<<<< Requesting a certificate for teste.remontti.com.br Performing the following challenges: http-01 challenge for teste.remontti.com.br Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/teste.remontti.com.br/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/teste.remontti.com.br/privkey.pem Your certificate will expire on 2022-02-03. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
Os arquivos do certificado foram criados em /etc/letsencrypt/live/SUB.DOMINIO.XXX.XX/ com validade de 90 dias.
Edite o arquivo de configuração OoklaServer, para usar o nosso certificado gerado.
1 |
# vim /usr/local/src/ooklaserver/OoklaServer.properties |
Localize openSSL.server.certificateFile e openSSL.server.privateKeyFile
1 2 |
# openSSL.server.certificateFile = cert.pem # openSSL.server.privateKeyFile = key.pem |
Descomente as linhas e e adicione o caminho para os seus.
1 2 |
openSSL.server.certificateFile = /etc/letsencrypt/live/SUB.DOMINIO.XXX.XX/fullchain.pem openSSL.server.privateKeyFile = /etc/letsencrypt/live/SUB.DOMINIO.XXX.XX/privkey.pem |
Sobreecreva OoklaServer.properties.default com o OoklaServer.properties novamente para em futuras atualizações.
1 |
# cp /usr/local/src/ooklaserver/OoklaServer.properties /usr/local/src/ooklaserver/OoklaServer.properties.default |
Reinicie o OoklaServer. (Pode levar ate 2min, tenha paciência)
1 |
# systemctl restart ooklaserver.service |
Agora acesse com HTTPS em seu navegador: https://sub.dominio:8080, e o certificado agora deve ser válido.
Realizando os testes novamente em https://www.ookla.com/pt/host-tester, o erro de certificado estará resolvido.
Mais ao final deixarei um script para renovação automática do certificado, pois o mesmo é valido apenas por 90 dias.
Cadastro Ookla
Hora de criar sua conta no ookla.com e fazer a solicitação para virar um host! https://account.ookla.com/register/servers, se você já tem acesse: https://account.ookla.com/servers/create
Com sua conta criada e validada no e-mail de verificação logue: https://account.ookla.com/, clique em Go To Servers, e aceite os Termos. Add Server preencha com os seus dados e do servidor.
Agora basta aguardar, pode levar alguns dias para aprovação, você receberá um e-mail lhe avisado (se não for aprovado eles lhe dirão porque). Boa sorte!
Renovar o certificado automaticamente
Para evitar que o certificado expire faremos um script colocando o certbot para renovar uma vez ao mês pelo cron do servidor.
1 |
# vim /usr/local/src/ooklaserver/renova-certificado |
Adicione:
1 2 3 4 5 6 7 |
#!/bin/bash # Renova o certificado /usr/bin/certbot renew -q # Aguarda o certificado renovar sleep 30 # Reinicie o OoklaServer /usr/bin/systemctl restart ooklaserver |
De permissão para execução e adicione ao cron, para que ele rode o script toda a meia noite do dia 1º de cada mês.
1 2 |
# chmod +x /usr/local/src/ooklaserver/renova-certificado # echo '00 00 1 * * root /usr/local/src/ooklaserver/renova-certificado' >> /etc/crontab |
Verifique se a última linha está nosso script.
1 |
# cat /etc/crontab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) # 00 00 1 * * root /usr/local/src/ooklaserver/renova-certificado |
Reinici o cron para ele carregar a nova rotina.
1 |
# systemctl restart cron |
Se o certificado por venturar expirar e o script não renovar, basta você rodar na mão:
1 2 |
# certbot renew # systemctl restart ooklaserver |
Parabéns seu servidor está pronto!
Se quiser fazer uma doação para o café ficarei muito feliz pelo seu reconhecimento!
Se não puder doar pode deixar seu agradecimento nos comentário também ficarei feliz em saber que ajudei. Se tiver qualquer pergunta deixe-a também. Se preferir entrar em Contato clique aqui.
Tutorial impecável! Café foi pago kkk!
Obrigado!
O validador corrigiu a porta no teste. Agora o arquivo crossdomain.xml nao apresenta mais falha. Ficando desnecessário o uso do apache. Vlw
Bom dia!
Seria possível utilizar vários servidores speedtest em uma maquina apenas ?
Testando aqui e estou enfrentando problemas com o certificado SSL.
muito bom Rudimar vc é monstro funcionou 100%
Parabéns pelo ótimo tutorial!
Apenas um detalhe, que no script para renovar o certificado você chama o certbot com a flag –dryrun, que deve apenas “testar” se consegue renovar o certificado, e não renovar de fato.
Também achava que fosse assim, mas lendo a documentação lá diz:
Se esse comando for concluído sem erros, seus certificados serão renovados automaticamente em segundo plano.
Também observei esse disclaimer na documentação, mas me parece estar mal escrito hehehe, dando a entender de que se o “teste” feito em dry-run foi bem sucedido, as renovações automáticas vão ocorrer com sucesso…
Fiquei na duvida se vai funciona, na dúvida vou por editar para
Como de costume, sempre inovando parabéns mestre.