ubuntu 20.04服务器指南(命令行篇)
换源
cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list
ggdG
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
安装gedit
sudo apt-get install gedit
显卡驱动
-
创建文件,如果没有下载vim编辑器,将vim换成gedit即可
sudo gedit /etc/modprobe.d/blacklist.conf -
在文件中插入以下内容,将nouveau加入黑名单,默认不开启
blacklist nouveau options nouveau modeset=0 -
输入以下命令使禁用生效然后重启
sudo update-initramfs -u sudo reboot -
重启后验证,没有输出就是正确的
lsmod | grep nouveau -
安装显卡驱动,先完全卸载之前安装的显卡驱动
sudo apt-get remove --purge nvidia* -
查看显卡信息
lshw -numeric -C display -
查看合适的显卡驱动,没有先安装
ubuntu-drivers devices -
然后安装命令安装
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get update sudo apt-get install nvidia-driver-450-server sudo apt-get install mesa-common-dev -
安装完后重启
sudo reboot -
查看安装是否成功
nvidia-smi
cuda和cudnn配置
-
去cuda官网下载cuda10.2,选择deb(local),然后按照官方命令走
-
配置变量环境
sudo gedit ~/.bashrc添加两行
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}然后
source ~/.bashrc -
重启,然后测试nvcc -V,
-
下载cudnn里面的三个文件
-
按照文档进行安装
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#axzz4qYJp45J2
安装anaconda
运行.sh文件,bash xxx.sh
接下来就是目标检测一条龙了s
Github加速
保存全局密码
git config --global credential.helper store
URL替换
git config --global url."https://github.com.cnpmjs.org/".insteadOf "https://github.com/"
或直接修改~/.gitconfig文件,添加以下内容:
[url "https://github.com.cnpmjs.org/"]
insteadOf = https://github.com/
# 这是我们要clone的
git clone https://github.com/hyperledger/fabric.git
git clone https://github.com/Hackergeek/architecture-samples
# 使用镜像
git clone https://github.com.cnpmjs.org/hyperledger/fabric.git
git clone https://github.com.cnpmjs.org/open-mmlab/mmdetection.git
git clone https://github.com.cnpmjs.org/Hackergeek/architecture-sample
# 或者 使用镜像
git clone https://git.sdut.me/Hackergeek/architecture-samples
科学上网
参考网址:https://knowledgebase.renzhecloud.link/zh/article/linux-clash-13smf1c/
下载clash地址:https://github.com/Dreamacro/clash/releases
#下载
wget -N --no-check-certificate https://github.com/Dreamacro/clash/releases/download/v1.4.1/clash-linux-amd64-v1.4.1.gz
#解压
gunzip clash-linux-amd64-v1.4.1.gz
#改名为clash
chmod +x clash
#下载clash配置链接,并且重命名为config.yaml
#在终端执行
nohup ./clash -d . >>log 2>&1 &
#查看进程
ps -aux | grep clash | grep -v grep
#远程管理,端口为9090,需要提前在腾讯云打开
http://clash.razord.top/#/proxies
#终止进程
pkill -9 clash
#增加别名,需要的时候再打开,不需要的时候关闭
vi ~/.bashrc
alias setproxy="export ALL_PROXY=127.0.0.1:7890"
alias unsetproxy="unset ALL_PROXY"
alias ip="curl www.trackip.net/i"
防火墙开放
#查看防火墙的状态
sudo ufw status
#关闭防火墙
sudo ufw disable
#开启防火墙
sudo ufw enable
#开启或者关闭端口
sudo ufw allow/deny 9090
Nodejs
安装Nodejs
添加PPA 用Ubuntu的方式安装,这个12数字可以更换成14,16等等
#添加源
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
#安装
sudo apt-get install -y nodejs
#查看版本
node -v
镜像源查看和切换
全局切换镜像源:
npm config set registry http://registry.npm.taobao.org
查看镜像源使用状态:
npm get registry
全局切换官方镜像源:
npm config set registry http://www.npmjs.org
yarn
全局镜像切换
yarn config set registry https://registry.npm.taobao.org/
获取当前镜像源
yarn config get registry
换回官方源
yarn config set https://registry.yarnpkg.com
性能监控1
参考网址:https://0xzx.com/2021010900161074136.html/amp
https://www.jianshu.com/p/08cc9a39a265
安装 sar 并监控系统状态
#1、安装
sudo apt-get install sysstat
#2、修改,改为true
sudo vim /etc/default/sysstat
#3、重启
sudo service sysstat restart
#4、安装完成后,请使用以下命令启动SAR服务并使其在系统重新启动时启动:
systemctl start sysstat
systemctl enable sysstat
#5、在安装过程中,SAR每10分钟生成一个Cron文件,用于收集和生成报告。 您可以使用以下命令进行检查:
cat /etc/cron.d/sysstat
修改SAR,每1分钟生成一个Cron文件
sudo vi /etc/cron.d/sysstat
#每一分钟生成一次(粒度最小为分钟)
*/1 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
#然后重新加载配置文件
service cron reload
查看文件
#文件在这/var/log/sysstat/ssDD
#查看某一天的文件,最多只保存一个月的,应该就是覆盖保存了
sar -f /var/log/sysstat/ssDD
#cron的运行日志在/var/log/syslog里面
监测CPU(临时命令)
#您可以运行以下命令每1秒,一共监视4次CPU使用率,并保存到文件
sar 1 4 -o cpu-report
#sar -u 1 -o cpu-report
查看CPU情况
sar -f cpu-report
监测内存
sar -r 1 4
检测分页情况
sar -B 1 4
性能监控2
atop
①apt install atop
②编辑/etc/default/atop修改间隔时间
LOGINTERVAL=60
日志在/var/log/atop
修改文件权限
#文件夹的权限为755
sudo find . -type d -exec chmod 755 {} \;
#文件的权限为644
sudo find . -type f -exec chmod 664 {} \;
设置开机自启
在/etc/rc.local里面加入启动语句就行了
后台运行且关闭
#后台运行
nohup python2 /home/ubuntu/software/cos-ftp-server-V5/ftp_server.py >> /dev/null 2>&1 &
#停止运行
ps -ef | grep python | grep ftp_server.py | grep -v grep | awk '{print $2}' | xargs -I{} kill {}
其他
实时刷新
watch -n 1 -d nvidia-smi
