You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Getting started with HPC Setup. Part 2: Configure conda enviornment, setup R and python, configure Jupyter kernels and start Jupyter Lab."
Following up from [Part 1: Initial HPC setup](../sumner_1/), we now start installing essential softwares or (in conda dictionary) packages, e.g., R, Jupyter, etc.
@@ -476,9 +483,20 @@ q(save = "no")
476
483
477
484
### bash kernel
478
485
479
-
Stay in _yoda_ env.
486
+
We will now install [bash kernel](https://github.com/takluyver/bash_kernel) in _yoda_ env. Unlike other (R and python) kernels, bash kernel do not need to be installed in all of conda env because we can always switch between conda env specific bash env using `mamba activate anakin` or `mamba activate rey`, etc.
487
+
488
+
Here, I will install bash kernel in _yoda_ and not _base_ env as I intend to use _yoda_ as my primary go-to env when I login to HPC.
489
+
490
+
491
+
!!! tip "Keep use of _base_ env to bare minimum"
492
+
Please remember that we keep use of _base_ to bare minimum for maintaining core of codna packages, and should avoid installing (and populating dependencies) packages in _base_ env. You can always delete secondary conda env and restart but you cannot do so with _base_ env!
480
493
481
494
```sh
495
+
## in yoda env
496
+
mamba list | grep -E "bash_kernel"
497
+
## if this does not show bash_kernel installed, redo install
@@ -662,7 +680,7 @@ Once we have installed env specific kernels as in _yoda_ (and other envs, if a n
662
680
conda deactivate
663
681
```
664
682
665
-
!!! warning "You should be in conda _base_ env"
683
+
!!! warning "You should now be in conda _base_ env"
666
684
If you were jumping across more than one conda envs, then each instance of `conda deactivate` command will bring you back to previously active env. So, make sure to return to _base_ env which you can confirm using `echo $CONDA_PREFIX` output. That should point to base path of conda (mambaforge in my case) installation: _/projects/verhaak-lab/amins/hpcenv/mambaforge/_. Also, notice change in bash prompt to `(base) userid@sumner50`.
667
685
668
686
* Once in the _base_ env, generate skeleton for default jupyter configuration.
@@ -678,8 +696,61 @@ jupyter server --generate-config
678
696
!!! danger "Secure Jupyter Server"
679
697
It is critical that you harden security of jupyterlab server. Default configuration is not good enough (in my view) for launching notebook server over HPC, especially without SSL (or _https_) support. Setting up individual security steps is beyond scope of this documentation. However, I strongly recommend reading official documentation on [running a public Jupyter Server](https://jupyter-server.readthedocs.io/en/latest/operators/public-server.html) and [security in the jupyter server](https://jupyter-server.readthedocs.io/en/latest/operators/security.html).
680
698
699
+
Checkout [this example guide](https://medium.com/@nyghtowl/setup-jupyter-notebook-access-on-google-compute-engine-with-https-ad69297f438b) on creating self-signed SSL certificates in case you do not have SSL certificates from Research IT department.
700
+
701
+
#### self-signed SSL certificates
702
+
703
+
Ideally you should have SSL certificates signed by a verified certificate authority (CA) else most of modern web browsers will issue a warning or an error regarding SSL secutity. CA-signed SSLs are typically paid unless issued via [let's encrypt](https://letsencrypt.org/) or your DNS providers.
704
+
705
+
Securing a website (Jupyter Env in our case) is beyond scope of this guide but I will suggest to inquire to your research IT department to see if they can help secure your Jupyter env. It's better to have CA-signed SSL over self-signed SSL, and always better to have SSL (https) over insecure (http) connection to your Jupyter env. This is true even when you are working within a secure firewall of your work network.
706
+
707
+
Here, I am creating a self-signed SSL which most of you can generate and at least have self-signed SSL. [See this post for details](https://medium.com/@nyghtowl/setup-jupyter-notebook-access-on-google-compute-engine-with-https-ad69297f438b).
708
+
709
+
```sh
710
+
## switch to base conda env
711
+
mamba activate base
712
+
713
+
## create dir to save SSL certificates
714
+
mkdir ~/ssl_cert && \
715
+
chmod 700 ~/ssl_cert && \
716
+
cd~/ssl_cert
717
+
718
+
## generate a private key
719
+
openssl genrsa -out hpc_cert.key 2048
720
+
721
+
## secure your private key
722
+
chmod 600 hpc_cert.key
723
+
724
+
## create a signed certificate using a key we generated above
>While creating a signed certificate, *hpc_cert.csr*, you will be prompted to enter issuer's country, city, etc., including Common Name (CN). You should put some info related to use of this certificate into respective fields, e.g., Common Name can be `hpcjupyter`.
732
+
733
+
!!! warning "SSL certificate - unable to verify SSL connection"
734
+
Regardless of what you put in CN, say `hpcjupyter.mywebsite.com`, most of modern web browsers so either SSL warning or error of not verifying your self-signed SSL. This is because you have self-signed this SSL and not using an approved certificate authority (CA) provider for signing your SSL. [Read this post for details](https://support.dnsimple.com/articles/what-is-common-name/). In essense, your self-signed SSL is acting as it is an authentic SSL for a CN you provided above, `hpcjupyter.mywebsite.com`. Since that's a clearly a security risk, most modern browsers will throw a warning before you are allowed to visit a site (Jupyter server in this case) or even may not allow at all to load that website! Hence, prefer asking your Research IT to make a signed SSL available for a specific intranet subdomain, e.g., `jupyter.company.com` for users to use.
735
+
736
+
#### cookie file
737
+
738
+
* After creating SSL certificates, also create a cookie file for jupyter server.
* Example config for _/home/userid/.jupyter/jupyter_server_config.py_. **Please do not copy and paste these options** without knowing [underlying details](https://jupyter-notebook.readthedocs.io/en/stable/config.html).
682
748
749
+
!!! warning "Jupyter token - provide a strong token string"
750
+
While editing jupyter config file below, please read inline comments carefully, especially for `c.ServerApp.token`. **Do not use the default token as that token is used for login to your running jupyter server**. Provide a secure (a longer string, 32 characters or more) string generated using `uuidgen` and after removing dashes.
751
+
752
+
Do not worry of remembering this token. Jupyter does allow you to have an alternate way of login using a custom, user-generated password (see further below).
753
+
683
754
```py
684
755
## leave commented out portion of default config as it is.
685
756
## then you can add your custom config
@@ -688,17 +759,18 @@ jupyter server --generate-config
* Once you customize _/home/userid/.jupyter/jupyter_notebook_config.py_ file, **make sure to generate a secret and strong password using**`jupyter server password` command. Your password then will be written in encrypted format in _/home/userid/.jupyter/jupyter_server_config.json_ file.
788
+
#### jupyter password
789
+
790
+
* Once you customize config file above, **make sure to generate a secret and strong password using**`jupyter server password` command. Your password then will be written in an encrypted format in _/home/userid/.jupyter/jupyter_server_config.json_ file.
791
+
717
792
* Make both files read/write-only by you.
718
793
719
794
```sh
720
795
## for directory, we use permission 700
721
796
chmod 700 ~/.jupyter
722
-
## location where cookie secret is stored
723
-
## prefer a secure and stable path
724
-
mkdir -p ~/xyz
725
-
chmod 700 ~/xyz
726
797
727
798
# For files, we use permission 600
728
799
chmod 600 ~/.jupyter/jupyter_server_config.py
729
800
chmod 600 ~/.jupyter/jupyter_server_config.json
730
-
## location of cookie secret file
731
-
chmod 600 ~/xyz/dummy_file
732
801
```
733
802
734
803
### Customizing user interface
735
804
805
+
If you need to add custom themes, fonts, shortcuts, etc. for Jupyter, you may follow this section, else safe to skip to [Start Jupyter](#start-jupyterlab) section.
806
+
736
807
Before installing themes or customizing jupyterlab further, I will install [node js](https://nodejs.org/en/) package to _base_ env.
737
808
738
809
>Ideally, _base_ env should not be cluttered with packages except bare mininmum that comes with original conda installation (mambaforge in my case). However, node js is required to setup and manage jupyterlab extensions and how jupyterhub can interact with a few kernels, e.g., `jupyterlab-sql` extension to interact with sql databases that I will end up installing in the future.
@@ -746,7 +817,7 @@ npm --version
746
817
747
818
#### Themes
748
819
749
-
Optional: Themes provide custom user interface and is optional for setup. See example themes at https://github.com/dunovank/jupyter-themes
820
+
Themes provide custom user interface and is optional for setup. See example themes at https://github.com/dunovank/jupyter-themes
750
821
751
822
```sh
752
823
mamba install -c conda-forge jupyterthemes
@@ -801,7 +872,7 @@ If you are familiar with RStudio shortcuts for R pipe `%>%` and assignment `<-`
801
872
802
873
#### gpg signatures
803
874
804
-
Optional: Import gpg keys, if any for [code signing](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits). More at https://unix.stackexchange.com/a/392355/28675
875
+
Import gpg keys, if any for [code signing](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits). More at https://unix.stackexchange.com/a/392355/28675
805
876
806
877
Earlier I installed required gpg packages, _gpg_ and _python-gnupg_ but they ended up conflicting with `gpg-agent` that is running by the system gpg at `/usr/bin/gpg`. So, I have to remove both conda packages in order to use system gpg at `/usr/bin/`.
807
878
@@ -848,7 +919,7 @@ gpg --list-secret-keys
848
919
849
920
#### rmate
850
921
851
-
Optional: I user `rmate` command to open remote files on HPC in the text editor like Atom or SublimeText on my macbook.
922
+
I user `rmate` command to open remote files on HPC in the text editor like Atom or SublimeText on my macbook.
852
923
853
924
* Prefer installing [standalone binary](https://github.com/textmate/rmate) over ruby-based (`gem install rmate`) command. If you prefer ruby based installation, better to add ruby installation in a separate conda env, e.g., in _luke_ or other backend env.
854
925
@@ -907,8 +978,7 @@ echo $?
907
978
# jupyter server extension enable --py jupyter_http_over_ws
908
979
```
909
980
910
-
* Test jupyterlab run: Please [read documentation](https://jupyter-notebook.readthedocs.io/en/stable/public_server.html) carefully on using SSL option and defining port and IP.
911
-
981
+
* Test jupyterlab run.
912
982
913
983
!!! warning "☠️ Use SSL and password protection ☠️"
914
984
Avoid running notebook server without SSL and proper password and token configuration as [detailed above](#configure-jupyterlab)) else you may encounter a significant data security risk.
## SSL related settings will be inherited from jupyter config file that
995
+
## we already have created as above.
996
+
jupyter lab --no-browser --ip="${REMOTEIP}"|& tee -a ~/tmp/jupyter/sumner/runtime.log
925
997
```
926
998
927
-
* Once a jupyter session begins and assuming you are on a secure local area network, you can open URL: `https://<REMOTEIP>:<PORT>/lab` to launch jupyter lab.
999
+
* Once a jupyter session begins and assuming you are on a secure local area network, you can open URL: `https://<REMOTEIP>:<PORT>/lab` to launch jupyter lab. Here, `<PORT>` is randomly assigned when you start a server and URL will be displayed on the terminal or in a log file at *~/tmp/jupyter/sumner/runtime.log*.
928
1000
929
1001
!!! warning "Run jupyterlab from a compute and not login node"
930
1002
**Avoid running JupyterLab server on a login node.** It will most likely be killed by HPC admins. For longer running and compute-intensive jupyterlab sessions, it is preferable to run jupyterlab from a compute and not a login node. This requires series of secure port forwarding which is beyond the scope of current documentation. However, your HPC may already have support for running JupyterLab on a compute node, e.g, similar to this one at [Univ. of Bern](https://hpc-unibe-ch.github.io/software/JupyterLab.html) or [Princeton Univ.](https://researchcomputing.princeton.edu/support/knowledge-base/jupyter). Talk to your HPC staff for policies on running JupyterLab server.
@@ -938,4 +1010,4 @@ exit # from sumner
938
1010
ssh sumner
939
1011
```
940
1012
941
-
[In Part 3](../sumner_3/), I will finalize setting up Sumner (or CPU-based) HPC and also install a dedicated conda env for Winter (GPU-based) HPC.
1013
+
[In Part 3](../sumner_3/), I will finalize setting up Sumner (or CPU-based) HPC and also install a dedicated conda env for Winter (GPU-based) HPC. If you like to stop here, you may except I prefer that you follow [bash startup]({{ config.site_url }}/hpc/cpu/sumner_3/#bash-startup) section in Part 3, so that conda and program-specific (R and python) environment variables are consistently loaded across HPC bash user env.
description: "Getting started with HPC Setup. Part 3: Configure conda environments for julia, python2, perl, and postgresql. Add Modules and containers, finally setup bash startup sequence."
Fix link - You can :octicons-file-code-16: [download my bash startup files]({{ repo.url }}{{ repo.tree }}/confs/hpc/user_env/). It will not work by cloning into your linux env. However, each file has inline comments that should help customizing your bash startup.
860
+
Fix link - You can :octicons-file-code-16: [download my bash startup files]({{ repo.url }}{{ repo.blob }}/confs/hpc/user_env/). It will not work by cloning into your linux env. However, each file has inline comments that should help customizing your bash startup.
0 commit comments