1.环境准备
yum -y install sqlite-devel #在安装Python之前执行,ipython notebook依赖sqlite执行
pip install ipython
pip install notebook
pip install pysqlite #ipython notebook 依赖sqlite数据库,必须安装后才能使用
[错误处理]
如果安装sqlite-devel后,执行命令
ipython notebook
仍然出现下面的错误
"没有名字为_sqlite3的模块",一般来说需要重新编译python环境然后使用下面的命令拷贝sqlite.so文件到系统目录
cp /usr/local/src/Python-2.7.8/build/lib.linux-i686-2.7/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
拷贝过去后,重新执行
ipython notebook #此时应该可以正常运行
2.配置启动
2.1创建ipython notebook的登录密码
import IPython
IPython.lib.passwd('yourpassword')
2.2使用supervisor进行ipython notebook的管理
#添加程序到supervisor
[program:notebook]
command = ipython notebook --notebook-dir=/R3/notebook/notebook/ --ip=ip_addr --no-mathjax --no-browser --NotebookApp.password=sha1:5
2de8d6f2ea6:90387094a062f493e7eea3df503c28ab3c3b8bf1
directory=/R3/notebook
stopsignal=QUIT
autostart=true
autorestart=true
startsecs=10
startretries=36
stdout_logfile=/R3/logs/ipython_check.log
stdout_logfile_backups=10
stdout_logfile_maxbytes=10MB
stderr_logfile=/R3/logs/ipython_check_err.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
loglevel=info
[command说明]
--notebook-dir 指定notebook的工作目录
--ip=169.24.2.82 指定notebook的服务器IP地址
--no-mathjax 禁止联网下载math的js
--no-browser 禁止启动时打开浏览器
--NotebookApp.password 指定用户密码(上述中创建的密码)
关于supervisor的安装配置及管理可参见官方站点
2.3设置开启以普通用户的方式执行supervisord程序
将下面的命令添加到/etc/rc.local文件中
su - george -c 'supervisord -c /etc/supervisor.conf'
每次启动后会自动启动supervisord进程,由该进程服务对ipython notebook进程进行管理
2.4检查是否正常启动
netstat -tunl|grep 8888检查服务器是否在8888端口进行监听
检查防火墙是否授权8888端口对外提供服务
浏览器中输入 http://ip:8888/会自动跳转到要求输入密码
**建议使用Firefox浏览器进行访问**
3.配置Nginx使其支持notebook的反向代理
location / {
proxy_pass http://ip:8888;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
**本质上notebook的通讯机制是使用websocket,在nginx的配置上要让其支持websocket才行
proxy_set_header Connection "$Upgrade"表示其支持websocket
**