PC系统配置

这篇文章主要是关于自己ArchLinux系统的配置的。

# 1 硬件配置

# 1.1 网络

# 1.1.1 旧方法(被抛弃)

pacman -S iw wpa_supplicant
systemctl start systemd-networkd.service
systemctl start systemd-resolved.service
systemctl start wpa_supplicant@wlp3s0.service
systemctl enable systemd-networkd.service
systemctl enable systemd-resolved.service
systemctl enable wpa_supplicant@wlp3s0.service
rm /etc/resolv.conf
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
pacman -S systemd-resolvconf

编辑/etc/systemd/network/20-wired.network

[Match]
Name=enp4s0f1

[Network]
DHCP=yes

[DHCP]
RouteMetric=10

编辑/etc/systemd/network/25-wireless.network

[Match]
Name=wlp3s0

[Network]
DHCP=ipv4

[DHCP]
RouteMetric=20

注意备份/etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf或者创建:

ctrl_interface=/run/wpa_supplicant
ctrl_interface_group=wheel
update_config=1

图形界面。

sudo yay -S wpa_supplicant_gui

# 1.1.2 新方法

sudo pacman -S networkmanager network-manager-applet
sudo systemctl start NetworkManager.service
sudo systemctl enable NetworkManager.service

# 1.2 显卡

解开/etc/pacman.confmultilib的注释。

pacman -S bumblebee mesa nvidia xf86-video-intel lib32-virtualgl lib32-nvidia-utils bbswitch

为了解决bumblebee无法在睡眠之后启动显卡,修改/etc/bumblebee/bumblebee.conf。只有重启才能生效。

[driver-nvidia]
PMMethod=bbswitch

 ...

[driver-nouveau]
PMMethod=bbswitch
gpasswd -a sun bumblebee
systemctl start bumblebeed.service
systemctl enable bumblebeed.service

# 1.3 触摸板

似乎xf86-input-synaptics已经自动安装了。

# 1.4 声卡

sudo pacman -S alsa-utils pulseaudio pulseaudio-bluetooth

图形界面使用pavucontrol

sudo pacman -S pavucontrol

消除奇怪的主板beep声。编辑/etc/modprobe.d/nobeep.conf

blacklist pcspkr

为解决休眠之后没有声音。编辑/etc/default/grub

...
GRUB_CMDLINE_LINUX_DEFAULT="quiet acpi_enforce_resources=lax"
...
sudo yay -S init-headphone
sudo systemctl enable init-headphone.service
sudo grub-mkconfig -o /boot/grub/grub.cfg

# 1.5 蓝牙

sudo pacman -S bluez bluez-utils
sudo systemctl start bluetooth.service
sudo systemctl enable bluetooth.service

图形界面使用blueman

sudo pacman -S blueman

为了消除登录时蓝牙请求权限,创建/etc/polkit-1/rules.d/81-blueman.rules

polkit.addRule(function(action, subject) {
  if (action.id == "org.blueman.rfkill.setstate" && subject.local && subject.active && subject.isInGroup("wheel")) {
      return polkit.Result.YES;
  }
  if (action.id == "org.blueman.network.setup" && subject.local && subject.active && subject.isInGroup("wheel")) {
      return polkit.Result.YES;
  }
});

# 1.6 CPU

消除TSC_DEADLINE disabled due to Errata的错误:

sudo pacman -S intel-ucode
sudo grub-mkconfig -o /boot/grub/grub.cfg

# 2 非图形界面

# 2.1 用户管理

添加自己并取消root登录:

useradd -m -G wheel -s /bin/zsh sun
passwd sun
passwd -l root

修改/etc/sudoers,解除wheel的注释。

# 2.2 引导程序

注意os-prober检测Windows需要ntfs-3g

sudo pacman -S os-prober

添加脚本使GRUB隐藏除非Shift键摁下。首先添加下面的到/etc/default/grub

GRUB_FORCE_HIDDEN_MENU="true"

然后下载文件/etc/grub.d/31_hold_shift,执行下面:

chmod a+x /etc/grub.d/31_hold_shift

添加脚本使GRUB按住Ctrl才进入Linux否则进入Windows。首先修改/etc/default/grub中的默认启动项:

GRUB_DEFAULT=2

然后编辑/etc/grub.d/32_hold_ctrl

! /bin/sh
set -e

cat <<EOF
if keystatus; then
  if keystatus --ctrl; then
    set default=0
  fi
fi
EOF
chmod a+x /etc/grub.d/32_hold_ctrl
grub-mkconfig -o /boot/grub/grub.cfg

# 2.3 源

添加源。编辑/etc/pacman.conf

[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch

[arch4edu]
SigLevel = Never
Server = http://mirrors.tuna.tsinghua.edu.cn/arch4edu/$arch
sudo pacman -S archlinuxcn-keyring

# 2.4 开发工具

sudo pacman -S openssh git gcc gdb cmake make python2 python python2-pip python-pip nodejs npm

备份私钥,或者通过ssh-keygen生成。

配置git:

git config --global user.name "Sun Ziping"
git config --global user.email sunziping2016@gmail.com

安装cnpm:

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

# 2.5 常用软件

sudo pacman -S bash-completion zsh htop tree vim wget gpm w3m tmux ntfs-3g udisks2
sudo systemctl start gpm
sudo systemctl enable gpm

# 2.6 zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sudo pacman -S zsh-syntax-highlighting

编辑自己喜爱的主题~/.oh-my-zsh/themes/my-theme.zsh-theme

PROMPT='%B%F{red}%(?..%? )%F{blue}%n%f%b@%m %B%~%b $(git_prompt_info)%# '

ZSH_THEME_GIT_PROMPT_PREFIX="%B%F{blue}(%F{red}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%f%b"
ZSH_THEME_GIT_PROMPT_DIRTY="%F{yellow}*%F{blue})"
ZSH_THEME_GIT_PROMPT_CLEAN="%F{blue})"

# 2.7 动态DNS(暂时未配置)

首先配置DDNS。注意保存配置文件。

wget http://download.oray.com/peanuthull/phddns-2.0.2.16556.tar.gz
tar zxvf phddns-2.0.2.16556.tar.gz
cd phddns-2.0.2.16556
aclocal
autoconf
automake --add-missing
./configure
make
sudo mv src/phddns /usr/local/bin

添加/etc/systemd/system/phddns.service

[Unit]
Description=phddns service
After=syslog.target network.target

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/usr/local/bin/phddns -c /etc/phlinux.conf -d
ExecReload=/usr/bin/kill -HUP $MAINPID
KillSignal=SIGQUIT
KillMode=mixed

[Install]
WantedBy=multi-user.target

# 2.8 翻墙(暂时未配置)

注意备份shadowsocks配置文件。

sudo pacman -S shadowsocks-libev proxychains-ng
sudo systemctl start shadowsocks-libev@tencent.service
sudo systemctl start shadowsocks-libev-redir@tencent-redir.service
sudo systemctl start shadowsocks-libev-tunnel@tencent-tunnel.service
sudo systemctl enable shadowsocks-libev@tencent.service
sudo systemctl enable shadowsocks-libev-redir@tencent-redir.service
sudo systemctl enable shadowsocks-libev-tunnel@tencent-tunnel.service

配置iptables、ipset。

sudo pacman -S ipset
sudo ipset -N gfwlist iphash
sudo iptables -t nat -A OUTPUT -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1080
sudo systemctl start iptables.service
sudo systemctl start ipset.service
sudo systemctl enable iptables.service
sudo systemctl enable ipset.service

配置dnsmasq和systemd-resolved。

sudo pacman -S dnsmasq

编辑/etc/systemd/resolved.conf

[Resolve]
...
DNS=127.0.0.1
Cache=no
DNSStubListener=no

编辑/etc/dnsmasq.conf

listen-address=127.0.0.1
conf-dir=/etc/dnsmasq.d

创建gfwlist。

cd /usr/local/bin
sudo wget https://raw.githubusercontent.com/cokebar/gfwlist2dnsmasq/master/gfwlist2dnsmasq.sh
sudo mv gfwlist2dnsmasq.sh gfwlist2dnsmasq
sudo gfwlist2dnsmasq -s gfwlist -o /etc/dnsmasq.d/dnsmasq_list.conf -s gfwlist -p 5353

启动dnsmasq。

sudo systemctl start dnsmasq.service
sudo systemctl enable dnsmasq.service
sudo systemctl restart systemd-resolved.service

注意应当时常更新下列命令。

sudo gfwlist2dnsmasq -s gfwlist -o /etc/dnsmasq.d/dnsmasq_list.conf -s gfwlist -p 5353
sudo sh -c "ipset save > /etc/ipset.conf"

# 2.9 LNMP

安装Nginx。

sudo pacman -S nginx-mainline
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Nginx#Configure example的内容拷贝到/etc/nginx/nginx.conf

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled

安装MariaDB。

sudo pacman -S mariadb
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo mysql_secure_installation

安装PHP。

sudo pacman -S php php-fpm
sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service

编辑/etc/php/php.ini

[php]
...
date.timezone = Asia/Shanghai
...
extension=bz2
extension=mysqli
extension=pdo_mysql

安装phpMyAdmin。

sudo pacman -S phpmyadmin

编辑/etc/nginx/sites-available/pma.conf,参照phpMyAdmin#Nginx。最后激活文件。

sudo ln -s /etc/nginx/sites-available/pma.conf /etc/nginx/sites-enabled/pma.conf
sudo systemctl reload nginx.service

编辑/etc/webapps/phpmyadmin/config.inc.php

...
$cfg['blowfish_secret'] = '...';
...
$cfg['TempDir'] = '/tmp/phpmyadmin';

# 2.10 MongoDB和Redis

安装MongoDB和Redis。

sudo pacman -S mongodb redis
sudo systemctl start mongodb.service redis.service
sudo systemctl enable mongodb.service redis.service

在终端输入mongo进入MongoDB命令行。

use admin
db.createUser(
  {
    user: "sun",
    pwd: "xxxxxxxx",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)

修改/etc/mongodb.conf,并重启MongoDB服务:

...
security:
  authorization: "enabled"
...

安装MongoDB Compass。

yay -S mongodb-compass

# 3 图形界面

# 3.1 安装Display Manager

sudo pacman -S lightdm lightdm-gtk-greeter

/etc/lightdm/lightdm.conf添加greeter。

[Seat:*]
...
greeter-session=lightdm-gtk-greeter

注意备份头像和壁纸。在/etc/lightdm/lightdm-gtk-greeter.conf中修改Indicators。

[greeter]
indicators=~host;~spacer;~clock;~spacer;~session;~language;~a11y;~power

安装用户服务,更改头像。

sudo pacman -S accountsservice

创建/var/lib/AccountsService/users/sun

[User]
Icon=/var/lib/AccountsService/icons/sun.png

最后创建用户文件/usr/local/bin/gdmflexiserver

!/bin/sh
/bin/dm-tool switch-to-greeter
sudo chmod +x /usr/local/bin/gdmflexiserver

# 3.2 安装xfce4

sudo pacman -S xfce4 xfce4-goodies
sudo systemctl start lightdm.service
sudo systemctl enable lightdm.service

创建/etc/profile.d/qt.sh

export QT_AUTO_SCREEN_SCALE_FACTOR=0

# 3.3 字体

注意备份windows-fonts包。同时安装monaco字体作为终端字体。

sudo pacman -S ttf-monaco

编辑~/.config/fontconfig/fonts.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <alias>
    <family>serif</family>
    <prefer>
      <family>Times New Roman</family>
      <family>SimSun</family>
    </prefer>
  </alias>
  <alias>
    <family>sans-serif</family>
    <prefer>
      <family>Arial</family>
      <family>SimHei</family>
    </prefer>
  </alias>
  <alias>
    <family>monospace</family>
    <prefer>
      <family>Monaco</family>
      <family>SimSun</family>
    </prefer>
  </alias>
</fontconfig>

# 3.4 添加gvfs支持

sudo pacman -S gvfs gvfs-mtp gvfs-smb gvfs-afc

# 3.5 输入法

sudo pacman -S fcitx fcitx-im fcitx-sogoupinyin fcitx-configtool zenity

~/.xprofile里面添加如下内容。

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

# 3.6 VirtualBox

sudo pacman -S virtualbox virtualbox-ext-oracle virtualbox-guest-iso
sudo gpasswd -a sun disk
VBoxManage internalcommands createrawvmdk -filename ~/VirtualBox\ VMs/Windows\ 10/sda.vmdk -rawdisk /dev/sda
VBoxManage internalcommands createrawvmdk -filename ~/VirtualBox\ VMs/Windows\ 10/sdb.vmdk -rawdisk /dev/sdb
sudo gpasswd -a sun vboxusers

然后添加一个拥有上面两个虚拟磁盘的虚拟机。

# 4 软件列表

# 4.1 Pacman安装的软件

xorg-kill chromium gimp inkscape vlc seafile-client wps-office ttf-wps-fonts
geogebra jdk intellij-idea-ultimate-edition clion unzip-iconv zip boost nvm
wine wine-mono wine_gecko clang rtorrent p7zip unrar texlive-most texlive-lang
texlive-langextra maxima wxmaxima rsync visual-studio-code-bin telegram-desktop
celestia wesnoth qt5-base qt5-multimedia yay valgrind
2016-2020 Ziping Sun
京ICP备 17062397号