Skip to content

Oracle Linux 8.5 Install with Cloudflare Tunneling

Reza Fouladian edited this page Dec 18, 2021 · 5 revisions

The first part of this install assumes you are running as root on a fresh install of Oracle Linux Server 8.5. To switch to the root user, type sudo -i.

If you haven't already, create a Cloudflare account and add a domain to it. In these instructions, that domain will be referred to as example.com. I also recommend enabling "Always Use HTTPS" for that domain in the Cloudflare dashboard.

Install Packages

Install required packages and enable the MySQL server:

dnf install -y git openssl-devel gcc-c++ make mysql-server mysql mysql-devel mysql-libs python3
systemctl enable --now mysqld
dnf module install -y nodejs:16

Database Setup

Run MySQL installation. You can answer "yes" (Y) to most questions here.

mysql_secure_installation

Login to MySQL using the root password you just set.

mysql -u root -p

Create the database and user. Make sure to replace "super_secure_password".

CREATE DATABASE cytube3;
CREATE USER cytube3@localhost IDENTIFIED BY 'super_secure_password';
GRANT ALL PRIVILEGES ON cytube3.* TO cytube3@localhost;
SET GLOBAL sql_mode = replace(@@global.sql_mode, 'NO_ZERO_DATE,', '');
FLUSH PRIVILEGES;
QUIT;

Setup Cloudflare Tunneling

Install the latest cloudflared binary

rpm -ivh https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-x86_64.rpm

Login to Cloudflare. This will give a URL to open in your web browser and sign in.

cloudflared tunnel login

Create the tunnel and add DNS records in Cloudflare.

cloudflared tunnel create cytube
cloudflared tunnel route dns cytube cytube.example.com
cloudflared tunnel route dns cytube cytube-io.example.com

Create the config file (vi /root/.cloudflared/config.yml) and configure appropriately using the GUID you got when you created the tunnel.

tunnel: <TUNNEL GUID>
credentials-file: /root/.cloudflared/<TUNNEL GUID>.json

ingress:
  - hostname: cytube.example.com
    service: http://localhost:8080
  - hostname: cytube-io.example.com
    service: http://localhost:1337
  - service: http_status:404

Install cloudflared as a service and start it.

cloudflared service install
systemctl enable --now cloudflared

Setup Cytube

Create the CyTube user.

useradd cytube
su cytube

Change to the user's home directory, clone CyTube and change to the sync directory.

cd ~
git clone -b 3.0 https://github.com/calzoneman/sync
cd sync
npm install
cp config.template.yaml config.yaml
vi config.yaml

In the config do the following

  • Under mysql, set password to the one you setup earlier for the cytube3 user.
  • Configure Socket.IO to connect with the correct port, and enable https to prevent any issues
# Default Socket.IO server - default interface, port 1337
  - ip: ''
    https: true
    port: 1337
    io: true
    url: https://cytube-io.example.com:443
  • Under http, change the root-domain, if you're using cytube.example.com then use example.com for the root domain.
  • Under http, change the cookie-secret.
  • Under io, change the domain to your IO domain, in this example it is cytube-io.example.com.
  • Under io, change the default-port to 443.
  • Under io, set the CORS origin for the non-IO domain, for example:
cors:
    # Additional origins to allow socket connections from (io.domain and
    # https.domain are included implicitly).
    allowed-origins: ["https://cytube.example.com"]
  • Set the YouTube API Key

Save the file and exit the editor.

Start the server.

node index.js

Browse to https://cytube.example.com (your domain) to test the server.

Once you've finished testing, press CTRL+C to stop the server.

Creating a service

Type exit to get back to root.

Create a service with vi /etc/systemd/system/cytube.service and enter the following:

[Unit]
Description=Cytube
After=cloudflared.service

[Service]
ExecStart=/usr/bin/node /home/cytube/sync/index.js
Restart=always
User=cytube
Group=cytube
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/cytube/sync

[Install]
WantedBy=multi-user.target

Enable and start the service.

systemctl enable --now cytube.service