One place for hosting & domains

      Quickstart

      Cómo instalar Anaconda en Ubuntu 18.04 [Quickstart]


      Introducción

      Diseñado para los flujos de trabajo de ciencia de los datos y aprendizaje automático, Anaconda es un gestor de paquetes de código abierto, gestor de entornos y distribución de los lenguajes de programación Python y R.

      Este tutorial lo guiará a través de la instalación de Anaconda en un servidor Ubuntu 18.04. Para obtener una versión más detallada de este tutorial, con mejores explicaciones de cada paso, consulte Cómo instalar la distribución de Python Anaconda en Ubuntu 18.04.

      Paso 1: obtención de la versión más reciente de Anaconda

      Desde un navegador web, vaya a la página de la distribución Anaconda, disponible en el siguiente enlace:

      https://www.anaconda.com/distribution/
      

      Busque la versión más reciente para Linux y copie la secuencia de comandos bash del instalador.

      Paso 2: descarga de la secuencia de comandos bash de Anaconda

      Con sesión iniciada en su servidor Ubuntu 18.04 como usuario sudo no root, vaya al directorio /tmp y utilice curl para descargar el enlace que copió desde el sitio web de Anaconda.

      • cd /tmp
      • curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh

      Paso 3: verificación de la integridad de los datos del instalador

      Compruebe la integridad del instalador con una comprobación hash criptográfica mediante la suma de comprobación SHA-256:

      • sha256sum Anaconda3-2019.03-Linux-x86_64.sh

      Output

      45c851b7497cc14d5ca060064394569f724b67d9b5f98a926ed49b834a6bb73a Anaconda3-2019.03-Linux-x86_64.sh

      Paso 4: ejecución de la secuencia de comandos de Anaconda

      • bash Anaconda3-2019.03-Linux-x86_64.sh

      Recibirá el siguiente resultado para revisar el acuerdo de licencia pulsando ENTER hasta llegar al final.

      Output

      Welcome to Anaconda3 2019.03 In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>> ... Do you approve the license terms? [yes|no]

      Cuando llegue al final de la licencia, escriba yes, si acepta la licencia, para completar la instalación.

      Paso 5: finalización del proceso de instalación

      Una vez que acepte la licencia, se le pedirá que seleccione la ubicación de la instalación. Puede pulsar ENTER para aceptar la ubicación predeterminada o especificar una ubicación diferente.

      Output

      Anaconda3 will now be installed into this location: /home/sammy/anaconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below [/home/sammy/anaconda3] >>>

      En este momento, se procederá con la instalación. Tenga en cuenta que el proceso puede tardar un tiempo.

      Paso 6: selección de opciones

      Cuando se complete la instalación, recibirá el siguiente resultado:

      Output

      ... installation finished. Do you wish the installer to prepend the Anaconda3 install location to PATH in your /home/sammy/.bashrc ? [yes|no] [no] >>>

      Se recomienda que escriba yes para usar el comando conda.

      Paso 7: activación de la instalación

      Ahora, puede activar la instalación con el siguiente comando:

      Paso 8: instalación de prueba

      Utilice el comando conda para probar la instalación y la activación:

      Recibirá el resultado de todos los paquetes que tiene disponibles a través de la instalación de Anaconda.

      Paso 9: configuración de los entornos de Anaconda

      Puede crear entornos de Anaconda con el comando conda create. Por ejemplo, se puede crear un entorno de Python 3 llamado my_envcon el siguiente comando:

      • conda create --name my_env python=3

      Active el nuevo entorno de esta manera:

      El prefijo de instrucción de su comando cambiará para reflejar que está en un entorno de Anaconda activo, y que, ahora, está listo para empezar a trabajar en un proyecto.

      Tutoriales relacionados

      Aquí tiene enlaces a tutoriales más detallados relacionados con esta guía:



      Source link

      How To Install Python 3 and Set Up a Programming Environment on Ubuntu 18.04 [Quickstart]


      Introduction

      Python is a flexible and versatile programming language, with strengths in scripting, automation, data analysis, machine learning, and back-end development.

      This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server. For a more detailed version of this tutorial, with better explanations of each step, please refer to How To Install Python 3 and Set Up a Programming Environment on an Ubuntu 18.04 Server.

      Step 1 — Update and Upgrade

      Logged into your Ubuntu 18.04 server as a sudo non-root user, first update and upgrade your system to ensure that your shipped version of Python 3 is up-to-date.

      • sudo apt update
      • sudo apt -y upgrade

      Confirm installation if prompted to do so.

      Step 2 — Check Version of Python

      Check which version of Python 3 is installed by typing:

      You’ll receive output similar to the following, depending on when you have updated your system.

      Output

      Python 3.6.5

      Step 3 — Install pip

      To manage software packages for Python, install pip, a tool that will install and manage libraries or modules to use in your projects.

      • sudo apt install -y python3-pip

      Python packages can be installed by typing:

      • pip3 install package_name

      Here, package_name can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. So if you would like to install NumPy, you can do so with the command pip3 install numpy.

      There are a few more packages and development tools to install to ensure that we have a robust set-up for our programming environment:

      • sudo apt install build-essential libssl-dev libffi-dev python3-dev

      Step 5 — Install venv

      Virtual environments enable you to have an isolated space on your server for Python projects. We’ll use venv, part of the standard Python 3 library, which we can install by typing:

      • sudo apt install -y python3-venv

      Step 6 — Create a Virtual Environment

      You can create a new environment with the pyvenv command. Here, we’ll call our new environment my_env, but you can call yours whatever you want.

      Step 7 — Activate Virtual Environment

      Activate the environment using the command below, where my_env is the name of your programming environment.

      • source my_env/bin/activate

      Your command prompt will now be prefixed with the name of your environment:

      Step 8 — Test Virtual Environment

      Open the Python interpreter:

      Note that within the Python 3 virtual environment, you can use the command python instead of python3, and pip instead of pip3.

      You’ll know you’re in the interpreter when you receive the following output:

      Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
      [GCC 7.3.0] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> 
      

      Now, use the print() function to create the traditional Hello, World program:

      Output

      Hello, World!

      Step 9 — Deactivate Virtual Environment

      Quit the Python interpreter:

      Then exit the virtual environment:

      Further Reading

      Here are links to more detailed tutorials that are related to this guide:



      Source link

      How to Install and Secure the Mosquitto MQTT Messaging Broker on Ubuntu 18.04 [Quickstart]


      Introduction

      MQTT is a machine-to-machine messaging protocol, designed to provide lightweight publish/subscribe communication to “Internet of Things” devices. Mosquitto is a popular MQTT server (or broker, in MQTT parlance) that has great community support and is easy to install and configure.

      In this condensed quickstart tutorial we’ll install and configure Mosquitto, and use Let’s Encrypt SSL certificates to secure our MQTT traffic. If you need more in-depth coverage of any of the steps, please review the following tutorials:

      Prerequisites

      Before starting this tutorial, you will need:

      • An Ubuntu 18.04 server with a non-root, sudo-enabled user and basic firewall set up, as detailed in this Ubuntu 18.04 server setup tutorial
      • A domain name pointed at your server. This tutorial will use the placeholder mqtt.example.com throughout
      • Port 80 must be unused on your server. If you’re installing Mosquitto on a machine with a web server that occupies this port, you’ll need to use a different method to fetch certificates, such as Certbot’s webroot mode.

      Step 1 — Installing the Software

      First we will install a custom software repository to get the latest version of Certbot, the Let’s Encrypt client:

      • sudo add-apt-repository ppa:certbot/certbot

      Press ENTER to accept, then install the software packages for Mosquitto and Certbot:

      • sudo apt install certbot mosquitto mosquitto-clients

      Next we’ll fetch our SSL certificate.

      Step 2 — Downloading an SSL Certificate

      Open up port 80 in your firewall:

      Then run Certbot to fetch the certificate. Be sure to substitute your server's domain name here:

      • sudo certbot certonly --standalone --preferred-challenges http -d mqtt.example.com

      You will be prompted to enter an email address and agree to the terms of service. After doing so, you should see a message telling you the process was successful and where your certificates are stored.

      We'll configure Mosquitto to use these certificates next.

      Step 3 — Configuring Mosquitto

      First we'll create a password file that Mosquitto will use to authenticate connections. Use mosquitto_passwd to do this, being sure to substitute your own preferred username:

      • sudo mosquitto_passwd -c /etc/mosquitto/passwd your-username

      You will be prompted twice for a password.

      Now open up a new configuration file for Mosquitto:

      • sudo nano /etc/mosquitto/conf.d/default.conf

      This will open an empty file. Paste in the following:

      /etc/mosquitto/conf.d/default.conf

      allow_anonymous false
      password_file /etc/mosquitto/passwd
      
      listener 1883 localhost
      
      listener 8883
      certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem
      cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem
      keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem
      
      listener 8083
      protocol websockets
      certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem
      cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem
      keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem
      

      Be sure to substitute the domain name you used in Step 2 for mqtt.example.com. Save and close the file when you are finished.

      This file does the following:

      • Disables anonymous logins
      • Uses our password file to enable password authentication
      • Sets up a unsecured listener on port 1883 for localhost only
      • Sets up a secure listener on port 8883
      • Sets up a secure websocket-based listener on port 8083

      Restart Mosquitto to pick up the configuration changes:

      • sudo systemctl restart mosquitto

      Check to make sure the service is running again:

      • sudo systemctl status mosquitto

      Output

      ● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker Loaded: loaded (/etc/init.d/mosquitto; generated) Active: active (running) since Mon 2018-07-16 15:03:42 UTC; 2min 39s ago Docs: man:systemd-sysv-generator(8) Process: 6683 ExecStop=/etc/init.d/mosquitto stop (code=exited, status=0/SUCCESS) Process: 6699 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS) Tasks: 1 (limit: 1152) CGroup: /system.slice/mosquitto.service └─6705 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

      The status should be active (running). If it's not, check your configuration file and restart again. Some more information may be available in Mosquitto's log file:

      • sudo tail /var/log/mosquitto/mosquitto.log

      If all is well, use ufw to allow the two new ports through the firewall:

      • sudo ufw allow 8883
      • sudo ufw allow 8083

      Now that Mosquitto is set up, we'll configure Certbot to restart Mosquitto after renewing our certificates.

      Step 4 — Configuring Certbot Renewals

      Certbot will automatically renew our SSL certificates before they expire, but it needs to be told to restart the Mosquitto service after doing so.

      Open the Certbot renewal configuration file for your domain name:

      • sudo nano /etc/letsencrypt/renewal/mqtt.example.com.conf

      Add the following renew_hook option on the last line:

      /etc/letsencrypt/renewal/mqtt.example.com.conf

      renew_hook = systemctl restart mosquitto
      

      Save and close the file, then run a Certbot dry run to make sure the syntax is ok:

      • sudo certbot renew --dry-run

      If you see no errors, you're all set. Let's test our MQTT server next.

      Step 5 – Testing Mosquitto

      We installed some command line MQTT clients in Step 1. We can subscribe to the topic test on the localhost listener like so:

      • mosquitto_sub -h localhost -t test -u "your-user" -P "your-password"

      And we can publish with mosquitto_pub:

      • mosquitto_pub -h localhost -t test -m "hello world" -u "your-user" -P "your-password"

      To subscribe using the secured listener on port 8883, do the following:

      • mosquitto_sub -h mqtt.example.com -t test -p 8883 --capath /etc/ssl/certs/ -u "your-username" -P "your-password"

      And this is how you publish to the secured listener:

      • mosquitto_pub -h mqtt.example.com -t test -m "hello world" -p 8883 --capath /etc/ssl/certs/ -u "your-username" -P "your-password"

      Note that we're using the full hostname instead of localhost. Because our SSL certificate is issued for mqtt.example.com, if we attempt a secure connection to localhost we'll get an error saying the hostname does not match the certificate hostname.

      To test the websocket functionality, we'll use a public, browser-based MQTT client. Open the Eclipse Paho javascript client utility in your browser and fill out the connection information as follows:

      • Host is the domain for your Mosquitto server, mqtt.example.com
      • Port is 8083
      • ClientId can be left to the default randomized value
      • Path can be left to the default value of /ws
      • Username is your Mosquitto username from Step 3
      • Password is the password you chose in Step 3

      The remaining fields can be left to their default values.

      After pressing Connect, the client will connect to your server. You can publish and subscribe using the Subscribe and Publish Message panes below the Connection pane.

      Conclusion

      We've now set up and tested a secure, password-protected and SSL-encrypted MQTT server. This can serve as a robust and secure messaging platform for your IoT, home automation, or other projects.



      Source link