How to accept connections for ipython from other computers? - configuration

I run ipython 0.12.1 on Ubuntu 12.04. You can run it in browser using notebook interface by running:
ipython notebook --pylab
Configuration files can be found in ~/.config/ipython/profile_default/. It seems that connection parameters for every kernel is placed in ~/.config/ipython/profile_default/security/kernel-4e424cf4-ba44-441a-824c-c6bce727e585.json. Here is the content of this file (new files are created as you start new kernels):
{
"stdin_port": 54204,
"ip": "127.0.0.1",
"hb_port": 58090,
"key": "2a105dd9-26c5-40c6-901f-a72254d59876",
"shell_port": 52155,
"iopub_port": 42228
}
It's rather self-explanatory but how can I set a server that would have a permanent configuration, so I can use notebook interface from other computers in the LAN?

If you are using an old version of the notebook, the following could still apply. For new versions see the other answers below.
Relevant section of the IPython docs
The Notebook server listens on localhost by default. If you want it to be visible to all machines on your LAN, simply instruct it to listen on all interfaces:
ipython notebook --ip='*'
Or a specific IP visible to other machines:
ipython notebook --ip=192.168.0.123
Depending on your environment, it is probably a good idea to enable HTTPS and a password when listening on external interfaces.
If you plan on serving publicly a lot, then it's a also good idea to create an IPython profile (e.g. ipython profile create nbserver) and edit the config accordingly, so all you need to do is:
ipython notebook --profile nbserver
To load all your ip/port/ssl/password settings.

The accepted answer/information is for an old version. How to enable remote access to your new jupyter notebook? I got you covered
First, generate a config file if you don't have it already:
jupyter notebook --generate-config
Notice the output of this command as it would tell you where the jupyter_notebook_config.py file was generated. Or if you already have it, it will ask you if you would like to overwrite it with the default config. Edit the following line:
## The IP address the notebook server will listen on.
c.NotebookApp.ip = '0.0.0.0' # Any ip
For added security, type in a python/IPython shell:
from notebook.auth import passwd; passwd()
You will be asked to input and confirm a password string. Copy the contents of the string, which should be of the form type:salt:hashed-password. Find and edit the lines as follows:
## Hashed password to use for web authentication.
#
# To generate, type in a python/IPython shell:
#
# from notebook.auth import passwd; passwd()
#
# The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = 'type:salt:the-hashed-password-you-have-generated'
## Forces users to use a password for the Notebook server. This is useful in a
# multi user environment, for instance when everybody in the LAN can access each
# other's machine through ssh.
#
# In such a case, server the notebook server on localhost is not secure since
# any user can connect to the notebook server via ssh.
c.NotebookApp.password_required = True
## Set the Access-Control-Allow-Origin header
#
# Use '*' to allow any origin to access your server.
#
# Takes precedence over allow_origin_pat.
c.NotebookApp.allow_origin = '*'
(Re)start your jupyter notebook, voila!

Related

Openshift 4.6 Node and Master Config Files

Where is the Openshift Master and Node Host Files in v4.6
Previously hosted below in v3
Master host files at /etc/origin/master/master-config.yaml
Node host files at /etc/origin/node/node-config.yaml
You can check your current kubelet configuration using the following procedures instead of the configuration file on the node hosts like OCPv3. Because the kubelet configuration was managed dynamically as of OCPv4.
Further information is here, Generating a file that contains the current configuration.
You can check it using above reference procedures(Generate the configuration file) or oc CLI as follows.
$ oc get --raw /api/v1/nodes/${NODE_NAME}/proxy/configz | \
jq '.kubeletconfig|.kind="KubeletConfiguration"|.apiVersion="kubelet.config.k8s.io/v1beta1"'
These files no longer exist in the same for as in OCP 3. To change anything on the machines themselves, you'll need to create MachineConfigs, as CoreOS is an immutable Operating System. If you change anything manually on the filesystem and reboot the machine, your changes will typically be reset.
To modify Worker Nodes, often the setting you are looking for can be configured via a kubeletConfig: Managing nodes - Modifying Nodes. Note that only certain settings can be changed, others cannot be changed at all.
For the Master Config, it depends on what you want to do, as you will potentially change the setting via a machineConfigPool or for example edit API Server setting via oc edit apiserver cluster. So it depends on what you actually want to change.

Dovecot log file location on Nixos

I want to use dovecot as a local IMAP server to serve my offlineimap synced mails to gnus. This is on a Nixos installation. I have installed the dovecot package via my configuration.nix. however I am having trouble configuring it, seeing where the log files are, etc. I copy the configuration files (dovecot.conf and config.d) from /nix/store/dovecot/share/doc/dovecot/example-config. I can then modify slightly the files to allow plain login (no ssl required) just to test.I can start dovecot (as root). I see the process running, the relevant ports are open and listening, e.g. 143. Everything looks OK. No crashes. However when I telnet localhost 143 (for imap) to test, I am connected and then immediately the connection is closed by foreign host. This is not what I expect from the Dovecot Wiki. I should get a statement that Dovecot is ready …
Additionally, the command doveadm log find responds with:
Looking for log files from /var/log Debug: Not found Info: Not found etc.
So there seem to be no log files. journalctl -u dovecot2.service shows logs begin …, end at …
No entries, so no issues ? I cannot find a log file which tells me why the connection on 143 is immediately closed.
I am at a loss what is going on. Is it to do with users needed, etc ? Appreciate any help. Can post doveconf -n if needed.
As written in the configuration file for dovecot2 here: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/mail/dovecot.nix#L344 as dovecot2 is the name of the service journalctl -u dovecot2 should be the right command to run to view its logs. That said, if for some reason there's a bug in the configuration module the command journalctl will show you the complete log, dovecot's included.
It would be nice if you had written here your configuration, because given that the configuation entries for dovecot are those listed here https://nixos.org/nixos/options.html#services.dovecot2 it's not clear to me what you mean when you write ... I copy the configuration files (dovecot.conf and config.d) from /nix/store/dovecot/share/doc/dovecot/example-config ... The configuration in nixos is comprised for the most part of Nix source files that specify entries in the NixOS configuration tree I've linked before.
I was doing things completely wrong. I now specify the dovecot service to start in my configuration.nic file and it sets up the correct environment with all config files in their correct place. To change options in the config file, e.g maildir, I now specify them also in the configuration.nix file. Thanks for your answer.

EB: Trigger container commands / deploy scripts on configuration change

I am running my web server on Elastic Beanstalk, and using Papertrail for logging. I am using the official .ebextensions script to get papertrail set up during deployment, but I have a problem. I use environment variables as part of my hostname used as the sender when remote_syslog uploads logs to papertrail, and while this works fine during deployment, when the 01_set_logger_hostname container command is triggered, I run into problems whenever I change environment variables by modifying the environment's configuration, since it seems an eb config call will only restart the application server, not run any of the scripts run during deployment, including the ebextensions container commands.
"/tmp/set-logger-hostname.sh":
mode: "00555"
owner: root
group: root
encoding: plain
content: |
#!/bin/bash
logger_config="/etc/log_files.yml"
appname=`{ "Ref" : "AWSEBEnvironmentName" }`
instid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
myhostname=${SOME_VARIABLE}_${appname}_${instid}
if [ -f $logger_config ]; then
# Sub the hostname
sed "s/hostname:.*/hostname: $myhostname/" -i $logger_config
fi
As you can see, since my hostname depends on ${SOME_VARIABLE}, I need to refresh the hostname whenever ${SOME_VARIABLE} is modified following eb config.
Is there a way to trigger a script to be run whenever an eb config command is run, so that I can not only restart my web application but also reconfigure and restart remote_syslog with the updated hostname?
This is now possible on AWS Linux 2 based environments with Configuration deployment platform hooks.
For example, you can make a shell script .platform/confighooks/predeploy/predeploy.sh that will run on all configuration changes. Make sure that you make this file executable according to git, or Elastic Beanstalk will give you a permission denied error.

ssh AWS, Jupyter Notebook not showing up on web browser

I am trying to use ssh connecting to AWS "Deep Learning AMI for Amazon Linux", and everything works fine except Jupyter Notebook. This is what I got:
ssh -i ~/.ssh/id_rsa ec2-user#yy.yyy.yyy.yy
gave me
Last login: Wed Oct 4 18:01:23 2017 from 67-207-109-187.static.wiline.com
=============================================================================
__| __|_ )
_| ( / Deep Learning AMI for Amazon Linux
___|\___|___|
The README file for the AMI ➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜➜ /home/ec2-user/src/README.md
Tests for deep learning frameworks ➜➜➜➜➜➜➜➜➜➜➜➜ /home/ec2-user/src/bin
=============================================================================
1 package(s) needed for security, out of 3 available
Run "sudo yum update" to apply all updates.
Amazon Linux version 2017.09 is available.
Then
[ec2-user#ip-xxx-xx-xx-xxx ~]$ jupyter notebook
[I 16:32:14.172 NotebookApp] Writing notebook server cookie secret to /home/ec2-user/.local/share/jupyter/runtime/notebook_cookie_secret
[I 16:32:14.306 NotebookApp] Serving notebooks from local directory: /home/ec2-user
[I 16:32:14.306 NotebookApp] 0 active kernels
[I 16:32:14.306 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0
[I 16:32:14.306 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 16:32:14.307 NotebookApp] No web browser found: could not locate runnable browser.
[C 16:32:14.307 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0
Copying http://localhost:8888/?token=74e2ad76eee284d70213ba333dedae74bf043cce331257e0 and get
"can’t establish a connection to the server at localhost:8888." on Firefox,
"This site can’t be reached localhost refused to connect." on Chrome
Further,
jupyter notebook --ip=yy.yyy.yyy.yy --port=8888 gives
Traceback (most recent call last):
File "/usr/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/usr/lib/python3.4/dist-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/lib/python3.4/dist-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/usr/lib/python3.4/dist-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "/usr/lib/python3.4/dist-packages/notebook/notebookapp.py", line 1296, in initialize
self.init_webapp()
File "/usr/lib/python3.4/dist-packages/notebook/notebookapp.py", line 1120, in init_webapp
self.http_server.listen(port, self.ip)
File "/usr/lib64/python3.4/dist-packages/tornado/tcpserver.py", line 142, in listen
sockets = bind_sockets(port, address=address)
File "/usr/lib64/python3.4/dist-packages/tornado/netutil.py", line 197, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
Note sure this will be helpful (Is it only for MXNet ? I am not familiar with MXNet) Jupyter_MXNet
localhost will only work when trying to use jupyter (or well, anything) from the machine itself. In this case, it seems you're trying to access it from another machine.
You can do that with the switch --ip=a.b.c.d, where a.b.c.d is the public address of your EC2 instance (or using 0.0.0.0 to make it listen in all interfaces.)
You can also use --port=X to define a particular port number to listen to.
Just remember that your security group must allow access from the outside into your choice of IP/Port.
For example:
jupyter notebook --ip=a.b.c.d --port=8888
Well, there are few things happening here.
ISSUE # 1 - Localhost
As Y. Hernandez said you are trying to access the URL incorrectly. You should replace localhost with the public IP address of your AWS VM (same IP you used to ssh into).
ISSUE # 2 - Jupyter needs proper configuration
But even then, this might not run because Jupyter has not been completely configured out of the box, you are using Deep Learning AMI for Amazon Linux. You need complete these following steps (of course there are multiple others of doing the same thing - and this is just one such way).
Configure Jupyter Notebook -
$ jupyter notebook --generate-config
Create certifications for our connections in the form of .pem files.
$ mkdir certs
$ cd certs
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
You’ll get asked some general questions after running that last line. Just fill them out #with some general information or keep pressing enter.
Next we need to finish editing the Jupyter Configuration file we created earlier. So change to .jupyter folder. For this, you can use nano or vi or your fav editor.
$ cd ~/.jupyter/
$ nano jupyter_notebook_config.py
Insert this code at the top of the file -
—insert begin——
c = get_config()
# Notebook config this is where you saved your pem cert
c.NotebookApp.certfile = u'/home/ubuntu/certs/mycert.pem'
# Run on all IP addresses of your instance
c.NotebookApp.ip = '*'
# Don't open browser by default
c.NotebookApp.open_browser = False
# Fix port to 8888
c.NotebookApp.port = 8888
-insert end——
save file
cd out of .jupyter folder
$ cd
You can set up a separate Notebook folder for Jupyter or from you anywhere you
choose, you can launch Jupyter
$ jupyter notebook
On your browser go to this url using your vm IP address and the token given in your terminal
http://VM-IPAddress:8888/?token=72385d6d854bb78b9b6e675f171b90afad47b3edcbaa414b
IF you get an SSL error, then you use https instead of http.
https://VM-IPAddress:8888/?token=72385d6d854bb78b9b6e675f171b90afad47b3edcbaa414b
ISSUE # 3 - Won't be able to launch Python interpreter.
if you intend to run Python 2 or 3, you need to upgrade iPython. If not, once you launch Jupyter, you will not see an option to launch Python interpreter. You will only see options for Text, Folder and Terminal.
Upgrade iPython. For this, shutdown your Jupyter and run this upgrade command.
$ sudo pip install ipython --upgrade
Relaunch Jupyter.
In Amazon DL AMIs, these occurs sometimes. Do
jupyter notebook password
set notebook password and do:
sudo jupyter notebook --ip 0.0.0.0 --port 8888 --allow-root
allow root is not necessary, but it allows copy/paste as a root user.

Couchbase Mobile (Sync Gateway) sample TODOlite application doesn't replicate; complains _facebook doesn't exist

My objective: get https://github.com/couchbaselabs/ToDoLite-iOS syncing with a Couchbase Server and sync gateway on localhost rather than the default demo URL.
I run sync gateway like so: bin/sync_gateway -url http://localhost:8091
And then the only thing I changed in the example is:
-#define kSyncGatewayUrl #"http://demo.mobile.couchbase.com/todolite"
+#define kSyncGatewayUrl #"http://localhost:4984/sync_gateway/"
And when I run
Error: Error Domain=CBLHTTP Code=404 "404 not_found" UserInfo=0x7ff11941fb50 {NSURL=http://localhost:4984/sync_gateway/_facebook, NSLocalizedFailureReason=not_found, NSLocalizedDescription=404 not_found}
How do I fix this?
I solved it. The reason is that I ran sync_gateway without enabling Facebook registration support.
Normally this is done in config.json file. In fact, this configuration file was supplied in ToDoLite all along.
It is crucial that you launch sync_gateway with this configuration file. The README actually states this but in a loose and casual way...
cd ToDoLite-iOS
sync_gateway -url http://localhost:8091 sync-gateway-config.json
NB: I assume above that sync_gateway has been made accessible through $PATH. It's a good idea to do that anyway.
Also, I didn't pay attention to the dbname. So you'll need to replace
#define kSyncGatewayUrl #"http://demo.mobile.couchbase.com/todolite"`
with
#define kSyncGatewayUrl #"http://localhost:4984/todos"
So, what's the complete sequence of steps to get it working?:
If you want to wipe everything on the server, rm -rf Library/Application\ Support/Couchbase and start over. Homebrew cask hides this setting somewhere else where it's hard to reset so a manual install is very recommended.
Install Couchbase Server
Set up login credentials if fresh install; otherwise just login
Create a bucket (a database) with name todos on the cluster. This is the dbname used by TODOLite.
Launch sync gateway. Be sure to pass in the replication URL AND the JSON config file.
bin/sync_gateway -url http://localhost:8091 sync-gateway-config.json; keep sync gateway running
In the TODOLite AppDelegate.m, change kSyncGatewayUrl:
#define kSyncGatewayUrl #"http://localhost:4984/todos". Notice the name of the database is necessary!
(Optionally) Access the administrator interface of the sync gateway by going to http://localhost:4985/_admin/db/sync_gateway/sync. You can set up the sync function here.
In case you're wondering where those port numbers came from, check out
ports Couchbase Server uses
ports Sync Gateway uses
4984 — SG API port
4985 — SG admin server
The default remote sync URL will be defined in different files depending on the version of the project you download (iOS, Android, PhoneGap, and Motion). To find the appropriate string to change simply search through your project for the URL "http://demo.mobile.couchbase.com/todolite" and replace it with the URL of your new sync gateway database.