<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jean-Michel ARNAUD on Medium]]></title>
        <description><![CDATA[Stories by Jean-Michel ARNAUD on Medium]]></description>
        <link>https://medium.com/@j3amail?source=rss-e321cd093337------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cgqhOYY9B0db3woNkKh0dA.jpeg</url>
            <title>Stories by Jean-Michel ARNAUD on Medium</title>
            <link>https://medium.com/@j3amail?source=rss-e321cd093337------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:37:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@j3amail/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Secure a VPS on Ubuntu]]></title>
            <link>https://medium.com/@j3amail/secure-a-vps-on-ubuntu-afef9756b832?source=rss-e321cd093337------2</link>
            <guid isPermaLink="false">https://medium.com/p/afef9756b832</guid>
            <category><![CDATA[rsa]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[fail2ban]]></category>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Jean-Michel ARNAUD]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 13:12:03 GMT</pubDate>
            <atom:updated>2025-01-24T15:21:57.181Z</atom:updated>
            <content:encoded><![CDATA[<p>To start securing your admin connection to an ubuntu server, we will install fail2ban (jails for malicious attempts), change the SSH default port, and use a pair of public and private keys to avoid having to enter a password for your admin connection from your local computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhSeZ4RGQusDZYKYxSuynA.png" /><figcaption>Change SSH port, put malicious IP in jails, strengthen admin connection</figcaption></figure><pre>* Install jails to block force brute attacks (with fail2ban)<br>* Change SSH port<br>* Use a private key</pre><p>The following instructions have been tested with Ubuntu 24.04.1 LTS.</p><p>If you want to know the version of your Virtual Private Server, enter the command:</p><pre>lsb_release -a</pre><p>Update and upgrade your system:</p><pre>sudo apt-get update<br>sudo apt-get upgrade</pre><p><strong>{1} Install jails to block force brute attacks</strong></p><blockquote>Fail2ban is designed to protect against repeated failed login attempts, such as those seen in SSH, Apache, FTP, and other services. When a malicious behavior is detected, Fail2ban can automatically update firewall rules to block the offending IP address for a specified period. This period can be configured and is typically set to a time that increases with each subsequent block.</blockquote><p>Let’s install it:</p><pre>sudo apt-get install fail2ban</pre><p>Check that this new service is running:</p><pre>systemctl status fail2ban</pre><p>You can review the default configuration to find which services are monitored by fail2ban:</p><pre>vi /etc/fail2ban/jail.conf</pre><p>By default, only the SSH service is taken into account by fail2ban. You can view it with the following command:</p><pre>sudo fail2ban-client status</pre><p>The main configuration file for the jails, “jail.conf”, includes many services, but they are not enabled. So, we need to update the file “defaults-debian.conf” located in the directory “jail.d”.</p><pre>sudo vi /etc/fail2ban/jail.d/defaults-debian.conf </pre><p>And update it like that for enabling two services:</p><pre>[DEFAULT]<br>banaction = nftables<br>banaction_allports = nftables[type=allports]<br>backend = systemd<br><br>[sshd]<br>enabled = true<br><br>[apache-auth]<br>enabled = true<br></pre><p>Restart the service:</p><pre>sudo systemctl restart fail2ban</pre><p>And display the service status to see the two services that have been enabled:</p><pre>sudo fail2ban-client status</pre><pre>Status<br>|- Number of jail: 2<br>`- Jail list: apache-auth, sshd</pre><p><strong>{2} Change default SSH port</strong></p><p>The current port for the SSH service is 22. You can see it with the following command:</p><pre>grep Port /etc/ssh/sshd_config</pre><p>And to have the confirmation:</p><pre>sudo lsof -i :22</pre><p>Now, define a port with a number higher than 10000 and confirm that this port is not currently in use (here, we took 48315):</p><pre>sudo lsof -i :48315</pre><p>Open the configuration file:</p><pre>sudo vi /etc/ssh/sshd_config</pre><p>And insert a new line with the required port (just below the commented line with the default port):</p><pre>#Port 22<br>Port 48315</pre><p>Now we need to retsart the server:</p><pre>sudo reboot</pre><p><strong>{3} Use a private key</strong></p><p>On your local computer, open a new shell tab.</p><p>On your local computer, check that the tool ssh-keygen is installed:</p><pre>which ssh-keygen</pre><p>If this is the case, you will the command path, otherwise, you will need to install it.</p><p>On your local computer, enter the command:</p><pre>ssh-keygen</pre><p>When prompted, enter a pass phrase to increase the security of your key.</p><p>At the end of the process, on your local computer, in your directory ~/.ssh/, you will get one file with the private key “id_ed25519” and another one with the public key “id_ed25519.pub”.</p><pre>ls -l ~/.ssh/*</pre><p>Now, you need to send your public key to the VPS:</p><pre>ssh-copy-id -p [PORT] [LOGIN]@[IP]</pre><p>The ssh-copy-id tool comes with openssh, so you should have it. During the process, your VPS password will be required.</p><p>Now, you should be able to connect to the VPS without entering your password:</p><pre>ssh [login]@[IP] -p [PORT]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afef9756b832" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting to a VPN using an Ubuntu Headless Server]]></title>
            <link>https://medium.com/@j3amail/connecting-to-a-vpn-using-an-ubuntu-headless-server-67d9ce8baa11?source=rss-e321cd093337------2</link>
            <guid isPermaLink="false">https://medium.com/p/67d9ce8baa11</guid>
            <category><![CDATA[ubuntu-server]]></category>
            <category><![CDATA[openvpn]]></category>
            <dc:creator><![CDATA[Jean-Michel ARNAUD]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 16:26:18 GMT</pubDate>
            <atom:updated>2024-12-06T16:26:18.149Z</atom:updated>
            <content:encoded><![CDATA[<p>A step by step guide to open a VPN connection from an Ubuntu headless server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zFQNOyMT6x-8CyPSKlVyA.png" /></figure><p><strong>1/ Install</strong></p><p>Connect to your server using the root account:</p><pre>ssh ubuntu@yourserver.com</pre><p>And install OpenVPN:</p><pre>sudo apt update<br>sudo apt install openvpn</pre><p>Then close the root session.</p><p><strong>2/ Set up your VPN configuration</strong></p><p>Connect to your server using the account for which you want to use to open a VPN connection to another server :</p><pre>ssh user@yourserver.com</pre><p>Create a directory to store the following files:</p><ol><li>“ca.crt” for the certificate authority</li><li>“client.crt” and “client.key” for a .crt/.key file pair</li><li>“credentials” with the username and his password</li><li>“config.ovpn” listing the information needed to OpenVPN</li></ol><pre>mkdir client_vpn<br>cd client_vpn<br>echo &#39;&#39; &gt; ca.crt<br>chmod 600 ca.crt<br>echo &#39;&#39; &gt; client.crt<br>chmod 600 client.crt<br>echo &#39;&#39; &gt; client.key<br>chmod 600 client.key<br>echo &#39;&#39; &gt; credentials<br>chmod 600 credentials<br>echo &#39;&#39; &gt; config.ovpn</pre><p>The credentials file contains two pieces of information, the username and the password that will be used to open the VPN connection:</p><pre>username<br>password</pre><p>The final file, “config.ovpn”, looks like that:</p><pre># We are a client.<br>client<br><br># TUN interface<br>dev tun<br><br># UDP server<br>proto udp<br><br># The hostname/IP and port of the server.<br>remote aws-vpn.bboxx.co.uk 1194 udp<br>remote aws-vpn.bboxx.co.uk 443 tcp<br><br># User credentials<br>auth-user-pass credentials<br><br># Most clients don&#39;t need to bind to<br># a specific local port number.<br>nobind<br><br># Try to preserve some state across restarts.<br>persist-tun<br><br># SSL/TLS parms.<br># See the server config file for more<br># description.  It&#39;s best to use<br># a separate .crt/.key file pair<br># for each client.  A single ca<br># file can be used for all clients.<br>ca ca.crt<br>cert client.crt<br>key client.key<br><br># Verify server certificate by checking that the<br># certificate has the correct key usage set.<br>remote-cert-tls server<br><br># Set log file verbosity.<br>verb 3<br><br># Silence repeating messages<br>mute 20</pre><p><strong>3/ Open the VPN connection</strong></p><p>Open the connection:</p><pre>openvpn --config config.ovpn &gt; /dev/null 2&gt;&amp;1</pre><p>Try to ping now the server to check that everything is ok.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67d9ce8baa11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyse the behaviour of a solar photovoltaic system using Python]]></title>
            <link>https://medium.com/@j3amail/analyse-the-behaviour-of-a-solar-photovoltaic-system-using-python-465bb4b497d0?source=rss-e321cd093337------2</link>
            <guid isPermaLink="false">https://medium.com/p/465bb4b497d0</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[photovoltaic]]></category>
            <category><![CDATA[solar-panels]]></category>
            <category><![CDATA[battery-management-system]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Jean-Michel ARNAUD]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 13:49:41 GMT</pubDate>
            <atom:updated>2024-09-18T13:49:41.689Z</atom:updated>
            <content:encoded><![CDATA[<p>Considering a solar system made up of a production set (solar panels, batteries, inverter) and a consumption set (light bulbs, fan, TV, freezer), we will simulate this electrical system, paying particular attention to the level of discharge of the batteries. For the main technical characteristics of the production set, we will simulate each characteristic in a range of values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ho53SsKCNGtHA0kMgpkb1A.png" /></figure><p>This story has four chapters:</p><p><strong>{1} The assumptions input file</strong></p><p><strong>{2} The methodology used</strong></p><p><strong>{3} The python script</strong></p><p><strong>{4} The results</strong></p><p>We will focus the modelisation on generating the total load curve for the appliances and compare this load curve to the total production curve (including the energy stored in the batteries when possible). Let’s present how we structure the different files we need:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dhb86wjTdkaUiJ1OPaxokg.png" /></figure><p>And how we launch the calculator:</p><pre>python3 calculator.py test</pre><p>“test” is the name of the set of assumptions to evaluate. The spreadsheets generated will begin with this name.</p><p><strong>{1} The assumptions input file</strong></p><p>The assumption input files contains an entry for each main item of the solar system. To explain each entry, we will present the following “test” scenario:</p><pre>{<br>    &quot;period&quot;: {<br>        &quot;h0&quot;: 10,<br>        &quot;days&quot;: 3<br>    },<br>    &quot;solarPanels&quot;: {<br>        &quot;power&quot;: {<br>            &quot;range&quot;: [ 500, 1500 ],<br>            &quot;step&quot;: 50,<br>            &quot;unit&quot;: &quot;Wp&quot;<br>        },<br>        &quot;price&quot;: 0.3<br>    },<br>    &quot;batteries&quot;: {<br>        &quot;capacity&quot;: {<br>            &quot;range&quot;: [ 50, 200 ],<br>            &quot;step&quot;: 10,<br>            &quot;unit&quot;: &quot;Ah&quot;,<br>            &quot;init&quot;: 0.8,<br>            &quot;maxDischarge&quot;: 0.5<br>        },<br>        &quot;voltage&quot;: {<br>            &quot;range&quot;: [ 24, 24 ],<br>            &quot;step&quot;: 1,<br>            &quot;unit&quot;: &quot;V&quot;<br>        },<br>        &quot;price&quot;: 100.0<br>    },<br>    &quot;sun&quot;: {<br>        &quot;irradiationCoefficient&quot;: {<br>            &quot;range&quot;: [ 4400, 6400 ],<br>            &quot;step&quot;: 100,<br>            &quot;unit&quot;: &quot;Wh/m²/day&quot;<br>        },<br>        &quot;profile&quot;: [<br>            [ 6.5, 7.0, 0.2 ],<br>            [ 7.0, 7.5, 0.5 ],<br>            [ 7.5, 8.5, 0.75 ],<br>            [ 8.5, 17.0, 1.0 ],<br>            [ 17.0, 17.5, 0.75 ],<br>            [ 17.5, 18.5, 0.5 ],<br>            [ 18.5, 19.0, 0.2 ]<br>        ]<br>    },<br>    &quot;appliances&quot;: [<br>        {<br>            &quot;name&quot;: &quot;light&quot;,<br>            &quot;unitPower&quot;: 8,<br>            &quot;quantity&quot;: 8,<br>            &quot;profile&quot;: [<br>                [  0.0,  6.0, 0.12 ],<br>                [  6.0,  7.0, 0.50 ],<br>                [ 18.0, 18.5, 0.50 ],<br>                [ 18.5, 23.0, 1.00 ],<br>                [ 23.0, 24.0, 0.12 ]<br>            ]<br>        },{<br>            &quot;name&quot;: &quot;fan&quot;,<br>            &quot;unitPower&quot;: 30,<br>            &quot;quantity&quot;: 1,<br>            &quot;profile&quot;: [<br>                [ 14.0, 21.0, 1.00 ]<br>            ]<br>        },{<br>            &quot;name&quot;: &quot;television&quot;,<br>            &quot;unitPower&quot;: 100,<br>            &quot;quantity&quot;: 1,<br>            &quot;profile&quot;: [<br>                [ 16.0, 22.0, 1.00 ]<br>            ]<br>        }, {<br>            &quot;name&quot;: &quot;freezer&quot;,<br>            &quot;unitPower&quot;: 200,<br>            &quot;quantity&quot;: 1,<br>            &quot;profile&quot;: [<br>                [  0.0,  0.1, 0.50 ],<br>                [  0.5,  0.6, 0.50 ],<br>                [  1.0,  1.1, 0.50 ],<br>                [  1.5,  1.6, 0.50 ],<br>                [  2.0,  2.1, 0.75 ],<br>                [  2.5,  2.6, 0.75 ],<br>                [  3.0,  3.1, 0.75 ],<br>                [  3.5,  3.6, 0.75 ],<br>                [  4.0,  4.1, 0.75 ],<br>                [  4.5,  4.6, 0.75 ],<br>                [  5.0,  5.1, 0.75 ],<br>                [  5.5,  5.6, 0.75 ],<br>                [  6.0,  6.1, 0.75 ],<br>                [  6.5,  6.6, 0.75 ],<br>                [  7.0,  7.1, 1.00 ],<br>                [  7.5,  7.6, 1.00 ],<br>                [  8.0,  8.1, 1.00 ],<br>                [  8.5,  8.6, 1.00 ],<br>                [  9.0,  9.1, 1.00 ],<br>                [  9.5,  9.6, 1.00 ],<br>                [ 10.0, 10.1, 1.00 ],<br>                [ 10.3, 10.4, 1.00 ],<br>                [ 10.6, 10.7, 1.00 ],<br>                [ 11.0, 11.1, 1.00 ],<br>                [ 11.3, 11.4, 1.00 ],<br>                [ 11.6, 11.7, 1.00 ],<br>                [ 12.0, 12.1, 1.00 ],<br>                [ 12.3, 12.4, 1.00 ],<br>                [ 12.6, 12.7, 1.00 ],<br>                [ 13.0, 13.1, 1.00 ],<br>                [ 13.3, 13.4, 1.00 ],<br>                [ 13.6, 13.7, 1.00 ],<br>                [ 14.0, 14.1, 1.00 ],<br>                [ 14.3, 14.4, 1.00 ],<br>                [ 14.6, 14.7, 1.00 ],<br>                [ 15.0, 15.1, 1.00 ],<br>                [ 15.3, 15.4, 1.00 ],<br>                [ 15.6, 15.7, 1.00 ],<br>                [ 16.0, 16.1, 1.00 ],<br>                [ 16.3, 16.4, 1.00 ],<br>                [ 16.6, 16.7, 1.00 ],<br>                [ 17.0, 17.1, 1.00 ],<br>                [ 17.3, 17.4, 1.00 ],<br>                [ 17.6, 17.7, 1.00 ],<br>                [ 18.0, 18.1, 1.00 ],<br>                [ 18.3, 18.4, 1.00 ],<br>                [ 18.6, 18.7, 1.00 ],<br>                [ 19.0, 19.1, 1.00 ],<br>                [ 19.3, 19.4, 1.00 ],<br>                [ 19.6, 19.7, 1.00 ],<br>                [ 20.0, 20.1, 1.00 ],<br>                [ 20.3, 20.4, 1.00 ],<br>                [ 20.6, 20.7, 1.00 ],<br>                [ 21.0, 21.1, 0.75 ],<br>                [ 21.5, 21.6, 0.75 ],<br>                [ 22.0, 22.1, 0.75 ],<br>                [ 22.5, 22.6, 0.75 ],<br>                [ 23.0, 23.1, 0.50 ],<br>                [ 23.5, 23.6, 0.50 ]<br>            ]<br>        }, {<br>            &quot;name&quot;: &quot;freezer&quot;,<br>            &quot;unitPower&quot;: 400,<br>            &quot;quantity&quot;: 1,<br>            &quot;profile&quot;: [<br>                [  0.0,  0.001, 0.50 ],<br>                [  0.5,  0.501, 0.50 ],<br>                [  1.0,  1.001, 0.50 ],<br>                [  1.5,  1.501, 0.50 ],<br>                [  2.0,  2.001, 0.75 ],<br>                [  2.5,  2.501, 0.75 ],<br>                [  3.0,  3.001, 0.75 ],<br>                [  3.5,  3.501, 0.75 ],<br>                [  4.0,  4.001, 0.75 ],<br>                [  4.5,  4.501, 0.75 ],<br>                [  5.0,  5.001, 0.75 ],<br>                [  5.5,  5.501, 0.75 ],<br>                [  6.0,  6.001, 0.75 ],<br>                [  6.5,  6.501, 0.75 ],<br>                [  7.0,  7.001, 1.00 ],<br>                [  7.5,  7.501, 1.00 ],<br>                [  8.0,  8.001, 1.00 ],<br>                [  8.5,  8.501, 1.00 ],<br>                [  9.0,  9.001, 1.00 ],<br>                [  9.5,  9.501, 1.00 ],<br>                [ 10.0, 10.001, 1.00 ],<br>                [ 10.3, 10.301, 1.00 ],<br>                [ 10.6, 10.601, 1.00 ],<br>                [ 11.0, 11.001, 1.00 ],<br>                [ 11.3, 11.301, 1.00 ],<br>                [ 11.6, 11.601, 1.00 ],<br>                [ 12.0, 12.001, 1.00 ],<br>                [ 12.3, 12.301, 1.00 ],<br>                [ 12.6, 12.601, 1.00 ],<br>                [ 13.0, 13.001, 1.00 ],<br>                [ 13.3, 13.301, 1.00 ],<br>                [ 13.6, 13.601, 1.00 ],<br>                [ 14.0, 14.001, 1.00 ],<br>                [ 14.3, 14.301, 1.00 ],<br>                [ 14.6, 14.601, 1.00 ],<br>                [ 15.0, 15.001, 1.00 ],<br>                [ 15.3, 15.301, 1.00 ],<br>                [ 15.6, 15.601, 1.00 ],<br>                [ 16.0, 16.001, 1.00 ],<br>                [ 16.3, 16.301, 1.00 ],<br>                [ 16.6, 16.601, 1.00 ],<br>                [ 17.0, 17.001, 1.00 ],<br>                [ 17.3, 17.301, 1.00 ],<br>                [ 17.6, 17.601, 1.00 ],<br>                [ 18.0, 18.001, 1.00 ],<br>                [ 18.3, 18.301, 1.00 ],<br>                [ 18.6, 18.601, 1.00 ],<br>                [ 19.0, 19.001, 1.00 ],<br>                [ 19.3, 19.301, 1.00 ],<br>                [ 19.6, 19.601, 1.00 ],<br>                [ 20.0, 20.001, 1.00 ],<br>                [ 20.3, 20.301, 1.00 ],<br>                [ 20.6, 20.601, 1.00 ],<br>                [ 21.0, 21.001, 0.75 ],<br>                [ 21.5, 21.501, 0.75 ],<br>                [ 22.0, 22.001, 0.75 ],<br>                [ 22.5, 22.501, 0.75 ],<br>                [ 23.0, 23.001, 0.50 ],<br>                [ 23.5, 23.501, 0.50 ]<br>            ]<br>        }<br>    ]<br>}</pre><p>The <strong>period</strong> entry specifies the hour the solar system starts, <strong>h0</strong>, and how many days have to be simulated, <strong>days</strong>. The last day will be used to evaluate the solar system. Every day starts at midnight, including the first day.</p><p>The <strong>solarPanels</strong> entry includes the <strong>price</strong> of a unit of watt peak and the <strong>power</strong> of the solar panels. The price has no unit here, but its monetary component should be the same as the price of a unit of battery capacity. These two prices are used for the cost function of the solar production set to be evaluated. The power value is given has a <strong>range</strong> with a <strong>step</strong>, and a unit (here always Wp). So the power of the solar panels will vary from the minimum range value to the maximum range value, with an increment fixed by the step value.</p><p>The <strong>batteries</strong> record includes the <strong>price</strong> of a unit of battery capacity, or ampere-hour. The <strong>voltage</strong> of the set of batteries, with a range, a step and a unit (here always V). As the power of the solar panels, the voltage value can vary. The <strong>capacity</strong> of the set of batteries, with also a range, a step and a unit (here always Ah). This technical caracteristic can also vary in value. Two more extra information are set: the initial capacity of the system before running, <strong>init</strong>, and the maximum discharge value to validate a set of production indicators (solar panel power, battery capacity, battery voltage), <strong>maxDischarge</strong>.</p><p>The daily production generated by the <strong>sun</strong> is the product of an irradiation coefficient (Wh/m²/day), <strong>irradiationCoefficient</strong>, by the profile of the solar irradiation during the day, <strong>profile</strong>. This irradiation coefficient can vary in a range with an incremental step. The profile is a list of intervals, where each interval contains three information: the start hour (included), the end hour (excluded), and a percentage to be applied to the irradiation coefficient to get the value to be taken into account for that interval. As this is a profile, the calculator could adjust these coefficients so that their sum equals 1.</p><p>The <strong>appliances</strong> are grouped in a list of items. Each appliance has a <strong>name</strong>, a power unit, <strong>unitPower</strong>, a quantity, <strong>quantity</strong>, and a consumption <strong>profile</strong>. As before, a profile is a bundle of intervals with a start hour, an end hour, and a percentage to be applied to the total energy consumed, we multiply the power unit value by the quantity of items for the appliance. This percentage must be a real number between 0 and 1.</p><p><strong>{2} The methodology used</strong></p><p>The methodology used may be simple, but it is enough to understand what happens when a load has to be met by solar generation and batteries.</p><p>Knowing the load curve for a user’s consumption, the aim is to size an off-grid installation made up of solar panels, batteries and an inverter. This sizing must enable the electricity consumption requirements to be met, while guaranteeing a maximum daily discharge rate and a low installation cost.</p><p>We’ll consider a day divided into minutes, which gives us 1,440 minutes in a day. At the start of the simulation, we will assume that the battery is charged to ∝ (generally between 0.5 and 0.8), and we will model the system over a period of 3 days to give the system time to reach equilibrium during the 3rd day. It is assumed that the system is installed in the morning and starts up at 10am on the first day.</p><p>Each minute that passes will be counted as a simulation step, so the first elapsed minute will have the index 0 and will also be the first step of the simulation. As we also need to know the index of the minute in a day as a function of the index of the simulation step, we introduce the function f which will give the index of the minute in a day (the first minute has index 0 and the last minute has index 1440–1) as a function of the index of the simulation step.</p><p>It is assumed that the consumption profile of each item of electrical equipment connected to the inverter is known. Each profile is modelled by a vector where the nth dimension corresponds to the energy demand in Wh over the nth simulation step. If A represents all the consumer equipment (excluding the battery), the load curve to be satisfied is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*xRvPYchsnB5YlKwPIqZ-XQ.png" /></figure><p>Hereafter, for ease of reading, all vectors are written in bold. When a vector has an index, we refer to the dimension corresponding to this index.</p><p>Electricity production from solar panels is a function of the surface area of the solar panels (in m2), the power produced by 1 m2 (peak watt unit) when the sun is at its zenith (the sun then produces 1000W), an irradiation coefficient (expressed in kWh / m2 / day), and a sunshine profile (each value being expressed from 0 to 1, the sum of the coefficients being equal to 1). This production is modelled in the form of a vector :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*bxHNo8RWojX5GLpwZ_JmuQ.png" /></figure><p>With:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*ndaP7L23BI8VnyMbVOlwCA.png" /></figure><p>And:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*_xxgynNaSKNYmYWxwvISWg.png" /></figure><p>The energy contained in the battery is expressed as a vector <strong>B</strong>, where the maximum rate of charge and discharge is given by :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*OicYF3RlGUZDaoKpmHkzrQ.png" /></figure><p>Where Bfull is the total energy that can be restored in one hour.</p><p>First, we calculate the difference between solar production and consumption:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*mT-5sx51-aXC8MhsaFw-cw.png" /></figure><p>At each simulation step, there is either a surplus of energy, which is either lost or used to recharge the battery, or a deficit of energy, which must be covered by energy from the battery. The battery charge vector is therefore constructed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*5E9EOy5XwYsmBN_68QUP2w.png" /></figure><p>And the discharge vector:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*RjYB_JIvGuL6aoMXaOJHKg.png" /></figure><p>The energy level in the battery at time n is therefore:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*UEjO2NuMxBmZRn9ft4wDsg.png" /></figure><p>If we exclude the first operations, and if we note n0 the index of the simulation step corresponding to the beginning of the last day of simulation, we will try to minimise the following cost function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*VjWY3D__wMht2rrqgmbbdw.png" /></figure><p>Subject to the following constraints:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*_N58QvG-iARJ28XFKz0L-Q.png" /></figure><p>Where Ppv is the price in euros of a Wpeak (for simplicity, we’ll multiply the surface area in m2 of the solar panels by the peak power of a m2), Pah is the price in euros of an Ah for the battery, and beta is the maximum daily discharge rate of the batteries.</p><p><strong>{3} The python script</strong></p><p>I won’t explain the following script, I’ll leave the pleasure of discovering it to you, the reader (Python knowledge is a prerequisite). This script can be improved, but it does the job.</p><pre>&quot;&quot;&quot;<br>Usage:<br>            python3 calculator.py scenario<br>Arborescence:<br>|   calculator.py<br>|__ input<br>|  |__ scenario.json<br>|__ output<br>|  |__ scenario.xlsx<br>|  |__ scenario_optimum.xlsx<br>&quot;&quot;&quot;<br><br>import json<br>import math<br>import pandas as pd<br>from sys import argv<br><br># lecture des paramètres<br>scenarioName = argv[1]<br><br># chargement des paramètres de la simulation<br>print(&quot;[info] reading parameters&quot;)<br>with open(f&quot;input/{scenarioName}.json&quot;, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:<br>    param = json.load(f)<br><br># on construit un vecteur vide<br>n9 = param[&#39;period&#39;][&#39;days&#39;] * 24 * 60<br>N = [0] * n9<br>n0 = param[&#39;period&#39;][&#39;h0&#39;] * 60<br>n1 = n9 - 24 * 60<br>print(f&quot;[info] {len(N)} steps (or minutes), installation starts at {n0}, last day starts at {n1}&quot;)<br><br># on construit les courbes de charge relatives à la consommation<br>L = {}<br>for a in param[&#39;appliances&#39;]:<br>    if a[&#39;name&#39;] not in L:<br>        L[a[&#39;name&#39;]] = N[:]<br>    tmp = [0] * ( 24 * 60 )<br>    for p in a[&#39;profile&#39;]:<br>        i0 = math.floor(p[0] * 60)<br>        i1 = math.ceil(p[1] * 60)<br>        e = math.ceil(a[&#39;unitPower&#39;] * a[&#39;quantity&#39;] * p[2] / 60.0)<br>        for i in range(i0,i1):<br>            tmp[i] += e<br>    for n in range(n0, n9):<br>        L[a[&#39;name&#39;]][n] += tmp[n % (24 * 60)]<br>items = list(L.keys())<br>print(f&quot;[info] appliances detected: {items}&quot;)<br>L[&#39;total&#39;] = N[:]<br>t = 0.0<br>for item in items:<br>    s = 0.0<br>    for n in range(n0,n9):<br>        L[&#39;total&#39;][n] += L[item][n]<br>        s += L[item][n]<br>    t += s<br>    s /= param[&#39;period&#39;][&#39;days&#39;]<br>    print(f&quot;[info] {s} Wh/day for {item}&quot;)<br>t /= param[&#39;period&#39;][&#39;days&#39;]<br>print(f&quot;[info] {t} Wh/day for all appliances&quot;)<br><br># Profilage journalier de l&#39;ensoleillement.<br>S = [0] * (24 * 60)<br>for p in param[&#39;sun&#39;][&#39;profile&#39;]:<br>    i0 = math.floor(p[0] * 60)<br>    i1 = math.ceil(p[1] * 60)<br>    for i in range(i0, i1):<br>        S[i] = p[2]<br>t = 0.0<br>for v in S:<br>    t += v<br>for i in range(24*60):<br>    S[i] /= t<br>print(&quot;[info] daily sun profile computed&quot;)<br><br># Paramètres relatifs aux simulations.<br>wattPeakMin = param[&quot;solarPanels&quot;][&quot;power&quot;][&quot;range&quot;][0]<br>wattPeakMax = param[&quot;solarPanels&quot;][&quot;power&quot;][&quot;range&quot;][1]<br>wattPeakStep = param[&quot;solarPanels&quot;][&quot;power&quot;][&quot;step&quot;]<br>batteryCapacityMin = param[&quot;batteries&quot;][&quot;capacity&quot;][&quot;range&quot;][0]<br>batteryCapacityMax = param[&quot;batteries&quot;][&quot;capacity&quot;][&quot;range&quot;][1]<br>batteryCapacityStep = param[&quot;batteries&quot;][&quot;capacity&quot;][&quot;step&quot;]<br>batteryVoltageMin = param[&quot;batteries&quot;][&quot;voltage&quot;][&quot;range&quot;][0]<br>batteryVoltageMax = param[&quot;batteries&quot;][&quot;voltage&quot;][&quot;range&quot;][1]<br>batteryVoltageStep = param[&quot;batteries&quot;][&quot;voltage&quot;][&quot;step&quot;]<br>irradiationMin = param[&quot;sun&quot;][&quot;irradiationCoefficient&quot;][&quot;range&quot;][0]<br>irradiationMax = param[&quot;sun&quot;][&quot;irradiationCoefficient&quot;][&quot;range&quot;][1]<br>irradiationStep = param[&quot;sun&quot;][&quot;irradiationCoefficient&quot;][&quot;step&quot;]<br>nSteps = [<br>    math.ceil((wattPeakMax-wattPeakMin+1)/wattPeakStep),<br>    math.ceil((batteryCapacityMax-batteryCapacityMin+1)/batteryCapacityStep),<br>    math.ceil((batteryVoltageMax-batteryVoltageMin+1)/batteryVoltageStep),<br>    math.ceil((irradiationMax-irradiationMin+1)/irradiationStep)<br>]<br>print(f&quot;[info] {nSteps[0]} for Wp, {nSteps[1]} for Ah, {nSteps[2]} for V, {nSteps[3]} for IC, then {nSteps[0]*nSteps[1]*nSteps[2]*nSteps[3]} epochs to do&quot;)                                <br><br># fonction simulant un scénario<br>def simulate(inputs: dict, exportFilename=None):<br>    global n0, n9, N, S, param<br>    # Capacité maximale de la batterie<br>    batteryFull = inputs[&#39;batteryCapacity&#39;] * inputs[&#39;batteryVoltage&#39;]<br>    batteryMaxSpeed = batteryFull / 60.0<br>    # On construit le profil de production.<br>    P = N[:]<br>    solarEnergy = ( inputs[&#39;wattPeak&#39;] / 1000) * inputs[&#39;irradiation&#39;]<br>    for i in range(n0, n9):<br>        P[i] = solarEnergy * S[i % (24*60)]<br>    # On calcule les écarts.<br>    delta = N[:]<br>    for i in range(n0,n9):<br>        delta[i] = P[i] - L[&#39;total&#39;][i]<br>    # On applique une formule de récurrence pour la batterie.<br>    B = N[:]<br>    C = N[:]<br>    D = N[:]<br>    B[n0] = param[&#39;batteries&#39;][&#39;capacity&#39;][&#39;init&#39;] * batteryFull<br>    for n in range(n0+1, n9):<br>        if delta[n] &gt; 0:<br>            C[n] = min([ delta[n], batteryFull - B[n-1], batteryMaxSpeed ])<br>        elif delta[n] &lt; 0:<br>            D[n] = min([ -delta[n], B[n-1], batteryMaxSpeed ])<br>        B[n] = B[n-1] + C[n] - D[n]<br>    # On calcule les indicateurs statistiques.<br>    c = param[&#39;solarPanels&#39;][&#39;price&#39;] * inputs[&#39;wattPeak&#39;] + param[&#39;batteries&#39;][&#39;price&#39;] * inputs[&#39;batteryCapacity&#39;]<br>    d = round(1 - min(B[n1:]) / batteryFull, 4)<br>    res = {<br>        &quot;wattPeakInput&quot;: inputs[&#39;wattPeak&#39;],<br>        &quot;batteryCapacityInput&quot;: inputs[&#39;batteryCapacity&#39;],<br>        &quot;batteryVoltageInput&quot;: inputs[&#39;batteryVoltage&#39;],<br>        &quot;irradiationInput&quot;: inputs[&#39;irradiation&#39;],<br>        &quot;solarEnergy&quot;: int(solarEnergy),<br>        &quot;fullBattery&quot;: int(batteryFull),<br>        &quot;energyProduced&quot;: int(sum(P[n1:])),<br>        &quot;energyConsumed&quot;: int(sum(L[&#39;total&#39;][n1:])),<br>        &quot;energyCharged&quot;: int(sum(C[n1:])),<br>        &quot;energyDischarged&quot;: int(sum(D[n1:])),<br>        &quot;maxDischarge&quot;: d,<br>        &quot;cost&quot;: int(c)<br>    }<br>    # on exporte les données<br>    if exportFilename != None:<br>        lists = {}<br>        lists[&#39;day&#39;] = []<br>        lists[&#39;hour&#39;] = []<br>        lists[&#39;minute&#39;] = []<br>        for n in range(n9):<br>            lists[&#39;day&#39;].append(1+math.floor((n/(24*60))))<br>            lists[&#39;hour&#39;].append(math.floor(n/60) % 24)<br>            lists[&#39;minute&#39;].append(n % 60)<br>        for k in list(L.keys()):<br>            lists[k] = L[k]<br>        lists[&#39;solarProduction&#39;] = P<br>        lists[&#39;delta&#39;] = delta<br>        lists[&#39;energyCharged&#39;] = C<br>        lists[&#39;energyDischarged&#39;] = D<br>        lists[&#39;batteryEnergy&#39;] = B<br>        with pd.ExcelWriter(exportFilename) as writer:<br>            config = {<br>                &quot;input&quot;: [],<br>                &quot;value&quot;: []<br>            }<br>            for k in res:<br>                config[&#39;input&#39;].append(k)<br>                config[&#39;value&#39;].append(res[k])<br>            df = pd.DataFrame(config)<br>            df.to_excel(writer, sheet_name=&quot;inputs&quot;)<br>            df = pd.DataFrame(lists)<br>            df.to_excel(writer, sheet_name=&quot;curves&quot;)<br>    # On retourne le résultat.<br>    return res<br><br># On boucle sur les différentes possibilités.<br>stats = []<br>optimum = {<br>    &#39;index&#39;: None,<br>    &#39;cost&#39;: None<br>}<br>stepIndex = 0<br>for wattPeak in range(wattPeakMin, wattPeakMax+1, wattPeakStep):<br>    for batteryCapacity in range(batteryCapacityMin, batteryCapacityMax+1, batteryCapacityStep):<br>        for batteryVoltage in range(batteryVoltageMin, batteryVoltageMax+1, batteryVoltageStep):<br>            for irradiation in range(irradiationMin, irradiationMax+1, irradiationStep):<br>                res = simulate({<br>                    &quot;wattPeak&quot;: wattPeak,<br>                    &quot;batteryCapacity&quot;: batteryCapacity,<br>                    &quot;batteryVoltage&quot;: batteryVoltage,<br>                    &quot;irradiation&quot;: irradiation,<br>                })<br>                stats.append(res)<br>                # Optimum<br>                if res[&quot;maxDischarge&quot;] &lt;= param[&#39;batteries&#39;][&#39;capacity&#39;][&#39;maxDischarge&#39;]:<br>                    if optimum[&#39;cost&#39;] == None or res[&quot;cost&quot;] &lt; optimum[&#39;cost&#39;]:<br>                        optimum[&#39;index&#39;] = stepIndex<br>                        optimum[&#39;cost&#39;] = res[&quot;cost&quot;]<br>                # display<br>                stepIndex += 1<br>                print(f&quot;[info] step {stepIndex}, max discharge {stats[-1][&#39;maxDischarge&#39;]}\r&quot;, end=&#39;&#39;)<br>print(&#39;&#39;)<br>if optimum[&#39;index&#39;] == None:<br>    print(&quot;[info] no optimum&quot;)<br>else:<br>    print(f&quot;[found] optimum for {stats[optimum[&#39;index&#39;]]}&quot;)<br>    # on rejoue le scénario optimum en exportant l&#39;ensemble des données simulées pour ce scénario<br>    simulate({<br>        &quot;wattPeak&quot;: stats[optimum[&#39;index&#39;]][&#39;wattPeakInput&#39;],<br>        &quot;batteryCapacity&quot;: stats[optimum[&#39;index&#39;]][&#39;batteryCapacityInput&#39;],<br>        &quot;batteryVoltage&quot;: stats[optimum[&#39;index&#39;]][&#39;batteryVoltageInput&#39;],<br>        &quot;irradiation&quot;: stats[optimum[&#39;index&#39;]][&#39;irradiationInput&#39;],<br>    }, exportFilename=f&quot;output/{scenarioName}_optimum.xlsx&quot;)<br><br># On met les résultats dans un fichier Excel.<br>df = pd.json_normalize(stats)<br>df.to_excel(f&quot;output/{scenarioName}.xlsx&quot;)<br>print(&quot;[info] data stored in spreadsheet&quot;)</pre><p><strong>{4} The results</strong></p><p>The results will be split into two files.</p><p>If the scenario name is ‘test’ then the file created is ‘test.xlsx’. This file stores each valid set of assumptions. The columns from B to E are the variable inputs (solar panel power, battery capacity, battery voltage, irradiation coefficient). The columns from F to M are the output values (maximum discharge rate of the battery, cost of the production kit). Each row refers to a specific production set, remembering the range inputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6dPdSMtFNPvJ--MbBKs9A.png" /></figure><p>Example of chart that can be done with such data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzIz9qK1rF1uQq-cz7kEhg.png" /></figure><p>A second file is created, called “test_optimum”, containing the details of the best scenario found. The “inputs” sheet contains the characteristics of the optimum production set and the “curves” sheet contains the different curves on a minute time basis.</p><p>Example of charts that can be produced:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FFr5CLnrCvlKy61BMOUVMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjNljVhxMiAWKbByuX6PAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSFEF58LwL8nHVssSAidcg.png" /></figure><p>This is not the end of the story. There’s still a lot to be improved, but it’s an interesting start to understanding an off-grid solar system with a production module and a consumption module.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=465bb4b497d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Apache Superset on Ubuntu Server with PostgreSQL and Apache Airflow]]></title>
            <link>https://medium.com/@j3amail/install-apache-superset-on-ubuntu-server-with-postgresql-and-apache-airflow-2aa031c94dff?source=rss-e321cd093337------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aa031c94dff</guid>
            <category><![CDATA[apache-superset]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[apache-airflow]]></category>
            <dc:creator><![CDATA[Jean-Michel ARNAUD]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 08:30:23 GMT</pubDate>
            <atom:updated>2024-12-09T15:15:40.832Z</atom:updated>
            <content:encoded><![CDATA[<p>In this story, we will start with a virtual machine on Ubuntu running Apache Airflow and PostgreSQL, and add Apache Superset. In the end, we will have a complete environment for ETL (extract, transform and load data) and BI (data visualisation) tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpQdegw94WFtkW3_VGDGOw.png" /><figcaption>Ubuntu, the operating system, PostgreSQL, the database, Apache Airflow, the extract transform and load tool, Apache Superset, the data visualization tool</figcaption></figure><p>Before starting this story, follow the previous story which describes how to install PostgreSQL and Apache Airflow on an Ubuntu virtual machine:</p><p><a href="https://medium.com/@j3amail/discover-apache-airflow-by-setting-up-a-working-environment-on-ubuntu-with-postgresql-and-ssl-6fbe2e0d5440">Discover Apache Airflow by setting up a working environment on Ubuntu with PostgreSQL and SSL…</a></p><p><strong>{1} Create a specific user for Apache Superset</strong></p><p>Open a shell on your computer and log into the virtual machine :</p><pre>ssh ubuntu@123.123.123.123</pre><p>Create a user for using Apache Superset :</p><pre>sudo adduser superset</pre><p>The current verion of Apache Airflow requires Python 3.9 and the dev module associated, so we need to install them :</p><pre>sudo add-apt-repository ppa:deadsnakes/ppa<br>sudo apt update<br>sudo apt install python3.9<br>sudo apt install python3.9-venv<br>sudo apt install python3.9-dev</pre><p>Install a library required by Superset to communicate with PostgreSQL:</p><pre>sudo apt-get install libpq-dev</pre><p>Connect to PostgreSQL :</p><pre>sudo -u postgres psql</pre><p>And create a user for Apache Superset (here, we grant a readable access to user <em>superset_user</em> to all tables in the schema <em>smart_schema</em> in the database <em>airflow_db</em>):</p><pre>\c airflow_db<br>CREATE USER superset_user WITH PASSWORD &#39;my_db_password&#39;;<br>GRANT CONNECT ON DATABASE airflow_db TO superset_user;<br>GRANT USAGE ON SCHEMA smart_schema TO superset_user;<br>GRANT SELECT ON ALL TABLES IN SCHEMA smart_schema TO superset_user;</pre><p><strong>{2} Create a virtual host</strong></p><p>Add a virtual host as an entry for the front end of Superset, for that, open the file with the current virtual hosts:</p><pre>sudo vi /etc/apache2/sites-enabled/000-default-le-ssl.conf</pre><p>And enter a new virtual host (here, Apache Superset will listen on port 8088) and quit vi editor:</p><pre>&lt;VirtualHost *:443&gt;<br>    ProxyPreserveHost On<br>    ProxyPass &quot;/&quot;  &quot;http://127.0.0.1:8088/&quot;<br>    ProxyPassReverse &quot;/&quot;  &quot;http://127.0.0.1:8088/&quot;<br><br>    ServerName your_sub_domain_url<br><br>    ErrorLog ${APACHE_LOG_DIR}/error.log<br>    CustomLog ${APACHE_LOG_DIR}/access.log combined<br>&lt;/VirtualHost&gt;</pre><p>Add a certificate to your subdomain:</p><pre>sudo certbot -d your_sub_domain_url --expand</pre><p>Close the ssh connection for ubuntu user, and open a new one with the superset user :</p><pre>exit<br>ssh superset@123.123.123.123</pre><p><strong>{3} Install Apache Superset</strong></p><p>Create a virtual environnement in the superset home directory :</p><pre>cd /home/superset/<br>python3.9 -m venv superset-env</pre><p>Activate the virtual environment :</p><pre>source superset-env/bin/activate</pre><p>Install Apache Superset (including the image library Pillow and the driver to connect to PostgreSQL) :</p><pre>pip3.9 install apache-superset<br>pip3.9 install Pillow<br>pip3.9 install psycopg2-binary</pre><p>At the end, be sure to read “Running setup.py install for apache-superset … done” on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgZRjbBonXL6CwH2j6bJIw.png" /><figcaption>screenshot at the end of the installation</figcaption></figure><p>Generate a secret key:</p><pre>openssl rand -base64 42</pre><p>Create a configuration file :</p><pre>cd /home/superset/<br>vi superset_config.py</pre><p>And paste inside the following content with your own random generated secret key:</p><pre># Superset specific config<br>ROW_LIMIT = 5000<br><br># Flask App Builder configuration<br># Your App secret key will be used for securely signing the session cookie<br># and encrypting sensitive information on the database<br># Make sure you are changing this key for your deployment with a strong key.<br># Alternatively you can set it with `SUPERSET_SECRET_KEY` environment variable.<br># You MUST set this for production environments or the server will refuse<br># to start and you will see an error in the logs accordingly.<br>SECRET_KEY = &#39;YOUR_OWN_RANDOM_GENERATED_SECRET_KEY&#39;</pre><p>Make some export:</p><pre>export FLASK_APP=superset<br>export SUPERSET_CONFIG_PATH=/home/superset/superset_config.py </pre><p>Initialise the database for Superset:</p><pre>superset db upgrade</pre><p>Create an admin user:</p><pre>superset fab create-admin</pre><p>Create default role and permissions:</p><pre>superset init</pre><p><strong>{4} Create a service to manage Apache Superset instance</strong></p><p>Exit and log as Ubuntu user:</p><pre>exit<br>ssh ubuntu@123.123.123.123<br>sudo vi /etc/systemd/system/superset-instance.service</pre><p>Paste the following lines:</p><pre>[Unit]<br>Description=Apache Superset instance daemon<br>After=network.target postgresql.service<br>Wants=postgresql.service<br><br>[Service]<br>EnvironmentFile=/etc/environment<br>Environment=&quot;FLASK_APP=superset&quot;<br>Environment=&quot;SUPERSET_CONFIG_PATH=/home/superset/superset_config.py&quot;<br>User=superset<br>Group=superset<br>Type=simple<br>ExecStart=/bin/bash -c &#39;source /home/superset/superset-env/bin/activate; superset run -p 8088 --with-threads --reload&#39;<br>Restart=on-failure<br>RestartSec=5s<br>PrivateTmp=true<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Reload the daemon :</p><pre>sudo systemctl daemon-reload</pre><p>Allow the superset user to run the service without being a sudo user :</p><pre>sudo vi /etc/sudoers.d/superset_service</pre><p>And paste the following lines:</p><pre>Cmnd_Alias SUPERSET_USER_SERVICE = /usr/bin/systemctl start superset-instance, /usr/bin/systemctl stop superset-instance, /usr/bin/systemctl restart superset-instance<br><br>superset ALL=(ALL) PASSWD:SUPERSET_USER_SERVICE</pre><p><strong>{5} Run Apache Superset</strong></p><p>Log in as Superset user:</p><pre>exit<br>ssh superset@123.123.123.123</pre><p>Run Apache Superset:</p><pre>sudo service superset-instance start</pre><p>Open a web browser and go to “your_sub_domain_url” to check that Apache Superset is well running.</p><p><strong>{6} Add a database connection</strong></p><p>After logging into the Superset application, go to the “Settings” menu, select “database connections”, then the “+ DATABASE” button, fill in the required information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aa031c94dff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Discover Apache Airflow by setting up a working environment on Ubuntu with PostgreSQL and SSL…]]></title>
            <link>https://medium.com/@j3amail/discover-apache-airflow-by-setting-up-a-working-environment-on-ubuntu-with-postgresql-and-ssl-6fbe2e0d5440?source=rss-e321cd093337------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fbe2e0d5440</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[airflow-installation]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Jean-Michel ARNAUD]]></dc:creator>
            <pubDate>Tue, 25 Jun 2024 17:11:23 GMT</pubDate>
            <atom:updated>2024-12-09T11:01:10.945Z</atom:updated>
            <content:encoded><![CDATA[<h3>Discover Apache Airflow by setting up a working environment on Ubuntu with PostgreSQL and SSL certificate</h3><p>In this story, we will start with a fresh Ubuntu server and, step by step, get an Apache Airflow instance up and running. Like a recipe for a cake, we will use a series of elementary actions and try to avoid nothing to get a good cake in the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bY-eFHh5ApvDjczGljtZhA.png" /></figure><p><strong>{0} Ingredients</strong></p><p>First, we need a virtual machine. We bought one on OVH cloud with Ubuntu 24.04 on it, after our purchase, we receive an IP (hereafter <em>123.123.123.123</em>), an account (<em>ubuntu</em>), and a password (<em>password</em>).</p><p>Secondly, buy a domain name (same provider for us, OVH). Let’s say : <em>mydomain.com</em></p><p><strong>{1} Prepare the virtual machine to run Apache Airflow</strong></p><p>Open a shell on your computer and log into this fresh virtual machine :</p><pre>ssh ubuntu@123.123.123.123</pre><p>Update and upgrade the operating system of the virtual machine :</p><pre>sudo apt-get update<br>sudo apt-get upgrade<br>sudo apt autoremove</pre><p>If Python 3 was already installed, that was not the case for pip, so we install it :</p><pre>sudo apt install python3-pip</pre><p>Install Apache :</p><pre>sudo apt install apache2</pre><p>Install the virtual environnement for Python :</p><pre>sudo apt install python3-venv</pre><p>Install PostgreSQL for the database :</p><pre>sudo apt install postgresql</pre><p>Connect to PostgreSQL :</p><pre>sudo -u postgres psql template1</pre><p>Inside PostgreSQL, create a database, create a user, grant privileges, grant again priviliges on the public schema, connect to this newly database, check the encoding (we should have UTF8), change the owner of this database, add a schema for saving data, then exit :</p><pre>CREATE DATABASE airflow_db;<br>CREATE USER airflow_user WITH PASSWORD &#39;my_db_password&#39;;<br>GRANT ALL PRIVILEGES ON DATABASE airflow_db TO airflow_user;<br>GRANT ALL ON SCHEMA public TO airflow_user;<br>\c airflow_db<br>SHOW SERVER_ENCODING;<br>ALTER DATABASE airflow_db OWNER TO airflow_user;<br>CREATE SCHEMA airflow_schema;<br>exit</pre><p>Open the postgresql configuration file :</p><pre>sudo vi /etc/postgresql/16/main/pg_hba.conf</pre><p>And change “peer” to “md5”, save and quit :</p><pre># &quot;local&quot; is for Unix domain socket connections only<br>local   all             all                                     md5</pre><p>Create a user for using Apache Airflow :</p><pre>sudo adduser airflow</pre><p>Close the ssh connection for ubuntu user, and open a new one with the airflow user :</p><pre>exit<br>ssh airflow@123.123.123.123</pre><p>Create a virtual environnement in the airflow home directory :</p><pre>cd /home/airflow/<br>python3 -m venv airflow-env</pre><p>Activate the virtual environment :</p><pre>source airflow-env/bin/activate</pre><p>Install Apache Airflow :</p><pre>pip3 install &quot;apache-airflow[celery]==2.9.2&quot; --constraint &quot;https://raw.githubusercontent.com/apache/airflow/constraints-2.9.2/constraints-3.8.txt&quot;</pre><p>Install the code editor plugin (useful to code directly inside the browser) :</p><pre>pip3 install airflow-code-editor</pre><p>Install the python library to connect to the database :</p><pre>pip3 install psycopg2-binary</pre><p>Install the package allowing Airflow to access PostgreSQL :</p><pre>pip3 install apache-airflow-providers-postgres</pre><p>Init Airflow :</p><pre>airflow db init</pre><p>Update the configuration of Apache Airflow :</p><pre>cd airflow<br>cp airflow.cfg airflow.cfg.genuine<br>vi airflow.cfg</pre><p>Then, inside the file, append these changes, and quit the text editor :</p><pre>#...<br>executor = LocalExecutor<br>#...<br>warn_deployment_exposure = False<br>#...<br>sql_alchemy_conn = postgresql+psycopg2://airflow_user:my_db_password@localhost/airflow_db<br>#...</pre><p>Moreover, you can optionnally apply the following changes :</p><pre># ...<br>load_examples = False<br># ...<br>load_default_connections = False<br># ...<br>from_email = noreply@mydomain.com<br>#...<br>smtp_host = ssl0.ovh.net<br>smtp_user = noreply@mydomain.com<br>smtp_password = noreply_password<br>smtp_port = 587<br>smtp_email_from = noreply@jimbot.eu</pre><p>Migrate the database :</p><pre>airflow db migrate</pre><p>Create an admin account for Apache Airflow :</p><pre>airflow users create --role Admin --username your_nickname --email your@email.com --firstname Your_Firstname --lastname Your_Lastname --password Your_Password</pre><p>Create two directories for the future DAGs and data :</p><pre>cd /home/airflow/airflow<br>mkdir data<br>mkdir dags</pre><p>Close the ssh connection for airflow user, and open a new one with the ubuntu user :</p><pre>exit<br>ssh ubuntu@123.123.123.123</pre><p><strong>{2} Run Apache Airflow</strong></p><p>Create a service to manage Apache Airflow webserver instance :</p><pre>sudo vi /etc/systemd/system/airflow-webserver.service</pre><p>Paste the following code inside this file, save, and quit :</p><pre>[Unit]<br>Description=Airflow webserver daemon<br>After=network.target postgresql.service<br>Wants=postgresql.service<br><br>[Service]<br>EnvironmentFile=/etc/environment<br>User=airflow<br>Group=airflow<br>Type=simple<br>ExecStart=/bin/bash -c &#39;source /home/airflow/airflow-env/bin/activate; airflow webserver&#39;<br>Restart=on-failure<br>RestartSec=5s<br>PrivateTmp=true<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Create a service to manage Apache Airflow scheduler instance :</p><pre>sudo vi /etc/systemd/system/airflow-scheduler.service</pre><p>Paste the following code inside this file, save, and quit :</p><pre>[Unit]<br>Description=Airflow scheduler daemon<br>After=network.target postgresql.service<br>Wants=postgresql.service<br><br>[Service]<br>EnvironmentFile=/etc/environment<br>User=airflow<br>Group=airflow<br>Type=simple<br>ExecStart=/bin/bash -c &#39;source /home/airflow/airflow-env/bin/activate; airflow scheduler&#39;<br>Restart=on-failure<br>RestartSec=5s<br>PrivateTmp=true<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Reload the daemon :</p><pre>sudo systemctl daemon-reload</pre><p>Run these two services :</p><pre>sudo service airflow-webserver start<br>sudo service airflow-scheduler start</pre><p>Allow the airflow user to run the services without being a sudo user :</p><pre>sudo vi /etc/sudoers.d/airflow_services</pre><p>And add these lines inside the file, and quit :</p><pre>Cmnd_Alias USER_SERVICES = /usr/bin/systemctl start airflow-webserver, /usr/bin/systemctl stop airflow-webserver, /usr/bin/systemctl restart airflow-webserver, /usr/bin/systemctl start airflow-scheduler, /usr/bin/systemctl stop airflow-scheduler, /usr/bin/systemctl restart airflow-scheduler<br><br>airflow ALL=(ALL) PASSWD:USER_SERVICES</pre><p>Install a SSL certificate (provide the domain name bought previously) :</p><pre>sudo snap install --classic certbot<br>sudo ln -s /snap/bin/certbot /usr/bin/certbot<br>sudo certbot --apache</pre><p>Edit the file :</p><pre>sudo vi /etc/apache2/sites-enabled/000-default-le-ssl.conf</pre><p>Add the following lines before &lt;/VirtualHost&gt; :</p><pre>ProxyPreserveHost On<br>ProxyPass &quot;/&quot;  &quot;http://127.0.0.1:8080/&quot;<br>ProxyPassReverse &quot;/&quot;  &quot;http://127.0.0.1:8080/&quot;</pre><p>Install the modules for redirection :</p><pre>sudo a2enmod proxy<br>sudo a2enmod proxy_http<br>sudo a2enmod rewrite<br>sudo systemctl restart apache2</pre><p>Quit the virtual machine :</p><pre>exit</pre><p><strong>{3} Update DNS</strong></p><p>In the DNS zone of mydomain.com (from the web interface of your domain provider), add the following entries :</p><pre>| Domain           | Type | TTL | Target          |<br>|------------------|------|-----|-----------------|<br>| mydomain.com     | 0    | A   | 123.123.123.123 |<br>| www.mydomain.com | 0    | A   | 123.123.123.123 |</pre><p><strong>{4} Log into Apache Airflow</strong></p><p>Enter the following adress inside your web browser :</p><pre>https://mydomain.com</pre><p><strong>{5} Miscellaneous</strong></p><p>A useful command if a problem with Airflow :</p><pre>journalctl -u airflow-webserver.service</pre><p>The adventure continue on:</p><p><a href="https://medium.com/@j3amail/install-apache-superset-on-ubuntu-server-with-postgresql-and-apache-airflow-2aa031c94dff">Install Apache Superset on Ubuntu Server with PostgreSQL and Apache Airflow</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fbe2e0d5440" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>