Linux 工作环境 Config 札记

使用 Linux 作为日常开发工作环境近 5 年时间,尝试过DebianFedoraUbuntuMint等桌面发行版。虽然 Linux 作为服务器运行稳定可靠,但是在桌面 GUI 体验一直有待改进,显卡驱动兼容性与 CPU 占用率过高等问题一直悬而未决。而日常工作当中经常需要使用到的Altium DesignerKeil uVision等商业软件仅提供 Windows 10 版本,因此笔者时常需要在两款操作系统之间来回进行切换。

Linux Mint 提供了嵌入式开发当中必不可少的交叉编译环境,也能够直接安装 KiCADSTM32CubeIDEVSCodeSublime 等生产力工具;Windows 10 则提供了 Altium Designer、开发板串口驱动等大量无法跨平台使用的商业软件支持。本文主要用于备注两款操作系统当中一些常用的开发与工作环境配置,便于后续在全新工作环境中展开部署,以方便的移植个性化的使用习惯至新设备。

DEB Packages

1
sudo apt-get install nginx autoconf git goldendict terminator guake tree tmux build-essential vim p7zip wireshark filezilla kchmviewer emacs uget audacious alacarte vlc okular putty ddd fcitx-table-wbpy whois darktable unrar rar calibre vokoscreen chromium-browser inkscape gimp flameshot tilix arduino ttf-wqy-zenhei
1
sudo apt-get install libreoffice-l10n-zh-cn libreoffice-help-zh-cn thunderbird-locale-zh-cn thunderbird-locale-zh-hans firefox-locale-zh-hans language-pack-gnome-zh-hans language-pack-zh-hans
1
sudo apt-get install minicom lib32z1 lib32ncurses5 lib32stdc++6
1
sudo apt-get install audacity blender
1
sudo apt-get gcolor2 blueman

OpenSSH Server

Linux Mint 默认没有安装 SSH 服务,因此需要手动安装相应的软件包:

1
➜ sudo apt-get install openssh-server

然后执行 ps -ef|grep ssh 命令,如果出现 sshdssh-agent 两个进程,则代表 SSH 服务已经启动:

1
2
3
4
➜ ps -ef|grep ssh
root 612 1 0 17:45 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
hank 844 719 0 17:45 ? 00:00:00 /usr/bin/ssh-agent /usr/bin/im-launch cinnamon-session-cinnamon
hank 1248 1243 0 17:45 ? 00:00:00 /usr/lib/openssh/sftp-server

如果 SSH 服务未能自动启动,则需要执行 /etc/init.d/ssh start 命令手动进行启动:

1
2
3
4
5
6
7
8
➜ /etc/init.d/ssh start
Starting ssh (via systemctl): ssh.service

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'ssh.service'.
Authenticating as: hank,,, (hank)
Password:
==== AUTHENTICATION COMPLETE ===

openssh-server 的配置文件位于 /etc/ssh/sshd_config 目录,可以在这里修改 SSH 服务端口(默认端口为 22),然后执行 /etc/init.d/ssh restart 命令重启 SSH 服务:

1
2
➜ sudo /etc/init.d/ssh restart
Restarting ssh (via systemctl): ssh.service.

Qt 5

解决由于 OpenGl 依赖缺失所导致的GL/gl.h: No such file or directory问题。

1
sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev

NTFS Mount

1
2
3
4
5
6
➜ sudo apt-get install ntfs-3g

➜ sudo ntfsfix /dev/sda1
➜ sudo ntfsfix /dev/sda2
➜ sudo ntfsfix /dev/sda3
➜ sudo ntfsfix /dev/sda4

Z-Shell

1
2
3
4
5
➜ sudo apt-get install zsh

➜ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- OR -
➜ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

GIMP2 with flatpak

1
➜ flatpak install https://flathub.org/repo/appstream/org.gimp.GIMP.flatpakref

KiCad

1
2
3
4
5
Eeschema 背景颜色:255, 252, 248
Eeschema 网格颜色:240, 240, 235

PCB 背景颜色:0, 0, 0
PCB 网格颜色:77, 77, 92
1
2
3
➜ sudo add-apt-repository ppa:js-reynaud/ppa-kicad
➜ sudo aptitude update && sudo aptitude safe-upgrade
➜ sudo aptitude install kicad kicad-doc-en

VSCode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
"editor.tabSize": 2,
"editor.fontSize": 12,
"editor.fontFamily": "Source Code Pro, Consolas, Ubuntu mono",
"editor.dragAndDrop": false,
"explorer.openEditors.visible": 0,
"editor.lineHeight": 19,
"editor.wordWrap": "on",
"editor.wordWrapColumn": 1000,
"editor.minimap.enabled": true,
"material-icon-theme.showUpdateMessage": false,
"emmet.syntaxProfiles": {
"vue-html": "html",
"vue": "html"
},
"explorer.confirmDelete": false,
"beautify.tabSize": 2,
"beautify.ignore": "**/*.jsx",
"workbench.startupEditor": "newUntitledFile",
"vim.useSystemClipboard": true,
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, TabWidth: 2, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -2 }",
"breadcrumbs.enabled": false,
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"explorer.confirmDragAndDrop": false,
"window.menuBarVisibility": "toggle",
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
"javascript.updateImportsOnFileMove.enabled": "always",
"workbench.iconTheme": "material-icon-theme",
"extensions.ignoreRecommendations": true,
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"vetur.completion.scaffoldSnippetSources": {},
"vetur.format.defaultFormatter.html": "js-beautify-html", // html 不换行
"vetur.format.defaultFormatter.js": "vscode-typescript", // js 不换行
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_line_length": 0, // 设置多个字符后换行 0 表示忽略
"wrap_attributes": "auto", // html 标签属性 换行设置[auto|force|force-aligned|force-expand-multiline] ["auto"]
"end_with_newline": false // 在文件结尾添加新行
},
"prettyhtml": {
"singleQuote": false,
"wrapAttributes": false,
"sortAttributes": false
}
},
"markdown.preview.scrollEditorWithPreview": false,
"workbench.statusBar.visible": false,
"workbench.activityBar.visible": false,
"workbench.colorTheme": "Monokai",
"update.mode": "none",
"security.workspace.trust.untrustedFiles": "open",
"prettier.printWidth": 1000,
"prettier.proseWrap": "always",
}

SpaceVim

1
➜ curl -sLf https://spacevim.org/install.sh | bash

Sublime

1
2
3
4
5
➜ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
➜ sudo apt-get install apt-transport-https
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
➜ sudo apt-get update
➜ sudo apt-get install sublime-text

Peek

Peek是 GIF 格式录屏工具。

1
2
3
➜ sudo add-apt-repository ppa:peek-developers/stable
➜ sudo apt update
➜ sudo apt install peek

Openshot

1
2
3
➜ sudo add-apt-repository ppa:openshot.developers/ppa
➜ sudo apt-get update
➜ sudo apt-get install openshot-qt

Notepadqq

1
2
3
➜ sudo add-apt-repository ppa:notepadqq-team/notepadqq
➜ sudo apt-get update
➜ sudo apt-get install notepadqq

Adobe Flash

1
➜ sudo apt-get install flashplugin-installer

Root Password

1
➜ sudo passwd root

USB Support for Virtualbox

1
➜ sudo adduser hank vboxusers

Ubuntu Color

1
2
Ubuntu [灰]   #42413C
Stardict [黄] #f0e8c9

Environment Variable

1
➜ sudo vim /etc/profile
1
2
export PATH=$PATH:/opt/jdk/bin:/opt/nodejs/bin:/opt/mongodb/bin:/opt/go/bin
export JAVA_HOME=/opt/jdk/
1
source /etc/profile

SSH key

(1)查看本地公钥是否存在:

1
cat ~/.ssh/id_rsa.pub

(2)生成公钥,该指令会要求提供公钥的保存位置和文件名,可以敲【Enter】键使用默认值:

1
➜ ssh-keygen -t rsa -C "uinika@outlook.com"

(3)查看默认生成的公钥:

1
cat ~/.ssh/id_rsa.pub

Stardict imports dictionaries

1
➜ sudo cp -a * /usr/share/stardict/dic

.gitconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[user]
name = hank.zheng
email = uinika@outlook.com
[core]
editor = vim
autocrlf = false
quotepath = false
ignorecase = false
[alias]
st = status
cm = commit
df = diff
br = branch
ps = push
pl = pull
lg = log
ad = add
cl = clone
mg = merge
sh = show
rs = reset
tg = tag
hp = help
bd = bundle
sb = submodule
sts = stash
apl = apply
stg = stage
rmt = remote
cko = checkout
[init]
defaultBranch = main
[push]
default = matching
[credential]
helper = store
[branch]
autosetuprebase = always
[http]
sslVerify = false

Nginx

1
➜ sudo vim /etc/nginx/nginx.conf
1
include /home/hank/nginx.conf

nginx.conf for Linux

1
2
3
4
5
6
7
8
9
10
11
12
server {
listen 1985;
root /opt/manual/angular;
}
server {
listen 1986;
root /opt/manual/es6-tutorial;
}
server {
listen 1987;
root /opt/manual/vuejs;
}

nginx.conf for Windows

1
2
3
4
5
6
7
8
9
10
11
12
server {
listen 1985;
root D:\manual\angular;
}
server {
listen 1986;
root D:\manual\es6-tutorial;
}
server {
listen 1987;
root D:\manual\vuejs;
}

Fonts Installation

Source Code Pro是 Adobe 提供的开源等宽字体。

1
2
3
4
5
6
7
➜ sudo mkdir /usr/share/fonts/ms_fonts
➜ sudo cp *.ttf /usr/share/fonts/ms_fonts
➜ sudo chmod 644 /usr/share/fonts/ms_fonts/*
cd /usr/share/fonts/ms_fonts/
➜ sudo mkfontscale
➜ sudo mkfontdir
➜ sudo fc-cache -fv

Remove libreoffice

1
➜ sudo apt remove libreoffice-calc libreoffice-draw libreoffice-impress libreoffice-writer

Fcitx bug fix

(1)移除多余字体。

1
➜ sudo apt-get remove fonts-arphic-ukai fonts-arphic-uming

(2)移除冗余的 Fcitx 可视化配置面板(Ubuntu 18.04 和 Mint 19 可以不执行此步骤)。

1
➜ sudo apt-get remove fcitx-ui-qimpanel

Maintain RTC

  • 0 -- Maintain RTC in universal time.
  • 1 -- Maintain RTC in local time.
1
➜ timedatectl set-local-rtc 1

MySQL 8.0 config

解压后在目录新建一个my.ini文件,并根据 MySQL 安装目录填写如下内容:

1
2
3
4
[mysqld]
basedir=C:\\Software\\Tech\\MySQL
datadir=C:\\Software\\Tech\\MySQL\\data
port = 3306

更多选项请直接查阅 MySQL 提供的官方文档《mysqld option tables》

注册 Windows 服务并生成 data 目录下的相关配置文件:

1
2
3
4
5
mysqld --initialize --console

2018-12-21T09:25:27.423145Z 0 [System] [MY-013169] [Server] C:\Software\Tech\MySQL\bin\mysqld.exe (mysqld 8.0.13) initializing of server in progress as process 9504
2018-12-21T09:25:32.190145Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 1qVHfp#+i5kk
2018-12-21T09:25:35.500145Z 0 [System] [MY-013170] [Server] C:\Software\Tech\MySQL\bin\mysqld.exe (mysqld 8.0.13) initializing of server has completed

安装 MySQL 后台服务:

1
2
λ mysqld install
Service successfully installed.

使用上一步获取的 root 随机密码连接至 MySQL 数据库:

1
2
λ mysql -u root -p
Enter password: 【输入上一步操作所获取的root随机密码】

登入数据库后修改日常开发所用的 MySQL 数据库密码:

1
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

移除 MySQL 服务:

1
λ mysqld remove

Intel Backlight

针对部分 Intel 笔记本电脑背光调节快捷键失效的问题,编辑下面文件中的内容为400,即可完成屏幕背光亮度的手动设置:

1
➜ sudo vim /sys/class/backlight/intel_backlight/brightness

Add admin

添加管理员用户 hank

1
2
sudo adduser hank
sudo adduser hank sudo

切换到刚才新建的管理员用户 hank

1
su hank

Nginx & Git for ECS

安装 Git 和 Nginx

启动 ECS 云服务器之后,初始化 root 密码,并在权限组打开 80 端口,并在进入系统之后更新与升级依赖包:

1
2
sudo apt update
sudo apt upgrade

安装 nginxgit 及其相关的依赖包:

1
sudo apt install nginx git

配置 Nginx

/opt 根目录下建立 blog 文件夹用于放置 Web 页面:

1
sudo mkdir /opt/blog

备份 Nginx 的配置文件到 /opt 目录下面:

1
sudo cp /etc/nginx/sites-available/default /opt

编辑 Nginx 的默认配置文件 default,将 80 端口映射的服务目录指向 /opt/blog

1
sudo vim /etc/nginx/sites-available/default

让 Nginx 重新加载修改之后的配置文件,使其能够立刻生效:

1
sudo nginx -s reload

配置 Git 服务

添加用于操作 Git 任务的 git 用户,并且设置其密码:

1
2
adduser git
passwd git

切换至 git 用户,然后初始化 SSH 公钥,并且赋予正确的权限:

1
2
3
4
5
6
7
su git
cd /home
mkdir -p /home/git/.ssh
touch /home/git/.ssh/authorized_keys
chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys
chown -R git:git /home/git/.ssh/authorized_keys

上传本地计算机上生成的 id_rsa.pub 公钥,然后将其内容复制给 authorized_keys,免去部署时反复输入 git 密码的繁琐:

1
cat id_rsa.pub >> /home/git/.ssh/authorized_keys

初始化 /srv/git,并且将 git 用户设置为 /srv/git 目录的拥有者:

1
2
3
mkdir -p /srv/git
git init --bare /srv/git/blog.git
chown -R git:git /srv/git

初始化用于存放 Nginx 访问静态资源的 Web 目录,同时也将 git 用户设置为 /opt/blog 的拥有者:

1
2
3
cd /opt
git clone git@127.0.0.1:/srv/git/blog.git
chown -R git:git /opt/blog

配置 Git Hooks

首先,通过修改 post-receive 文件,添加 Git 自动更新钩子:

1
vim /srv/git/blog.git/hooks/post-receive

然后,上述 post-receive 源文件的具体内容如下面所示:

1
2
3
4
5
6
7
#!/bin/bash

WebDIR=/opt/blog
GitDIR=/srv/git/blog.git

git --work-tree=${WebDIR} clean -fd
git --work-tree=${WebDIR} --git-dir=${GitDIR} checkout --force

注意,必须确保 /opt/blog 目录的所有者为 git 用户,否则将会导致钩子触发失败:

1
sudo chown -R git:git /opt/blog

最后,为用户 git 添加钩子文件的可执行权限:

1
chmod +x /srv/git/blog.git/hooks/post-receive

配置 Hexo

最后,添加如下设置项到 Hexo 的 _config.yml 配置文件:

1
2
3
4
deploy:
- type: git
repo: git@47.100.4.172:/srv/git/blog.git
branch: master