从零开始配置一个服务器(生信与临床研究方向)

基本信息

服务器配置

  • 4核 8G,带宽 5M,200G 硬盘

更改 root 用户名密码

vi /etc/passwd
vi /etc/shadow
#更改这两个文件的第一行的 root 为新用户名
sudo passwd root

创建新用户

useradd user01 -d /home/user01
passwd user01

用 VPN 连接校园网

yum install openconnect
openconnect ocvpn.sysu.edu.cn -u netid

安装 R Studio Server

yum install epel-release
yum install R

wget https://download2.rstudio.org/server/centos6/x86_64/rstudio-server-rhel-1.3.1073-x86_64.rpm

yum install rstudio-server-rhel-1.3.1073-x86_64.rpm
#登录方式为ip:8787,不能用root账号登录

安装 Python3

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
tar zxf Python-3.8.5.tgz

cd Python-3.8.5/

./configure --prefix=/usr/python --enable-shared CFLAGS=-fPIC
make && make install

ln -s /usr/python/bin/python3 /usr/bin/python3.8
ln -s /usr/python/bin/pip3 /usr/bin/pip3

#添加lib,没有这一步会报错
vim etc/ld.so.conf.d/python3.conf #如果没有这个文件就重新建
/usr/python/lib #这文件里输入这一行就退出

ldconfig #输入这个命令后才能生效

python3.8 --version

安装 jupyterhub

安装 nodejs

# 安装 nodejs 到官网下载安装
wget https://npm.taobao.org/mirrors/node/v14.8.0/node-v14.8.0-linux-x64.tar.xz
xd -d *tar.xz
tar -xvf *.tar

#配置环境变量
vi /etc/profile #在这个文件里追加以下两行
export NODEJS_HOME=/root/software/nodeJS/node-v14.8.0-linus-x64
export PATH=$PATH:$NODEJS_HOME/bin

source /etc/profile

node -v

安装 jupyterhub 和 jupyter notebook

pip3 install jupyterhub -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

pip3 install notebook -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
# 腾讯云的镜像不如阿里云的好用,建议yum的源也换成阿里云的。

jupyterhub --generate-config
jupyter notebook --generate-config

可能踩的坑

  1. ModuleNotFoundError: No module named ‘_ctypes’
    错误原因:

Python3中有个内置模块叫ctypes,它是Python3的外部函数库模块,它提供兼容C语言的数据类型,并通过它调用Linux系统下的共享库(Shared library),此模块需要使用CentOS7系统中外部函数库(Foreign function library)的开发链接库(头文件和链接库)。
由于在CentOS7系统中没有安装外部函数库(libffi)的开发链接库软件包,所以在安装pip的时候就报了"ModuleNotFoundError: No module named ‘_ctypes’"的错误。参考资料

yum install libffi-devel

#安装这个库后,要重新进入 Python3 的安装包,重新编译
cd Python3.8
make && make install
  1. ImportError: No module named _ssl
#查看openssl是否已经安装
rpm -qa|grep openssl
whereis openssl

# 安装 openssl-dev
yum install openssl-devel

# 修改 setup 文件
cd Python3.5/Modules
vim Septup
# 把以下 4 行的注释去掉
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

# 重新编译
make && make install

参考资料

  1. ModuleNotFoundError: No module named ‘pysqlite2’

错误原因,服务器一般是从源码安装 python 的,sqlite3并没有包含在安装包里,需要依赖系统的库

yum install sqlite-devel
sqlite3 -version

#照例重新编译安装 python
cd python3.8
make && make install

jupyterhub 默认端口是 8000

把 jupyterhub 设置为系统服务

# 建立一个 jupyterhub.sh 脚本,内容如下

#!/bin/bash -l
jupyterhub --no-ssl >> jupyterhub.log
# 让 jupyterhub.sh 变成可执行文件
chmod a+x jupyterhub.sh
# 在/etc/systemd/system/ 下建立一个 jupyterhub.service 的文件,写入如下命令
[Unit]
Description=jupyterhub
After=syslog.target network.target
[Service]
User=root
ExecStart=/root/software/jupyterhub.sh
[Install]
WantedBy=default.target
# 启动服务
systemctl start jupyterhub
systemctl status jupyterhub

配置 X11 转发

# vi /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

# sudo systemctl restart sshd

# 不行的话安装 xauth
yum install xorg-x11-auth

猜你喜欢

转载自blog.csdn.net/Alleine/article/details/108106609