ubuntu server 18.04 first config

ubuntu server 18.04 first config


Note info

  • Update aliyun source
    • http://mirrors.aliyun.com/ubuntu/
  • After installing the environment on vmware, the virtual machine cannot copy and paste with the host machine, and the following methods can be used to solve the problem
    • vmware version :pro 14.1.8 build-14921873
    • sudo apt-get install -y open-vm-tools-desktop
  • vim .config/i3/config, enter as follows
    • exec --no-startup-id vmware-user
  • Automatic window size, can be solved by installing vmtools
  • Restart the Ubuntu server network
    • sudo systemctl restart systemd-networkd.service
  • Solve the permission problem of virtual box shared folder
    • sudo usermod -aG vboxsf $(whoami)
    • That is to add the current user to the vboxsf user group, because the owner group of the shared directory is vboxsf.
    • After executing this command, you need to restart the system to take effect, or you can restart after executing all configurations.
  • If vim needs 自动补全the plug-in coc-nvin, vim8.2 and above need to be installed
    • sudo add-apt-repository ppa:jonathonf/vim
    • sudo apt-get update
    • sudo apt-get install -y vim vim-gtk3 vim-gui-common
    • This demo does not need this plug-in, the code is written using vscode, but vscode takes up too much memory

oneClick

  • Install 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-his 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

    • Choose lightdm, because Lightdm is the default in Ubuntu
    • You can also re-select sudo dpkg-reconfigure lightdm
  • sudo apt-get -y remove gnome-*

    • sudo apt-get install -y nautilus
    • sudo apt autoremove -y
    • Note: Prevent gnome from logging into the desktop when nautilus is installed on Ubuntu server 20.04
  • commonly used

    • feh is used to configure wallpapers and view pictures

    • alsamixergui with pavucontrol to control the sound

    • For the use of i3wm, see "A.2 Commonly used shortcut keys for i3wm"

    • After restarting, configure the time zone

      • sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
      • sudo hwclock --systohc
    • Turn off auto sleep

      • systemctl status sleep.target to see if it is sleeping
      • sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target turn off hibernation
    • Configure the screen

      • xset q         #查看当前屏保设置
        xset s 5       #5秒后黑屏
        xset s off     #关闭黑屏
        xset dpms 5    #5秒后关闭显示器
        xset -dpms     #取消自动关闭显示器
        xset b off/on  #关闭或开启黑屏提示音
        
    • The configuration file is $HOME/.config/i3/config

      • exec --no-startup-id xset s 0 turn off screen saver
      • exec --no-startup-id xset dpms 6000 8000 9000 Set the black screen, sleep, and power-off times to 6000s, 8000s, and 9000s respectively, or you can write 0 for both, indicating that the time is permanent

I googled it

  • sudo apt-get install -y fcitx-googlepinyin
    • Switch the input mode to fcitx, use the im-config command to realize graphical operation, and then restart the computer
    • Then open fcitx-configtool graphically to add googlepinyin input method
    • Restart after installing the Chinese language pack: sudo apt-get install language-pack-zh-hans
    • Restart after installing Chinese fonts: sudo apt install fonts-wqy-microhei fonts-wqy-zenhei xfonts-intl-chinese

ssh

  • install ssh service
    • sudo apt-get install -y openssh-server
  • start up
    • sudo /etc/init.d/ssh start
  • turn off firewall
    • sudo ufw disable
  • Check, if successful, the connection is passed
    • ssh localhost
  • git config
    • git config --global user.name xxx
    • git config --global user.email [email protected]
    • git config --global core.editor vim
  • ssh-keygen -t rsa -C [email protected]

samba

Installation: sudo apt-get install -y samba smbclient cifs-utils
Configuration: Open the configuration file smb.conf, sudo vim /etc/samba/smb.conf, enter the following

#本机配置
security = user

[aldrich]
   path = /home/aldrich
   browseable = yes
   public = no
   writable = yes
   valid users = aldrich

reboot

  • sudo smbpasswd -a aldrich #Set password for samba user
  • sudo service smbd restart
    • Alternatively, sudo /etc/init.d/smbd restart

example

  • sudo mount.cifs -o user=aldrich //10.106.xx.xx/aldrich /mnt
    • mount, mapping another samba under Ubuntu to the local

tftp

Install: sudo apt-get install -y tftp-hpa tftpd-hpa

  • tftp-hpa is the client,
  • tftpd-hpa is the server side

Create a directory:

  • mkdir -p ~/tftproot
  • chmod 777 ~/tftproot

Configuration: sudo vim /etc/default/tftpd-hpa

  • TFTP_USERNAME="tftp"
    TFTP_DIRECTORY="/home/aldrich/tftproot"
    TFTP_ADDRESS=":69"
    TFTP_OPTIONS="-l -c -s"
    

Restart: sudo service tftpd-hpa restart

  • systemctl status tftpd-hpa.service #View status
  • systemctl start tftpd-hpa.service #Start

Test: You can test whether tftp is normal through the following methods

  • $ 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

Install

  • sudo apt-get install -y nfs-kernel-server nfs-common

Configuration: sudo vim /etc/exports

  • $ cat /etc/exports
    /home/aldrich *(rw,sync,no_root_squash,no_subtree_check)
    #直接使用根目录做nfs具有很高的灵活性
    

Create a directory and create a file:

  • mkdir -p /home/aldrich/devnet/nfs;
  • touch /home/aldrich/devnet/nfs/a.txt

Restart the nfs service:

  • sudo service nfs-kernel-server restart

Test whether the nfs service is normal

  • sudo mount -t nfs -o nolock 127.0.0.1:/home/aldrich/devnet/nfs /opt
  • sudo umount /opt

flash

firefox web video requires flash plug-in

  • sudo apt-get install -y ubuntu-restricted-extras flashplugin-installer vlc

chipboard

Install

  • 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

Edit: iverilog -o wave led_demo_tb.v led_demo.v

  • If multiple .v modules are called, you can specify the path of the source file through the -y parameter, otherwise an error will be reported when compiling. If the source files are all in the same directory, they can be specified directly by ./absolute path.

Generate wave file: vvp -n wave -lxt2 # Generate vcd wave file

Open wave file: gtkwave wave.vcd

make.sh batch processing, one-click execution

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 install

    • sudo python3 -m pip install --upgrade pip setupTools -i https://pypi.tuna.tsinghua.edu.cn/simple
    • sudo pip3 install --upgrade pyinstaller numpy pandas sciPy scikit-Learn matplotlib keras scrapy gensim pyzmq flask -i https://pypi.tuna.tsinghua.edu.cn/simple
    • Serial related: sudo pip3 install --upgrade psutil xmodem pyprind pyftdi -i https://pypi.tuna.tsinghua.edu.cn/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.cn/simple
  • plug-in illustrate
    numpy Provide array support and corresponding efficient processing functions
    pandas Powerful, flexible data analysis and exploration tools
    sciPy Provide matrix support and matrix-related numerical calculation modules
    matplotlib Powerful data visualization tools and graphing libraries
    scikit-Learn Supports powerful machine learning libraries such as regression, classification, and clustering
    hard Deep learning library for building neural networks and deep learning models
    as a nation A library for text topic modeling, possibly useful for text mining

vimplug

  • cscope
    • autoload_cscope.vim, automatically load the cscope library
  • ctags
    • vim-gutentags, automatically generate tags
  • DoxygenToolKit
  • taglist
  • mark.vim
    • Depends on vim-ingo-library
  • bufexploer
  • quickfix(build-in)
  • insearch
  • NerdComment
  • nerdtree
  • lightline
  • leaderf
  • coc.nvim
    • Upgrade 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: use the master branch, otherwise yarn build will fail due to package.json
    • Install coc.nvim (master)
      • curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
      • sudo apt-get install -y nodejs
      • sudo npm install -g yarn
      • yarn install
      • yarn build
      • Excuting an order
        • c/c++ completion: CocInstall coc-clangd
          • sudo apt install clang-10 install C/C++ Language Server
        • Python completion: CocInstall coc-pyright
        • Java completion: CocInstall coc-java
      • Execute: CocInstall coc-snippets install code snippets
        • Collection of snippets, honza/vim-snippets
      • Existing non-LSP plugins
        • coc-emmet provides emmet autocompletion support.
        • coc-highlight provides current word and color highlighting support.
        • coc-lists provides common list support.
        • coc-pairs provides automatic pairing support.
        • coc-snippets provides code block solutions.
        • coc-yank provides yank highlighting and history listings.
        • coc-git provides support for git chunks, status, lists, etc.

address

  • https://github.com/tianzong2019/myvimrc
  • https://gitee.com/tianzong2019/myvimrc

cut zsh

  • There is a freeze in the process of using it under the virtual machine. . .
  • sudo apt install -y zsh
  • sh -c “$(curl -fsSL https://raw.fastgit.org/robbyrussell/oh-my-zsh/master/tools/install.sh)”
  • git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  • configuration, ~/.zshrc
    • plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
    • switch theme
      • ZSH_THEME=“eastwood”
      • ZSH_THEME=“gallois”

appendix

A.1 Commonly used shortcut keys for i3wm

Path to i3wm configuration file: $HOME/.config/i3/config

  • Set the windows key as the mod key. In i3wm, the default Mod1 is Alt, and Mod4 is the windows key. If you want the windows key to be the mod key, you can add a sentence before the configuration file: set $mod Mod4.

  • The file manager command that comes with Ubuntu is: nautilus; if you use the command to open it directly, it will be opened with the desktop, which is not friendly and inconvenient to use. The command to open without the desktop is: nautilus --no- desktop

  • hot key describe
    $mod + D Start dmenu, which is the command input box, where you can enter the name of the software to be opened
    $mod + Enter Create a new Terimal
    $mod + F window full screen
    $mode + NUM Jump to workspace NUM, i3 has 10 workspaces, corresponding to 1~9,0
    $mod + H The next time a new window is created, split the window horizontally
    $mod + V The next time a new window is created, split the window vertically
    $mod + S Make windows appear in a stacked layout
    $mod + W Make the window appear in a tabbed layout
    $mod + E Make the window appear in the default layout, which is a tiled layout
    $mod + Shift + Q close current window
    $mod + Shift + E quit i3
    $mod + Shift + C Reload i3config on the spot, no reboot required
    $mod + Shift + R Restarted i3 (also reloaded i3config, without exiting the process)
    $mod + J Move the focus to the left window, or use the arrow keys to move up, down, left, and right
    $mod + K focus down window
    $mod + L focus up window
    $mod + ; Move focus to right window
    $mod + Shift + J window left
    $mod + Shift + K window down
    $mod + Shift + L window up
    $mod + Shift + : window right
    $MOD + R When there are multiple windows, adjust the window size
    $MOD + T New window with tab bar
    $MOD + Y New window with border
    $MOD + U Create a new window with no tab bar and no border
    window size The window border can be dragged with the mouse to change the window size

A.2 Adjust python priority

Adjust the python priority. Under ubuntu16.04, there will be python3.5 and python3.6 at the same time, so that the python version 3.6 has a higher priority. The following operations can be performed

  • Install
    • 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.cn/anaconda/pkgs/free/
    • conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    • conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/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$
    • 配置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$

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

Guess you like

Origin blog.csdn.net/tianzong2019/article/details/122971583