diff --git a/Set-up-centos.Rmd b/Set-up-centos.Rmd index bb2035a..cf69414 100644 --- a/Set-up-centos.Rmd +++ b/Set-up-centos.Rmd @@ -318,13 +318,6 @@ Then we need to start docker sudo systemctl start docker ``` -Not sure this is needed. -```{bash eval=FALSE} -sudo firewall-cmd --zone=docker --add-port=8081/tcp -sudo firewall-cmd --reload -sudo systemctl restart docker -``` - ### Install dockerspawner I am going to be creating the user environment from a docker image, so I also want dockerspawner. Note dockerspawner installed docker-py but it was really old and threw errors so I installed separately to get the latest version. Note make sure you are in the jupyterhub conda env. You can run `conda env list` and use `conda activate jupyterhub` if you are not in it. @@ -482,13 +475,12 @@ Create user useradd jhub ``` -Open the 8000 (for jupyterhub) and 8787 (for RStudio) port +Open the 8000 port for access to the application. ```{bash eval=FALSE} #sudo systemctl enable firewalld #sudo systemctl start firewalld sudo firewall-cmd --permanent --add-port 8000/tcp -sudo firewall-cmd --permanent --add-port 8787/tcp sudo firewall-cmd --reload sudo firewall-cmd --list-ports ``` diff --git a/docs/Set-up-centos.html b/docs/Set-up-centos.html index f5624be..0d2301a 100644 --- a/docs/Set-up-centos.html +++ b/docs/Set-up-centos.html @@ -497,19 +497,13 @@

Install docker

sudo systemctl start docker
-

Not sure this is needed.

-
-
sudo firewall-cmd --zone=docker --add-port=8081/tcp
-sudo firewall-cmd --reload
-sudo systemctl restart docker
-

Install dockerspawner

I am going to be creating the user environment from a docker image, so I also want dockerspawner. Note dockerspawner installed docker-py but it was really old and threw errors so I installed separately to get the latest version. Note make sure you are in the jupyterhub conda env. You can run conda env list and use conda activate jupyterhub if you are not in it.

-
conda install -c conda-forge dockerspawner
-conda install -c conda-forge docker-py
+
conda install -c conda-forge dockerspawner
+conda install -c conda-forge docker-py
@@ -517,7 +511,7 @@

Jupyter images

The image that we use must have the jupyterhub and notebook module installed. The jupyterhub version needs to also match what you have on your hub.

Check the version on your server:

-
$JHUBENV/bin/jupyterhub -V
+
$JHUBENV/bin/jupyterhub -V

For demo purposes, we will use the jupyter images on DockerHub. We want to find an image with the same version of jupyterhub as we have on our server.

@@ -528,21 +522,21 @@

Edit the config file<
  • https://discourse.jupyter.org/t/whats-the-main-difference-between-hub-connect-url-vs-hub-bind-url/3596/2
  • -
    c = get_config()  #noqa
    -c.JupyterHub.port = 8000
    -c.JupyterHub.hub_bind_url = "http://0.0.0.0:8081"
    -c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
    -c.DockerSpawner.remove = True
    -c.Spawner.http_timeout = 3600
    -c.DockerSpawner.image_whitelist = {
    -    'datascience-r': 'jupyter/datascience-notebook:r-4.3.1',
    -    'scipy-notebook': 'jupyter/scipy-notebook:7e1a19a8427f',
    -}
    +
    c = get_config()  #noqa
    +c.JupyterHub.port = 8000
    +c.JupyterHub.hub_bind_url = "http://0.0.0.0:8081"
    +c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
    +c.DockerSpawner.remove = True
    +c.Spawner.http_timeout = 3600
    +c.DockerSpawner.image_whitelist = {
    +    'datascience-r': 'jupyter/datascience-notebook:r-4.3.1',
    +    'scipy-notebook': 'jupyter/scipy-notebook:7e1a19a8427f',
    +}

    Do a docker pull of the images so that they don’t have to be pulled the first time that a user chooses that image.

    -
    docker pull jupyter/datascience-notebook:r-4.3.1
    -docker pull jupyter/scipy-notebook:7e1a19a8427f
    +
    docker pull jupyter/datascience-notebook:r-4.3.1
    +docker pull jupyter/scipy-notebook:7e1a19a8427f

    Now you can restart the service and the user can start a notebook with the specified images.

    @@ -551,50 +545,50 @@

    Create your

    Docker images that work with JupyterHub with Kubernetes will work with this set-up with the addition of jupyterhub and notebook.

    Add the following to your Docker image

    -
    RUN pip3 install \
    -    'jupyter-rsession-proxy' \
    -    'jupyterhub==3.1.*' \
    -    'notebook==6.*' \
    -    'jupyterlab'
    -
    -CMD ["jupyterhub-singleuser"]
    +
    RUN pip3 install \
    +    'jupyter-rsession-proxy' \
    +    'jupyterhub==3.1.*' \
    +    'notebook==6.*' \
    +    'jupyterlab'
    +
    +CMD ["jupyterhub-singleuser"]

    Example using rocker image. Code added to make the home directory home/jovyan.

    -
    FROM rocker/binder:4.3
    -
    -USER root
    -RUN usermod -d /home/jovyan rstudio
    -RUN mkdir /home/jovyan
    -RUN chown rstudio:rstudio /home/jovyan
    -USER rstudio
    -
    -RUN pip3 install \
    -    'jupyter-rsession-proxy' \
    -    'jupyterhub==3.1.*' \
    -    'notebook==6.*' \
    -    'jupyterlab'
    -
    -WORKDIR /home/jovyan
    -
    -CMD ["jupyterhub-singleuser"]
    +
    FROM rocker/binder:4.3
    +
    +USER root
    +RUN usermod -d /home/jovyan rstudio
    +RUN mkdir /home/jovyan
    +RUN chown rstudio:rstudio /home/jovyan
    +USER rstudio
    +
    +RUN pip3 install \
    +    'jupyter-rsession-proxy' \
    +    'jupyterhub==3.1.*' \
    +    'notebook==6.*' \
    +    'jupyterlab'
    +
    +WORKDIR /home/jovyan
    +
    +CMD ["jupyterhub-singleuser"]

    Example using openscapes/rocker

    -
    FROM openscapes/rocker:a7596b5
    -
    -RUN pip3 install \
    -    'jupyter-rsession-proxy' \
    -    'jupyterhub==3.1.*' \
    -    'notebook==6.*' \
    -    'jupyterlab'
    -
    -USER root
    -RUN mkdir /home/jovyan
    -RUN chown rstudio:rstudio /home/jovyan
    -USER rstudio
    -
    -CMD ["jupyterhub-singleuser"]
    +
    FROM openscapes/rocker:a7596b5
    +
    +RUN pip3 install \
    +    'jupyter-rsession-proxy' \
    +    'jupyterhub==3.1.*' \
    +    'notebook==6.*' \
    +    'jupyterlab'
    +
    +USER root
    +RUN mkdir /home/jovyan
    +RUN chown rstudio:rstudio /home/jovyan
    +USER rstudio
    +
    +CMD ["jupyterhub-singleuser"]
    @@ -602,12 +596,12 @@

    Create your

    Persistent volume

    Add the following to the config file to create a persistent volume.

    -
    notebook_dir = '/home/jovyan'
    -c.DockerSpawner.notebook_dir = notebook_dir
    -
    -# Mount the real user's Docker volume on the host to the notebook user's
    -# notebook directory in the container
    -c.DockerSpawner.volumes = { 'jupyter-{username}': notebook_dir }
    +
    notebook_dir = '/home/jovyan'
    +c.DockerSpawner.notebook_dir = notebook_dir
    +
    +# Mount the real user's Docker volume on the host to the notebook user's
    +# notebook directory in the container
    +c.DockerSpawner.volumes = { 'jupyter-{username}': notebook_dir }

    Special note regarding rocker images

    @@ -636,121 +630,120 @@

    Summary

    Only the instructions. Make sure you are installing as the root user. I assume you have Python and conda installed.

    Create the conda environment

    -
    sudo -i
    -
    -conda create -n jupyterhub python --yes
    -conda activate jupyterhub
    -conda install -c conda-forge jupyterhub --yes
    -conda install -c conda-forge jupyterlab notebook --yes
    -
    -JHUBENV=/opt/miniconda3/envs/jupyterhub
    -chmod 755 $JHUBENV
    +
    sudo -i
    +
    +conda create -n jupyterhub python --yes
    +conda activate jupyterhub
    +conda install -c conda-forge jupyterhub --yes
    +conda install -c conda-forge jupyterlab notebook --yes
    +
    +JHUBENV=/opt/miniconda3/envs/jupyterhub
    +chmod 755 $JHUBENV

    Create user

    -
    useradd jhub
    +
    useradd jhub
    -

    Open the 8000 (for jupyterhub) and 8787 (for RStudio) port

    +

    Open the 8000 port for access to the application.

    -
    #sudo systemctl enable firewalld
    -#sudo systemctl start firewalld
    -
    -sudo firewall-cmd  --permanent --add-port 8000/tcp
    -sudo firewall-cmd  --permanent --add-port 8787/tcp
    -sudo firewall-cmd --reload
    -sudo firewall-cmd --list-ports
    +
    #sudo systemctl enable firewalld
    +#sudo systemctl start firewalld
    +
    +sudo firewall-cmd  --permanent --add-port 8000/tcp
    +sudo firewall-cmd --reload
    +sudo firewall-cmd --list-ports

    Create the configuration file. Will be editted at end.

    -
    sudo mkdir -p $JHUBENV/etc/jupyterhub/
    -cd $JHUBENV/etc/jupyterhub/
    -sudo $JHUBENV/bin/jupyterhub --generate-config
    +
    sudo mkdir -p $JHUBENV/etc/jupyterhub/
    +cd $JHUBENV/etc/jupyterhub/
    +sudo $JHUBENV/bin/jupyterhub --generate-config

    Install docker if needed

    -
    sudo yum install -y yum-utils
    -sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    -
    -sudo systemctl start docker
    +
    sudo yum install -y yum-utils
    +sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    +
    +sudo systemctl start docker

    Not sure this is needed.

    -
    sudo firewall-cmd --zone=docker --add-port=8081/tcp
    -sudo firewall-cmd --reload
    -sudo systemctl restart docker
    +
    sudo firewall-cmd --zone=docker --add-port=8081/tcp
    +sudo firewall-cmd --reload
    +sudo systemctl restart docker

    Install dockerspawner

    -
    conda install -c conda-forge dockerspawner --yes
    -conda install -c conda-forge docker-py --yes
    +
    conda install -c conda-forge dockerspawner --yes
    +conda install -c conda-forge docker-py --yes

    Edit the configuration file.

    -
    cd $JHUBENV/etc/jupyterhub/
    -nano jupyterhub_config.py
    +
    cd $JHUBENV/etc/jupyterhub/
    +nano jupyterhub_config.py

    Paste this in

    -
    # Configuration file for jupyterhub.
    -
    -c = get_config()  #noqa
    -c.JupyterHub.port = 8000
    -c.JupyterHub.hub_bind_url = "http://0.0.0.0:8081"
    -c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
    -c.DockerSpawner.remove = True
    -c.Spawner.http_timeout = 3600
    -c.DockerSpawner.image_whitelist = {
    -    'iorocker': 'eeholmes/iorocker-standalone:20231003',
    -    'rocker-binder': 'eeholmes/rocker-binder:20231003',
    -    'openscapes-rocker': 'eeholmes/minimal-jhub:20231004',
    -    'datascience-r': 'jupyter/datascience-notebook:r-4.3.1',
    -    'scipy-notebook': 'jupyter/scipy-notebook:7e1a19a8427f',
    -}
    -
    -notebook_dir = '/home/jovyan'
    -c.DockerSpawner.notebook_dir = notebook_dir
    -
    -# Mount the real user's Docker volume on the host to the notebook user's
    -# notebook directory in the container
    -c.DockerSpawner.volumes = { 'jupyter-{username}': notebook_dir }
    +
    # Configuration file for jupyterhub.
    +
    +c = get_config()  #noqa
    +c.JupyterHub.port = 8000
    +c.JupyterHub.hub_bind_url = "http://0.0.0.0:8081"
    +c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
    +c.DockerSpawner.remove = True
    +c.Spawner.http_timeout = 3600
    +c.DockerSpawner.image_whitelist = {
    +    'iorocker': 'eeholmes/iorocker-standalone:20231003',
    +    'rocker-binder': 'eeholmes/rocker-binder:20231003',
    +    'openscapes-rocker': 'eeholmes/minimal-jhub:20231004',
    +    'datascience-r': 'jupyter/datascience-notebook:r-4.3.1',
    +    'scipy-notebook': 'jupyter/scipy-notebook:7e1a19a8427f',
    +}
    +
    +notebook_dir = '/home/jovyan'
    +c.DockerSpawner.notebook_dir = notebook_dir
    +
    +# Mount the real user's Docker volume on the host to the notebook user's
    +# notebook directory in the container
    +c.DockerSpawner.volumes = { 'jupyter-{username}': notebook_dir }

    Docker pull of the images. Do all.

    -
    docker pull jupyter/datascience-notebook:r-4.3.1
    -docker pull jupyter/scipy-notebook:7e1a19a8427f
    +
    docker pull jupyter/datascience-notebook:r-4.3.1
    +docker pull jupyter/scipy-notebook:7e1a19a8427f

    Make a new server service

    -
    sudo mkdir -p $JHUBENV/etc/systemd
    -cd $JHUBENV/etc/systemd
    -nano jupyterhub.service
    +
    sudo mkdir -p $JHUBENV/etc/systemd
    +cd $JHUBENV/etc/systemd
    +nano jupyterhub.service

    Paste this in

    -
    [Unit]
    -Description=JupyterHub
    -After=syslog.target network.target
    -
    -[Service]
    -User=root
    -Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/miniconda3/envs/jupyterhub/bin"
    -ExecStart=/opt/miniconda3/envs/jupyterhub/bin/jupyterhub -f /opt/miniconda3/envs/jupyterhub/etc/jupyterhub/jupyterhub_config.py
    -
    -[Install]
    -WantedBy=multi-user.target
    +
    [Unit]
    +Description=JupyterHub
    +After=syslog.target network.target
    +
    +[Service]
    +User=root
    +Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/miniconda3/envs/jupyterhub/bin"
    +ExecStart=/opt/miniconda3/envs/jupyterhub/bin/jupyterhub -f /opt/miniconda3/envs/jupyterhub/etc/jupyterhub/jupyterhub_config.py
    +
    +[Install]
    +WantedBy=multi-user.target

    Make sure SELinux doesn’t block our service

    -
    ls -Z $JHUBENV/etc/systemd/
    -sudo chcon system_u:object_r:systemd_unit_file_t:s0 $JHUBENV/etc/systemd/jupyterhub.service
    -sudo find $JHUBENV/bin -type f -exec chcon system_u:object_r:bin_t:s0 {} \;
    +
    ls -Z $JHUBENV/etc/systemd/
    +sudo chcon system_u:object_r:systemd_unit_file_t:s0 $JHUBENV/etc/systemd/jupyterhub.service
    +sudo find $JHUBENV/bin -type f -exec chcon system_u:object_r:bin_t:s0 {} \;

    Enable our new service

    -
    sudo ln -s $JHUBENV/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
    -sudo systemctl daemon-reload
    -sudo systemctl enable jupyterhub.service
    -sudo systemctl start jupyterhub.service
    +
    sudo ln -s $JHUBENV/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
    +sudo systemctl daemon-reload
    +sudo systemctl enable jupyterhub.service
    +sudo systemctl start jupyterhub.service

    Done! See the long instructions if anything is not working.