- 初衷
方便在服务器上跑一些python爬虫脚本
- 环境准备
Centos × 64 服务器
- 开始
由于Centos预装的是2.×版本的python,而jupyter需要3.4以上的python版本,所以需要再安装python3.4或以上的版本。(注意不要将之前2.×版本的python删掉,否则会出现系统异常)
要安装python3,首先要安装一系列安装包。
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
然后去python官网上下载python3的安装包,具体版本按自己的需求来
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
然后在下创建一个空的文件夹用来当做安装目录
mkdir /usr/local/python3
之后解压下载的安装包,进入该文件夹进行安装
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install
最后创建软连接用来在任意目录下使用python3 命令
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
至此,python3安装完毕。
接下来进行jupyter安装:
- 安装jupyter
pip3 install jupyter
2. 生成配置文件
jupyter notebook --generate-config --allow-root
配置文件生成在:~/.jupyter/jupyter_notebook_config.py
3. 生成密码
jupyter notebook password
4. 修改配置文件
# 设置监听地址,一般改为当前主机的ip
sed -ie "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '0.0.0.0'/g" ~/.jupyter/jupyter_notebook_config.py
# 设置监听端口
sed -ie 's/#c.NotebookApp.port = 8888/c.NotebookApp.port = 8000/g' ~/.jupyter/jupyter_notebook_config.py
# 禁用自动打开浏览器
sed -ie 's/#c.NotebookApp.open_browser = True/c.NotebookApp.open_browser = False/g' ~/.jupyter/jupyter_notebook_config.py
5. 启动jupyter
jupyter notebook --allow-root
6. 访问
在访问前,检查防火墙规则是否允许8000(自己设置的jupyter端口)是否允许被访问。
在浏览器地址栏输入服务器的地址和端口。
进入登录页面后,用刚刚设置的密码登录。
配置完成。开心的玩耍吧!