admin管理员组文章数量:1597894
ubuntu server 18.04 first config
文章目录
- ubuntu server 18.04 first config
- oneClick
- i3wm
- googlepinyin
- ssh
- samba
- tftp
- nfs
- flash
- iverilog
- python
- vimplug
- 切zsh
- 附录
- A.1 i3wm的常用快捷键
- A.2 调整python优先级
- A.3 多版本切换
- A.4 VirtualBox UUID修改
- A.5 vbox压缩磁盘占用空间
- A.6 anaconda on win10x64
- A.7 虚拟网桥
Note info
- 更新aliyun源
- http://mirrors.aliyun/ubuntu/
- 在vmware上安装该环境,虚拟机无法与宿主机复制粘贴问题,可用如下方法解决
- vmware version :pro 14.1.8 build-14921873
- sudo apt-get install -y open-vm-tools-desktop
- vim .config/i3/config,输入如下
- exec --no-startup-id vmware-user
- 自动窗口大小,可通过安装vmtools解决
- 重启Ubuntu server网络
- sudo systemctl restart systemd-networkd.service
- 解决virtual box共享文件夹的权限问题
- sudo usermod -aG vboxsf $(whoami)
- 也就是给当前用户追加到vboxsf用户组中,因为共享目录的owner group是vboxsf。
- 执行完该命令后,需要重启系统生效,亦可以执行完所有的配置后再重启。
- 如果vim需要
自动补全
插件 coc-nvin,需要安装vim8.2及以上- sudo add-apt-repository ppa:jonathonf/vim
- sudo apt-get update
- sudo apt-get install -y vim vim-gtk3 vim-gui-common
- 本次演示不需要这个插件,代码编写使用vscode,但vscode太占内存
oneClick
- 安装vim8.2(need by coc-nvim)
- sudo add-apt-repository ppa:jonathonf/vim
- sudo apt-get update
- sudo apt-get install -y vim vim-gtk3 vim-gui-common
- sudo apt-get install -y vim vim-gui-common git tree exuberant-ctags cscope unrar sshpass uml-utilities bridge-utils zip lxappearance papirus-icon-theme bison flex libncurses5-dev libssl-dev minicom gitk net-tools qemu zsh clang-10 openjdk-8-jdk
- sudo apt-get install -y
- i3 lightdm lightdm-gtk-greeter nautilus gedit firefox feh alsamixergui pavucontrol build-essential make cmake perl terminator
- fcitx-googlepinyin language-pack-zh-hans fonts-wqy-microhei fonts-wqy-zenhei xfonts-intl-chinese
- openssh-server samba smbclient cifs-utils tftp-hpa tftpd-hpa nfs-kernel-server nfs-common
- ubuntu-restricted-extras flashplugin-installer vlc iverilog gtkwave python3-pip
i3wm
-
sudo apt-get install -y i3 lightdm lightdm-gtk-greeter nautilus gedit firefox feh alsamixergui pavucontrol build-essential make cmake perl terminator
- 选lightdm,因为Lightdm是Ubuntu的默认设置
- 也可以重新选择sudo dpkg-reconfigure lightdm
-
sudo apt-get -y remove gnome-*
- sudo apt-get install -y nautilus
- sudo apt autoremove -y
- Note:防止在Ubuntu server 20.04上安装nautilus时会带上gnome登录桌面
-
常用
-
feh用于配置壁纸、查看图片
-
alsamixergui 搭配 pavucontrol 控制声音
-
i3wm使用见《A.2 i3wm的常用快捷键》
-
重启后,配置时区
- sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- sudo hwclock --systohc
-
关闭自动休眠
- systemctl status sleep.target 查看是否休眠
- sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target 关闭休眠
-
配置息屏
-
xset q #查看当前屏保设置 xset s 5 #5秒后黑屏 xset s off #关闭黑屏 xset dpms 5 #5秒后关闭显示器 xset -dpms #取消自动关闭显示器 xset b off/on #关闭或开启黑屏提示音
-
-
配置文件是$HOME/.config/i3/config
- exec --no-startup-id xset s 0 关闭屏保
- exec --no-startup-id xset dpms 6000 8000 9000 黑屏、睡眠、断电时间分别设为6000s,8000s,9000s,也可以都写0,表示时间永久
-
googlepinyin
- sudo apt-get install -y fcitx-googlepinyin
- 切换输入方式为fcitx,im-config命令实现图形化操作,之后 重启电脑
- 再打开fcitx-configtool图形化添加googlepinyin输入法
- 安装中文包后重启:sudo apt-get install language-pack-zh-hans
- 安装中文字体后重启:sudo apt install fonts-wqy-microhei fonts-wqy-zenhei xfonts-intl-chinese
ssh
- 安装ssh服务
- sudo apt-get install -y openssh-server
- 启动
- sudo /etc/init.d/ssh start
- 关闭防火墙
- sudo ufw disable
- 检查,成功则连接通过
- ssh localhost
- git config
- git config --global user.name xxx
- git config --global user.email xxx@163
- git config --global core.editor vim
- ssh-keygen -t rsa -C xxx@163
samba
安装:sudo apt-get install -y samba smbclient cifs-utils
配置:打开配置文件smb.conf,sudo vim /etc/samba/smb.conf,输入如下内容
#本机配置
security = user
[aldrich]
path = /home/aldrich
browseable = yes
public = no
writable = yes
valid users = aldrich
重启
- sudo smbpasswd -a aldrich #给samba用户设置密码
- sudo service smbd restart
- 或者,sudo /etc/init.d/smbd restart
示例
- sudo mount.cifs -o user=aldrich //10.106.xx.xx/aldrich /mnt
- mount,映射另外一个Ubuntu下的samba到本地
tftp
安装:sudo apt-get install -y tftp-hpa tftpd-hpa
- tftp-hpa是客户端,
- tftpd-hpa是服务器端
创建目录:
- mkdir -p ~/tftproot
- chmod 777 ~/tftproot
配置:sudo vim /etc/default/tftpd-hpa
-
TFTP_USERNAME="tftp" TFTP_DIRECTORY="/home/aldrich/tftproot" TFTP_ADDRESS=":69" TFTP_OPTIONS="-l -c -s"
重启:sudo service tftpd-hpa restart
- systemctl status tftpd-hpa.service #查看状态
- systemctl start tftpd-hpa.service #启动
测试:可通过如下方式,测试tftp是否正常
-
$ cd ~/tftpboot echo "hello tftp service">>a.txt $ echo "hello tftp service,put to tftp serive">>b.txt $ tftp localhost tftp> get a.txt tftp> put b.txt tftp> quit #其中get是取得文件, put是将文件上传到TFTP服务器上。
nfs
安装
- sudo apt-get install -y nfs-kernel-server nfs-common
配置:sudo vim /etc/exports
-
$ cat /etc/exports /home/aldrich *(rw,sync,no_root_squash,no_subtree_check) #直接使用根目录做nfs具有很高的灵活性
创建目录,并创建一个文件:
- mkdir -p /home/aldrich/devnet/nfs;
- touch /home/aldrich/devnet/nfs/a.txt
重启nfs服务:
- sudo service nfs-kernel-server restart
测试nfs服务是否正常
- sudo mount -t nfs -o nolock 127.0.0.1:/home/aldrich/devnet/nfs /opt
- sudo umount /opt
flash
firefox网页视频需要flash插件
- sudo apt-get install -y ubuntu-restricted-extras flashplugin-installer vlc
iverilog
安装
- sudo apt-get install -y iverilog gtkwave
src
// 新建led_demo.v源文件
module led_demo(
input clk,
input rst_n,
output reg led
);
reg [7:0] cnt;
always @ (posedge clk)
begin
if(!rst_n)
cnt <= 0;
else if(cnt >= 10)
cnt <= 0;
else
cnt <= cnt + 1;
end
always @ (posedge clk)
begin
if(!rst_n)
led <= 0;
else if(cnt == 10)
led <= !led;
end
endmodule
testbench
// 仿真testbench文件led_demo_tb.v
`timescale 1ns/100ps
module led_demo_tb;
parameter SYSCLK_PERIOD = 10;
reg SYSCLK;
reg NSYSRESET;
initial
begin
SYSCLK = 1'b0;
NSYSRESET = 1'b0;
end
/*iverilog编译器专用的语句,如果不加的话后面不能生成vcd文件*/
initial
begin
$dumpfile("wave.vcd"); //生成的vcd文件名称
$dumpvars(0, led_demo_tb); //tb模块名称
end
/*iverilog */
initial
begin
#(SYSCLK_PERIOD * 10 )
NSYSRESET = 1'b1;
#1000
$stop;
end
always @(SYSCLK)
#(SYSCLK_PERIOD / 2.0) SYSCLK <= !SYSCLK;
led_demo led_demo_ut0 (
// Inputs
.rst_n(NSYSRESET),
.clk(SYSCLK),
// Outputs
.led( led)
);
endmodule
编译:iverilog -o wave led_demo_tb.v led_demo.v
- 如果调用了多个.v的模块,可以通过-y参数指定源文件的路径,否则编译报错。如果源文件都在同同一个目录,可以直接通过./绝对路径的方式来指定。
生成波形文件:vvp -n wave -lxt2 # 生成vcd波形文件
打开波形文件:gtkwave wave.vcd
make.sh 批处理,一键执行
echo "开始编译"
iverilog -o wave led_demo.v led_demo_tb.v
echo "编译完成"
vvp -n wave -lxt2
echo "生成波形文件"
cp wave.vcd wave.lxt
echo "打开波形文件"
gtkwave wave.lxt
python
-
sudo apt-get install -y python3-pip
-
pip3安装
- sudo python3 -m pip install --upgrade pip setupTools -i https://pypi.tuna.tsinghua.edu/simple
- sudo pip3 install --upgrade pyinstaller numpy pandas sciPy scikit-Learn matplotlib keras scrapy gensim pyzmq flask -i https://pypi.tuna.tsinghua.edu/simple
- 串口相关:sudo pip3 install --upgrade psutil xmodem pyprind pyftdi -i https://pypi.tuna.tsinghua.edu/simple
- sudo pip3 install --upgrade opencv_python-4.5.4.60-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -i https://pypi.tuna.tsinghua.edu/simple
-
插件 说明 numpy 提供数组支持以及相应的高效的处理函数 pandas 强大、灵活的数据分析和探索工具 sciPy 提供矩阵支持以及矩阵相关的数值计算模块 matplotlib 强大的数据可视化工具、作图库 scikit-Learn 支持回归、分类、聚类等强大的机器学习库 keras 深度学习库,用于建立神经网络以及深度学习模型 gensim 用来做文本主题模型的库,文本挖掘可能会用到
vimplug
- cscope
- autoload_cscope.vim,自动加载cscope库
- ctags
- vim-gutentags,自动生成tags
- DoxygenToolKit
- taglist
- mark.vim
- 依赖,vim-ingo-library
- bufexploer
- quickfix(build-in)
- insearch
- NerdCommenter
- nerdtree
- lightline
- leaderf
- coc.nvim
- 升级vim8.2
- sudo add-apt-repository ppa:jonathonf/vim
- sudo apt-get update
- sudo apt-get install -y vim vim-gtk3 vim-gui-common
- Note:要使用master分支,不然因package.json,yarn build失败
- 安装coc.nvim(master)
- curl -sL https://deb.nodesource/setup_14.x | sudo -E bash -
- sudo apt-get install -y nodejs
- sudo npm install -g yarn
- yarn install
- yarn build
- 执行命令
- c/c++补全 :CocInstall coc-clangd
- sudo apt install clang-10 安装C/C++ Language Server
- python补全 :CocInstall coc-pyright
- java补全 :CocInstall coc-java
- c/c++补全 :CocInstall coc-clangd
- 执行:CocInstall coc-snippets 安装代码片段
- 代码段集合,honza/vim-snippets
- 现有的非 LSP 插件
- coc-emmet 提供 emmet 自动补全支持。
- coc-highlight 提供当前单词以及颜色高亮支持。
- coc-lists 提供常用列表支持。
- coc-pairs 提供自动配对支持。
- coc-snippets 提供代码块方案。
- coc-yank 提供 yank 高亮和历史列表。
- coc-git 提供 git chunks、状态、列表等支持
- 升级vim8.2
地址
- https://github/tianzong2019/myvimrc
- https://gitee/tianzong2019/myvimrc
切zsh
- 在虚拟机下使用的过程中有卡顿。。。
- sudo apt install -y zsh
- sh -c “$(curl -fsSL https://raw.fastgit/robbyrussell/oh-my-zsh/master/tools/install.sh)”
- git clone https://github/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- git clone https://github/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
- 配置,~/.zshrc
- plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
- 切换主题
- ZSH_THEME=“eastwood”
- ZSH_THEME=“gallois”
附录
A.1 i3wm的常用快捷键
i3wm配置文件的路径: $HOME/.config/i3/config
-
设置windows键为mod键,i3wm中默认Mod1为Alt,Mod4为windows键,如果想让windows键为mod键,可以在配置文件前加一句:set $mod Mod4。
-
Ubuntu自带的文档管理器命令是:nautilus ; 若直接使用命令打开,则会带着桌面一起打开,这样使用起来不友好,更不方便,使用不带桌面的打开命令是:nautilus --no-desktop
-
快捷键 描述 $mod + D 启动 dmenu,也就是命令输入框,可以在其中输入要打开的软件名称 $mod + Enter 新建一个Terimal $mod + F 窗口全屏 $mod + NUM 跳转到工作区NUM,i3有10个工作区,对应1~9,0 $mod + H 下一次新建窗口时,水平分割窗口 $mod + V 下一次新建窗口时,垂直分割窗口 $mod + S 使窗口以堆叠布局呈现 $mod + W 使窗口以标签布局呈现 $mod + E 使窗口以默认布局呈现,也就是平铺布局 $mod + Shift + Q 关闭当前窗口 $mod + Shift + E 退出 i3 $mod + Shift + C 当场重新加载 i3config, 无需重启 $mod + Shift + R 重启 i3 (还重新加载了 i3config, 又没有退出过程) $mod + J 焦点往左窗口移,也可以使用箭头按键实现上下左右移动 $mod + K 焦点往下窗口移 $mod + L 焦点往上窗口移 $mod + ; 焦点往右窗口移 $mod + Shift + J 窗口左移 $mod + Shift + K 窗口下移 $mod + Shift + L 窗口上移 $mod + Shift + : 窗口右移 $MOD + R 存在多个窗口时,调整窗口大小 $MOD + T 新建窗口有标签栏 $MOD + Y 新建窗口有边框 $MOD + U 新建窗口无标签栏无边框 窗口大小 可使用鼠标拖动窗口边界,以改变窗口大小
A.2 调整python优先级
调整python优先级,ubuntu16.04 下会同时存在python3.5 和 python3.6,让python版本3.6 优先级较高,可进行如下操作
- 安装
- sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
- sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
- 调整
- sudo update-alternatives --config python3
A.3 多版本切换
$ update-alternatives --help
用法:update-alternatives [<选项> ...] <命令>
命令:
--install <链接> <名称> <路径> <优先级>
[--slave <链接> <名称> <路径>] ...
在系统中加入一组候选项。
--remove <名称> <路径> 从 <名称> 替换组中去除 <路径> 项。
--remove-all <名称> 从替换系统中删除 <名称> 替换组。
--auto <名称> 将 <名称> 的主链接切换到自动模式。
--display <名称> 显示关于 <名称> 替换组的信息。
--query <名称> 机器可读版的 --display <名称>.
--list <名称> 列出 <名称> 替换组中所有的可用候选项。
--get-selections 列出主要候选项名称以及它们的状态。
--set-selections 从标准输入中读入候选项的状态。
--config <名称> 列出 <名称> 替换组中的可选项,并就使用其中哪一个,征询用户的意见。
--set <名称> <路径> 将 <路径> 设置为 <名称> 的候选项。
--all 对所有可选项一一调用 --config 命令。
<链接> 是指向 /etc/alternatives/<名称> 的符号链接。(如 /usr/bin/pager)
<名称> 是该链接替换组的主控名。(如 pager)
<路径> 是候选项目标文件的位置。(如 /usr/bin/less)
<优先级> 是一个整数,在自动模式下,这个数字越高的选项,其优先级也就越高。
..........
实例
$ update-alternatives --display python
python - 手动模式
link best version is /usr/bin/python3.5
链接目前指向 /usr/bin/python2.7
link python is /usr/bin/python
/usr/bin/python2.7 - 优先级 1
/usr/bin/python3.5 - 优先级 2
$ update-alternatives --config python
有 2 个候选项可用于替换 python (提供 /usr/bin/python)。
选择 路径 优先级 状态
------------------------------------------------------------
0 /usr/bin/python3.5 2 自动模式
* 1 /usr/bin/python2.7 1 手动模式
2 /usr/bin/python3.5 2 手动模式
要维持当前值[*]请按<回车键>,或者键入选择的编号:
# 添加 python link
$ update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
# 第一个参数: --install 表示向update-alternatives注册服务名。
# 第二个参数: 注册最终地址,成功后将会把命令在这个固定的目的地址做真实命令的软链,以后管理就是管理这个软链;
# 第三个参数: 服务名,以后管理时以它为关联依据。
# 第四个参数: 被管理的命令绝对路径。
# 第五个参数: 优先级,数字越大优先级越高。
$ update-alternatives –remove python /usr/bin/python2.7
A.4 VirtualBox UUID修改
- cd /d C:\Program Files\Oracle\VirtualBox
- VBoxManage.exe internalcommands sethduuid “D:\Program Files\zVirtualMachine\ubuntu.server_1804\ubuntu.server_1804.vdi”
- UUID changed to: 5118f355-b6dd-47ea-834f-a2707493675c
A.5 vbox压缩磁盘占用空间
虚拟机:Ubuntu
- 虚拟机中执行
- sudo dd if=/dev/zero of=/empty #时间有点久
- sudo rm -f /empty
- 关执行完成后,关闭虚拟机
- 宿主机
- cmd进入virtualbox安装目录
- VBoxManage.exe modifyhd “D:\Program Files\zVirtualMachine\ubuntu.server_1804\ubuntu.server_1804.vdi” --compact #时间有点久
- 双引号中为虚拟系统磁盘文件全路径
A.6 anaconda on win10x64
- 1 添加清华源
- 打开,Anaconda Prompt (anaconda),依次如下
- conda config --add channels https://mirrors.tuna.tsinghua.edu/anaconda/pkgs/free/
- conda config --add channels https://mirrors.tuna.tsinghua.edu/anaconda/cloud/conda-forge
- conda config --add channels https://mirrors.tuna.tsinghua.edu/anaconda/cloud/msys2/
- 设置搜索时显示通道地址
- conda config --set show_channel_urls yes
- 2 安装zmq
- 打开,Anaconda Prompt (anaconda)
- conda install -c anaconda zeromq
- 3 安装opencv
- 下载whl文件,https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
- 打开,Anaconda Prompt (anaconda)
- pip install opencv_python-4.5.5-cp39-cp39-win_amd64.whl
- 4 安装pyinstaller
- 打开,Anaconda Prompt (anaconda),依次安装如下
- pip install wheel pywin32(一般默认会安装)
- pip install --upgrade --ignore-installed setuptools
- pip install pyinstaller
- 5 安装Pyqt
- 打开,Anaconda Prompt (anaconda),依次安装如下
- pip install sip (一般默认会安装)
- python -m pip install PyQt5
- pip install PyQt5-tools
- 6 pycharm配置
- 配置Python解释器
- xxx\anaconda\python.exe
- 配置QT-Designer
- 选中 Tools -> external tools,添加
- Name:QtDesigner
- Group:Qt
- Programs: 你的Designer路径
- xxx\Anconda3\Lib\site-packages\qt5_applications\Qt\bin
- Working directory:$ProjectFileDir$
- 选中 Tools -> external tools,添加
- 配置PYUIC
- 选中 Tools -> external tools,添加
- Name:Pyuic
- Group:Qt
- Program: 你的python路径
- xxx\anaconda\python.exe
- Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
- Working directory:$FileDir$
- 选中 Tools -> external tools,添加
- 配置Python解释器
A.7 虚拟网桥
使用qemu时有时候需要启用虚拟网桥,配置脚本如下,重启失效
#!/bin/bash
#
# sudo apt install -y uml-utilities bridge-utils
# bridge-utils 虚拟网桥工具
# uml-utilities UML(User-mode linux)工具
#
# 要桥接的宿主机网卡:enp0s3
netcard=enp0s3
if [[ $1 = "on" ]]; then
#先关闭eth0接口
sudo ifconfig ${netcard} down
#创建虚拟网桥
sudo brctl addbr br0
#在br0中添加一个接口${netcard}
sudo brctl addif br0 ${netcard}
#只有一个网桥,所以关闭生成树协议
sudo brctl stp br0 off
#设置br0的转发延迟
sudo brctl setfd br0 1
#设置br0的hello时间
sudo brctl sethello br0 1
#创建一个tap0接口,只允许当前用户访问
sudo tunctl -t tap0 -u `whoami`
#在虚拟网桥中增加一个tap0接口
sudo brctl addif br0 tap0
#打开br0接口
sudo ifconfig br0 0.0.0.0 promisc up
#打开${netcard}接口
sudo ifconfig ${netcard} 0.0.0.0 promisc up
#打开tap0接口
sudo ifconfig tap0 0.0.0.0 promisc up
#从dhcp服务器获得br0的IP地址
sudo dhclient br0
#没有dhcp时,也可配置静态IP并路由
# ifconfig br0 192.168.0.133 netmask 255.255.255.0
# route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.0.254
#查看虚拟网桥列表
#sudo brctl show br0
#查看br0的各接口信息
#sudo brctl showstp br0
#ifconfig -a
else
#从虚拟网桥中删除tap0
sudo brctl delif br0 tap0
#删除tap0接口
sudo tunctl -d tap0
#从虚拟网桥中删除${netcard}
sudo brctl delif br0 ${netcard}
#关闭br0
sudo ifconfig br0 down
#删除br0
sudo brctl delbr br0
#开启${netcard}
sudo ifconfig ${netcard} up
#检测是否自动给${netcard}分配IP,若没有则自动获取
sudo dhclient -v ${netcard}
fi
–end
版权声明:本文标题:ubuntu server 18.04 first config 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728287283a1152318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论