文章目录
前言
由于学校或者公司服务器不会给普通用户开通root权限,因此每次新装服务器都需要从非root用户安装配置自己的环境。此篇记录一下linux常用的软件配置和安装。方便重装系统!!!
一、zsh和oh-my-zsh配置
安装zsh
mkdir zsh && cd zsh # 新建文件夹
wget -O zsh.tar.xz https://sourceforge.net/projects/zsh/files/latest/download # 下载最新版本zsh
xz -d zsh.tar.xz # .tar.xz 文件需要解压两次
tar -xvf zsh.tar
cd zsh-5.7.1 #不同版本此路径不一样,cd就完事了
./configure --prefix=$HOME/usr/ # 指定路径configure
make && make install # 安装
问题
安装时如果出现下面问题:
./configure
时出现问题
configure: error: “No terminal handling library was found on your system.
This is probably a library called ‘curses’ or ‘ncurses’. You may
need to install a package called ‘curses-devel’ or ‘ncurses-devel’ on your
system.”
See `config.log’ for more details
make
时出现问题
make: *** No targets specified and no makefile found. Stop.
解决方法
先配置环境变量,如下命令写入~/.bashrc
文件方便使用:
export CXXFLAGS="-fPIC"
export CFLAGS="-fPIC"
export NCURSES_HOME=$HOME/usr # 你自己的 ncurses 目录
export PATH=$NCURSES_HOME/bin:$PATH
export LD_LIBRARY_PATH=$NCURSES_HOME/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I$NCURSES_HOME/include" LDFLAGS="-L$NCURSES_HOME/lib"
然后运行source ~/.bashrc
使其生效。
然后安装ncurses,找到最新版本ncurses下载安装
cd ../../ && mkdir ncurses && cd ncurses # 切换到上级目录新建ncurses文件夹
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.1.tar.gz # 找到最新版本ncurses,并更改版本号
tar -xzvf ncurses-6.1.tar.gz # 解压
cd ncurses-6.1
./configure --prefix=$HOME/usr/ --with-shared --without-debug --enable-widec # 指定路径configure
make && make install # 安装
然后回到zsh下重新./configure
及 make && make install
就可以了
安装oh-my-zsh
安装 oh-my-zsh
前先将安装好的 zsh
所在的路径添加到系统环境变量 PATH
中
export PATH=$HOME/zsh/bin:$PATH
安装 oh-my-zsh
几种方法
# 方法一:wget方式自动化安装oh my zsh:
$ wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
# 方法二:
$ curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
# 官网上的另外一种写法
$ sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# 方法三:手动安装
$ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
注: 1. 克隆后将templates目录下的zsh配置文件拷贝至~/.zshrc即可
2. .oh-my-zsh一定要在$HOME下( ~ 下)
可以用gitee作为中转。
问题
按如上步骤安装完后cat /etc/shells
仍然不会显示有zsh
,因为我们是装在自己的目录$HOME/usr/bin/zsh
中。所以启动时仍然默认是bash
,我们在~/.bashrc
文件中再添加如下命令即可让zsh
自启动
export SHELL=$HOME/usr/bin/zsh
exec $HOME/usr/bin/zsh -l
二、tmux安装
这部分由于我有root权限,直接用root安装了,后续在没有root权限的服务器上装时再补充。
sudo apt-get install tmux
三、anaconda安装
- 清华镜像站介绍,镜像下载地址,下载对应版本的anaconda,目前最新的是
Anaconda3-2020.11-Linux-x86_64.sh
。 - 然后
bash Anaconda3-2020.11-Linux-x86_64.sh
安装,根据指令安装完成即可。 - 将conda加入PATH
echo 'export PATH="$HOME/anaconda3/bin:$PATH"'>>~/.bashrc source ~/.bashrc
- 修改conda为清华源,如果
~/.condarc
不存在,则先输入conda config --add channels r
创建该文件,然后将文件内容修改为:
这一步可见清华镜像站介绍channels: - defaults show_channel_urls: true channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
四、pytorch
安装最新版pytorch方法见pytorch官网,一般都会根据cuda版本的需要安装旧版本,可见此链接。
服务器安装的cuda版本为10.2,因此选择如下命令安装gpu版本
pip install torch==1.5.0 torchvision==0.6.0
五、配置ssh和putty登录
1 本地生成密钥对
ssh-keygen -t rsa
默认保存位置即可。
密码可以选择不填。id_rsa
是私钥,id_rsa.pub
是公钥。
2 公钥添加到服务器
连接到远程服务器
vim ~/.ssh/authorized_keys
将id_rsa.pub
中的内容复制进去即可。
之后ssh username@xx.xx.xx.xx
即可免密登录。
3 putty免密登录
首先使用puttygen
工具生成密钥对
将其中的公钥复制到远程服务器的~/.ssh/authorized_keys
文件中,并点击保存公钥和私钥到本地的C:\Users\username/.ssh/
文件夹中。
然后进入putty
配置,输入服务器IP
配置登录用户名
配置私钥位置
最后记得将配置保存!!!!
打开后即可免密登录
六、配置vscode远程连接
1 安装扩展
2 配置
安装完插件后侧边栏会出现远程电脑的按钮,点击进入如下界面,点击设置
打开默认第一个文件
输入如下配置并保存
Host xx #可随意输入
HostName xx.xx.xx.xx #服务器IP
User username #你的用户名
左侧会出现你的服务器
再点击右侧的按钮即可打开远程窗口,如果你已经按照前一步配置了ssh免密登录,则vscode远程登陆也可以免密。否则打开远程窗口需要输入用户密码,打开文件夹需要再次输入密码。之后就可以跟本地一样在服务器使用vscode啦~
七、配置jupyter notebook远程连接
1 生成配置文件
$ jupyter notebook --generate-config
Writing default config to: /home/sakura/.jupyter/jupyter_notebook_config.py
2 配置密码
部分教程会选择设置空密码,方便登录,但为了服务器安全起见,还是设置强密码为好。
方法一 自动生成
$ jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/sakura/.jupyter/jupyter_notebook_config.json
方法二 ipython手动生成
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
然后将密钥添加到jupyter_notebook_config.py
,路径也在/home/sakura/.jupyter/
下,将文件中的密钥取消注释并改为
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
3 其他配置
同样打开jupyter_notebook_config.py
,添加如下配置
c.NotebookApp.ip = '服务器IP'
c.NotebookApp.password = u'sha:ce...刚才复制的那个密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =88 #可自行指定一个端口, 访问时使用该端口
然后运行jupyter notebook
启动服务,在本地浏览器访问服务器IP:端口号
即可访问jupyter,第一次需要输入密码。
4 配置虚拟环境
首先创建anaconda虚拟环境
conda create -n torch python=3.7
进入虚拟环境安装插件nb_conda
source activate torch
conda install nb_conda
然后启动jupyter notebook会发现多了一个环境
在文件中也可以更改虚拟环境
改为torch环境后输出如下
可见更换虚拟环境成功