ubuntu os

记录ubuntu的安装过程。

安装操作系统

https://ubuntu.com/download/desktop

优化apt

登录时使用Ubuntu on X11 Org,否则Theme不能切换。因为Gnome Wayland不成熟。

Recommend: Software & Update->Download from->Other去选择aliyun镜像。如果手动的话参考以下方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list

#Adding he following lists
#For ubuntu 22.04
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb http://mirrors.aliyun.com/ubuntu/ jammy multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-security multiverse

Update:

1
2
3
4
5
sudo apt update
#apt
sudo add-apt-repository ppa:apt/stable
sudo apt install apt-fast
sudo apt upgrade

安装基础包

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
#sudo apt install software-properties-common
#sudo apt install aria2


sudo apt install vim unrar gdebi curl screen keepassxc git
#sudo apt install vlc

#Installing chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

#Installing albert
#wget https://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_20.04/amd64/albert_0.17.2-0_amd64.deb
wget https://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_22.04/amd64/albert_0.17.3-0_amd64.deb
sudo dpkg -i albert_0.17.3-0_amd64.deb

#添加application菜单
sudo apt-get install alacarte
#serch mainmenu就可以

#mount NTFS
sudo apt install ntfs-3g
#Get UUID
ls -l /dev/disk/by-uuid
sudo vim /etc/fstab
UUID=409AB21C9AB20F02 /data1 ntfs-3g rw 0 0
UUID=5E98B57C98B552EF /data2 ntfs-3g rw 0 0

修改操作系统配置

完整脚本:

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
73
apt-get update
#apt-get install make g++ init inetutils-ping sudo jq iproute2 net-tools wget htop vim screen curl lsof lrzsz zip unzip expect openssh-server -y
apt-get install init inetutils-ping sudo iptables psmisc jq iproute2 net-tools wget htop vim screen curl lsof lrzsz zip unzip expect openssh-server -y

#LANG="en_US.UTF-8"
#sed -i 's;LANG=.*;LANG="zh_CN.UTF-8";' /etc/locale.conf


systemctl disable iptables
systemctl stop iptables
systemctl disable firewalld
systemctl stop firewalld

#ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-timezone Asia/Shanghai

#logined limit
cat /etc/security/limits.conf|grep "^root" > /dev/null
if [[ $? != 0 ]]; then
cat >> /etc/security/limits.conf << EOF
root - nofile 100000
root - nproc 100000
* - nofile 100000
* - nproc 100000
EOF
fi

#systemd service limit
cat /etc/systemd/system.conf|egrep '^DefaultLimitNOFILE' > /dev/null
if [[ $? != 0 ]]; then
cat >> /etc/systemd/system.conf << EOF
DefaultLimitCORE=infinity
DefaultLimitNOFILE=100000
DefaultLimitNPROC=100000
EOF
fi
#user service limit
cat /etc/systemd/user.conf|egrep '^DefaultLimitNOFILE' > /dev/null
if [[ $? != 0 ]]; then
cat >> /etc/systemd/system.conf << EOF
DefaultLimitCORE=infinity
DefaultLimitNOFILE=100000
DefaultLimitNPROC=100000
EOF
fi

cat /etc/sysctl.conf|grep "net.ipv4.ip_local_port_range" > /dev/null
if [[ $? != 0 ]]; then
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 500
net.ipv4.ip_forward = 1
fs.inotify.max_user_instances=1280
fs.inotify.max_user_watches=655360
vm.overcommit_memory=1
fs.protected_regular=0
EOF
sysctl -p
fi

su - root -c "ulimit -a"

echo "140.82.112.4 github.com
185.199.110.133 raw.githubusercontent.com" >> /etc/hosts

sed -i 's;#PermitRootLogin.*;PermitRootLogin yes;g' /etc/ssh/sshd_config
systemctl enable ssh
systemctl restart ssh

Safe-RM

Safe-RM.zip

rm.sh:

1
2
3
4
5
6
7
8
9
10
11
12
sudo mkdir -p /works/shell /works/backup
sudo chown -R dave.dave /works/
chmod +x /works/shell/*


#https://superuser.com/questions/192725/how-can-i-alias-a-command-for-sudo
cat >> /etc/profile <<EOF
alias sudo='sudo '
alias rm="/works/shell/rm.sh"
EOF

. /etc/profile

GIT

1
2
3
4
5
6
7
8
9
git config --global user.name "dave.zhao"
git config --global user.email dave.zhao@zerofinance.com
git config --global core.autocrlf false
git config --global core.safecrlf warn
git config --global core.filemode false
git config --global core.whitespace cr-at-eol
git config --global credential.helper store
#由于 Windows 版本的 Git 是使用 msys 编译的,它使用了旧版本的 Windows Api,限制文件名不能超过 260 个字符
git config --global core.longpaths true

配置环境变量

vim ~/.bash_profile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

alias ll="ls -l"
alias k=kubectl
source <(kubectl completion bash | sed s/kubectl/k/g)

function proxy_off(){
unset http_proxy
unset https_proxy
echo -e "The proxy has been closed!"
}
function proxy_on() {
export no_proxy="127.0.0.1,localhost,10.0.0.0/8,172.0.0.0/8,192.168.0.0/16,*.zerofinance.net,*.aliyun.com,*.163.com,*.docker-cn.com,registry.gcalls.cn"
export http_proxy="http://127.0.0.1:1082"
export https_proxy=$http_proxy
echo -e "The proxy has been opened!"
}

source ~/.bash_profile

rc.local

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
#http://www.atmcu.com/2256.html
#rc-local.service
cat > /etc/systemd/system/rc-local.service << EOF
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
EOF

#rc.local
cat > /etc/rc.local <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0
EOF

#systemctl
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

搜狗输入法 for linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#https://shurufa.sogou.com/linux
#https://shurufa.sogou.com/linux/guide
sudo apt install fcitx
#按照第一步:1、添加中文语言支持 处理,并重启系统
#安装
wget https://ime.sogouimecdn.com/202208041520/03940f168eb3fa5819e568874dcc6a2f/dl/gzindex/1656597217/sogoupinyin_4.0.1.2800_x86_64.deb
sudo dpkg -i sogoupinyin_4.0.1.2800_x86_64.deb
#重启系统
#安装其他
sudo cp /usr/share/applications/fcitx.desktop /etc/xdg/autostart/
sudo apt purge ibus
sudo apt install libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2
sudo apt install libgsettings-qt1
#重启电脑

系统快捷键

1
2
3
4
5
6
7
#sudo apt install deepin-screenshot
# sudo apt install deepin-terminal
#deepin-screenshot -> ctrl+alt+Q
#deepin-terminal -> ctrl+alt+T
sudo apt install flameshot
xdg-open . -> Win+E
flameshot gui -> ctrl+alt+Q

NODEJS

1
2
3
4
5
6
7
#https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
. ~/.bashrc
#显示有远端的版本
nvm ls-remote
#安装对应的版本
nvm install v12.22.6

安装常用工具:

1
2
3
4
5
6
7
8
9
10
11
npm config set registry https://registry.npmmirror.com --global
npm config set disturl https://npmmirror.com/dist --global
npm install hexo-cli -g
npm install hexo-server -g
npm install hexo-deployer-git -g
npm install yarn -g
npm install http-server -g

yarn config set registry https://registry.npmmirror.com --global
yarn config set disturl https://npmmirror.com/dist --global
#yarn global add serve

JAVA

1
2
3
4
5
6
7
8
9
10
sudo mkdir -p /Developer/java /Developer/workspace
sudo chown -R dave.dave /Developer
sudo vim /etc/profile.d/java.sh
export JAVA_HOME=/Developer/java/jdk1.8.0_202
#export JAVA_HOME=$(/usr/libexec/java_home)
export M2_HOME=/Developer/apache-maven-3.5.4
export GRADLE_USER_HOME=/Developer/.gradle
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

source /etc/profile

gnome-shell

安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#For 22.04
sudo apt install gnome-tweaks chrome-gnome-shell gnome-shell-extension-manager
#open with firefox or chrome
https://extensions.gnome.org
#Click: Click here to install browser extension

plugin:
User Themes: https://extensions.gnome.org/extension/19/user-themes/
#dock-from-dash: https://extensions.gnome.org/extension/4703/dock-from-dash/
dash2dock-lite: https://extensions.gnome.org/extension/4994/dash2dock-lite/
dash-to-panel: https://extensions.gnome.org/extension/1160/dash-to-panel/
arc menu: https://extensions.gnome.org/extension/3628/arcmenu/

Gnome Wayland不成熟,登录时使用Ubuntu on X11 Org,否则Theme不能切换。

##Disable wayland on Ubuntu 22.04 Desktop
##https://linuxconfig.org/how-to-enable-disable-wayland-on-ubuntu-22-04-desktop
#echo $XDG_SESSION_TYPE
#sudo nano /etc/gdm3/custom.conf
##Within this file, look for the line that says #WaylandEnable=false. You can uncomment this line and either set it to true or #false, depending on whether you want Wayland enabled or not.
#WaylandEnable=false
##Restart
#sudo systemctl restart gdm3

Wine

企业微信需要用wine7安装才会有消息提醒,推荐使用:

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
#https://www.cnblogs.com/hyaline-doc/p/18011541

sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key

# 注意 对应你的ubuntu版本
# ubuntu 22.04 jammy
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources

sudo apt update
sudo apt install --install-recommends winehq-stable
wine --version


#企业微信
wine WeCom_3.1.16.3008.exe
#微信
wine WeChatSetup_V3.4.0.38.exe
#卸载
wine uninstaller
#配置
wine winecfg

#输入框不能正常显示(不显示)输入的文字
#https://blog.csdn.net/hongxiao2016/article/details/115156831
sudo apt install winetricks
# 安装微信需要的依赖,时间可能较长,我开了魔法的,还是下了挺久,wine在第一次使用是会问你是否安装 wine mono ,这是linux 上的.net,安装就好,但是可能比较慢,也可以后期手动装(后面补充),好像不装wine mono也可以正常打开微信
winetricks riched20 riched30 richtx32 msftedit ie8

#英文模式下微信乱码解决:
#https://blog.csdn.net/ysy950803/article/details/80326832
#cp -a /Developer/Software/Themes/Fonts/* ~/.deepinwine/Deepin-WeChat/drive_c/windows/Fonts/
cp -a /Developer/linux/software/Themes/Fonts/*.TTC ~/.wine/drive_c/windows/Fonts/
#cp -a MSYH/* ~/.wine/drive_c/windows/Fonts/

#vim msyh_font.reg
#REGEDIT4
#
#[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink]
#"Lucida Sans Unicode"="msyh.ttc"
#"Microsoft Sans Serif"="msyh.ttc"
#"MS Sans Serif"="msyh.ttc"
#"Tahoma"="msyh.ttc"
#"Tahoma Bold"="msyhbd.ttc"
#"msyh"="msyh.ttc"
#"Arial"="msyh.ttc"
#"Arial Black"="msyh.ttc"
#
##deepin-wine6-stable regedit msyh_font.reg
#wine regedit msyh_font.reg
#
##vim /home/dave/.deepinwine/Deepin-WeChat/system.reg
##vim ~/.wine/system.reg
##查找关键词FontSubstitutes,把它下面挨着的“MS Shell Dlg”与“MS Shell Dlg2”的内容改为“msyh”
#sed -i 's;"MS Shell Dlg"="Tahoma";"MS Shell Dlg"="msyh";g' ~/.wine/system.reg
#sed -i 's;"MS Shell Dlg 2"="Tahoma";"MS Shell Dlg 2"="msyh";g' ~/.wine/system.reg

VPN

1
2
3
sudo apt install openconnect
sudo apt install network-manager-openconnect
sudo apt install network-manager-openconnect-gnome

SecureCRT

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
#libssl1.0.0
sudo dpkg -i libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb

#libpython2.7
#sudo apt-get install libpython2.7
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
tar -xvjf Python-2.7.5.tar.bz2
cd Python-2.7.5
./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
make
make install altinstall

ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib
ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
ln -s /usr/local/python2.7/bin/python2.7 /usr/local/bin
/sbin/ldconfig -v

#libpng12
#sudo add-apt-repository ppa:linuxuprising/libpng12
#sudo apt update
#sudo apt install libpng12-0
sudo apt install build-essential zlib1g-dev
cd
mkdir src
wget https://ppa.launchpadcontent.net/linuxuprising/libpng12/ubuntu/pool/main/libp/libpng/libpng_1.2.54.orig.tar.xz
tar Jxfv libpng_1.2.54.orig.tar.xz
cd libpng-1.2.54
./configure
make
sudo make install
sudo ln -s /usr/local/lib/libpng12.so.0.54.0 /usr/lib/libpng12.so
sudo ln -s /usr/local/lib/libpng12.so.0.54.0 /usr/lib/libpng12.so.0

#Install
sudo dpkg -i scrt-sfx-8.3.4-1699.ubuntu16-64.x86_64.deb
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
sudo apt install libfuse2

#libcrypto
wget https://www.openssl.org/source/openssl-1.1.0k.tar.gz
tar xvf openssl-1.1.0k.tar.gz
cd openssl-1.1.0l
./config
make -j`nproc`
sudo make install
sudo ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
sudo ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

#Crack
./navicat-keygen --text ./RegPrivateKey.pem

sudo cp -a libgio-2.0.so.0 /Developer/Navicat15/

#/lib/x86_64-linux-gnu/libgio-2.0.so.0: undefined symbol: g_module_open_full的解决:
#vim navicat15.sh
#!/bin/bash

export LD_LIBRARY_PATH=/Developer/Navicat15:$LD_LIBRARY_PATH;
/Developer/Navicat15/navicat15-premium-cs-patched.AppImage

#Start
/Developer/Navicat15/navicat15.sh

#https://www.zssnp.top/2021/11/11/netease/
#sudo mv /lib/x86_64-linux-gnu/libgio-2.0.so.0 /lib/x86_64-linux-gnu/libgio-2.0.so.0.bak
##download libgio-2.0.so.0 from: https://wwx.lanzoui.com/iNxJNwdnkle
#sudo cp -a libgio-2.0.so.0 /lib/x86_64-linux-gnu/
##发现处理后settings打不开,恢复:
#sudo ln -sf /lib/x86_64-linux-gnu/libgio-2.0.so.0.7200.1 /lib/x86_64-linux-gnu/libgio-2.0.so.0
##libselinux.so.1: no version information available (required by /lib/x86_64-linux-gnu/libgio-2.0.so.0)
#可以忽略,不影响使用

Cider

1
2
3
#https://cider.sh/
wget https://github.com/ciderapp/cider-releases/releases/download/v1.5.0/cider_1.5.0_amd64.deb
sudo dpkg -i cider_1.5.0_amd64.deb

字体

1
2
3
4
#wget "https://dl-sh-ctc-2.pchome.net/25/rm/YosemiteSanFranciscoFont-master.zip"
#mv YosemiteSanFranciscoFont-master SanFranciscoFont
#sudo cp -a SanFranciscoFont /usr/share/fonts/
sudo git clone https://github.com/AppleDesignResources/SanFranciscoFont /usr/share/fonts/SanFranciscoFont

San Francisco Text Medium

WPS字体

1
2
3
4
5
#https://blog.huzhifeng.com/2017/01/15/WPS/
#https://www.dropbox.com/s/q6rhaorhsbxbylk/wps_symbol_fonts.zip?dl=0
sudo mkdir -p /usr/share/fonts/wps_symbol_fonts
sudo unzip wps_symbol_fonts.zip -d /usr/share/fonts/wps_symbol_fonts
sudo chmod 755 /usr/share/fonts/wps_symbol_fonts

开机画面

1
2
3
4
#https://www.gnome-look.org/browse/cat/109/ord/latest/
git clone https://github.com/vinceliuice/grub2-themes
cd grub2-themes
./install.sh

SysMonitor

1
2
3
4
5
6
7
8
9
10
11
12
13
#https://www.zhyong.cn/posts/f35/
sudo apt install python3-psutil gir1.2-appindicator3-0.1
git clone https://github.com/fossfreedom/indicator-sysmonitor.git
cd indicator-sysmonitor
sudo make install
cd ..
rm -rf indicator-sysmonitor

#配置
方案一
{net}║cpu:{cpu}/{cputemp}
方案二
{net}║CPU {cpu}/{cputemp}║MEM {mem}/{fs///}

Zerotier

1
2
3
4
5
6
#https://blog.csdn.net/awzs7758520/article/details/130127967
#curl -s https://install.zerotier.com | sudo bash
sudo apt install zerotier-one
sudo zerotier-cli join network-id
sudo systemctl enable zerotier-one
sudo systemctl start zerotier-one

路由不通解决:

1
2
3
4
5
6
7
8
9
10
11
12
#https://zhichao.org/posts/zerotier
通过上面的设置,已经实现了连接到 ZeroTier 的设备使用内网 IP 访问局域网,但是局域网内的设备仍然无法使用 ZeroTier 分配的 IP 来访问那些连接到 ZeroTier 的设备,我们还需要在路由器中配置静态路由:

内部网络--->路由设置:

网络 / 主机 IP: 与 ZeroTier 网段保持一致: 192.168.195.0
网络掩码: 与 ZeroTier 掩码保持一致 (/24 为 255.255.255.0): 255.255.255.0
网关: 安装 ZeroTier 设备的内网 IP: 192.168.3.2


#OpenWRT的参考:
https://www.douban.com/note/841817168/?_i=00754617wYVM7F,0086159YLqUxZi

XRDP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo apt install xrdp
sudo systemctl enable xrdp
sudo systemctl start xrdp
#https://stackoverflow.com/questions/78074498/how-to-configure-xrdp-to-work-with-gnome-on-ubuntu
sudo apt update
sudo apt install xrdp gnome-session

sudo adduser xrdp ssl-cert

echo "gnome-session" | tee ~/.xsession

echo "export XAUTHORITY=${HOME}/.Xauthority" | tee ~/.xsessionrc
echo "export GNOME_SHELL_SESSION_MODE=ubuntu" | tee -a ~/.xsessionrc
echo "export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg" | tee -a ~/.xsessionrc

echo "export XDG_CURRENT_DESKTOP=ubuntu:GNOME" | tee -a ~/.xsessionrc

sudo systemctl restart xrdp
#You must always be logged out locally in order to connect in remotely.

完美方案——解决XRDP连接黑屏,以及桌面优化:

1
2
3
4
5
6
#https://www.cnblogs.com/bruce1992/p/16535833.html
sudo vim /etc/xrdp/startwm.sh
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR

sudo systemctl restart xrdp.service

Xrdp 体验优化 减少/解决画面卡顿:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#https://blog.csdn.net/wu_weijie/article/details/116158271
#编辑 /etc/xrdp/xrdp.ini

tcp_send_buffer_bytes=4194304
tcp_recv_buffer_bytes=6291456

#将以下内容写入配置文件 /etc/sysctl.conf

net.core.rmem_max = 12582912
net.core.wmem_max = 8388608

sudo sysctl -p

sudo systemctl restart xrdp

EQ13 Ubuntu Bluetooth

1
2
3
4
5
sudo dmesg|grep Bluetooth

lsusb

sudo apt install bluez-firmware

修复grub

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#view UUID
blkid

#Starting repair grub
#root=(hd0,gpt8)
#prefix=/boot/grub
set root=(hd0,gpt8)
set prefix=(hd0,gpt8)/boot/grub
insmod normal
normal
#Logon System
sudo update-grub
sudo grub-install /dev/nvme0n1
#或者
sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt-get update
sudo apt-get install boot-repair
#打开Dash,输入boot-repair,打开它,点击recommanded repair按钮。接下来按照提示修复即可。

#Fixed fstab error
mount -o remount, rw /

MySQL

二进制文件安装

全自动安装:

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
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

sudo apt-get install libaio1 libaio-dev -y
sudo apt-get install libnuma-dev -y
sudo apt-get install libncurses5 -y

cat > /etc/my.cnf << EOF
[mysqld]
bind-address=0.0.0.0
port=3306
socket=/Developer/mysql-5.7.37/data/mysql.sock
pid-file=/Developer/mysql-5.7.37/logs/mysql.pid
basedir=/Developer/mysql-5.7.37
datadir=/Developer/mysql-5.7.37/data
max_connections=20

character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
EOF

cat > /usr/lib/systemd/system/mysqld.service << EOF
[Unit]
Description=MySQL Server
After=syslog.target
After=network.target

[Service]
Type=simple
PermissionsStartOnly=true
#ExecStartPre=/bin/mkdir -p /var/run/mysqld
#ExecStartPre=/bin/chown mysql:mysql -R /var/run/mysqld
ExecStart=/Developer/mysql-5.7.37/bin/mysqld_safe --defaults-file=/etc/my.cnf
ExecStop=/Developer/mysql-5.7.37/bin/mysql.server stop
TimeoutSec=300
PrivateTmp=true
User=mysql
Group=mysql
WorkingDirectory=/Developer/mysql-5.7.37
EOF

tar zxf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
mkdir -p /Developer/mysql-5.7.37/
cp -a mysql-5.7.37-linux-glibc2.12-x86_64/* /Developer/mysql-5.7.37/
rm -fr mysql-5.7.37-linux-glibc2.12-x86_64

cp -a /Developer/mysql-5.7.37/support-files/mysql.server /Developer/mysql-5.7.37/bin/mysql.server
sed -i "s;^basedir=.*;basedir=/Developer/mysql-5.7.37;g" /Developer/mysql-5.7.37/bin/mysql.server
sed -i "s;^datadir=.*;datadir=/Developer/mysql-5.7.37/data;g" /Developer/mysql-5.7.37/bin/mysql.server

groupadd mysql
useradd -r -g mysql mysql
sudo chown -R mysql:mysql /Developer/mysql-5.7.37
sudo mkdir -p /Developer/mysql-5.7.37/logs/
sudo chown -R mysql.mysql /Developer/mysql-5.7.37/logs/

sudo /Developer/mysql-5.7.37/bin/mysqld --initialize --user=mysql > ./log 2>&1
rootpwd=`cat ./log | grep "temporary password"|sed 's;^.*: ;;g'`
echo "root pwd is: $rootpwd"
#--basedir=/Developer/mysql-5.7.37 --datadir=/Developer/mysql-5.7.37/data

ln -s /Developer/mysql-5.7.37/bin/mysql /usr/bin/mysql

ln -s /Developer/mysql-5.7.37/data/mysql.sock /tmp/mysql.sock
#Doesn't work for docker build
systemctl daemon-reload
sudo systemctl enable mysqld

su - mysql -c "/Developer/mysql-5.7.37/bin/mysqld_safe --defaults-file=/etc/my.cnf &"
mkdir -p /var/run/mysqld/
ln -s /Developer/mysql-5.7.37/data/mysql.sock /var/run/mysqld/mysqld.sock
ln -s /Developer/mysql-5.7.37/bin/mysqladmin /usr/bin/mysqladmin
sleep 3

mysql -uroot -h127.0.0.1 -p$rootpwd --connect-expired-password -e "alter user user() identified by '';FLUSH PRIVILEGES;"
echo "The root password has been empty for localhost!"

echo "Starting granting some privileges..."
mysql -uroot -h127.0.0.1 -e " \
grant all privileges on *.* to root@'%' identified by 'Aa123#@!' WITH GRANT OPTION; \
grant all privileges on *.* to webase@'%' identified by 'Aa123#@!' WITH GRANT OPTION; \
FLUSH PRIVILEGES; \
"

mysqladmin -uroot -S /var/run/mysqld/mysqld.sock shutdown

手动安装:

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#https://blog.csdn.net/weixin_36349646/article/details/102616914
#https://www.cnblogs.com/ralap7/p/9034879.html
#https://raw.githubusercontent.com/zhaoxunyong/stock-webapp/1.1.x/backend/README.md

sudo apt-get install libaio1 libaio-dev -y
sudo apt-get install libnuma-dev -y

#创建用户组mysql
groupadd mysql
#-r参数表示mysql用户是系统用户,不可用于登录系统,创建用户mysql并将其添加到用户组mysql中
useradd -r -g mysql mysql
sudo chown -R mysql:mysql /Developer/mysql-5.7.37
sudo mkdir -p /Developer/mysql-5.7.37/logs/
sudo chown -R mysql.mysql /Developer/mysql-5.7.37/logs/

vim my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
socket=/Developer/mysql-5.7.37/data/mysql.sock
pid-file=/Developer/mysql-5.7.37/logs/mysql.pid
basedir=/Developer/mysql-5.7.37
datadir=/Developer/mysql-5.7.37/data
max_connections=20

character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1

sudo cp -a my.cnf /etc/my.cnf

/usr/lib/systemd/system/mysqld.service
#vim mysqld.service
[Unit]
Description=MySQL Server
After=syslog.target
After=network.target

[Service]
Type=simple
PermissionsStartOnly=true
#ExecStartPre=/bin/mkdir -p /var/run/mysqld
#ExecStartPre=/bin/chown mysql:mysql -R /var/run/mysqld
ExecStart=/Developer/mysql-5.7.37/bin/mysqld_safe --defaults-file=/etc/my.cnf
ExecStop=/Developer/mysql-5.7.37/bin/mysql.server stop
TimeoutSec=300
PrivateTmp=true
User=mysql
Group=mysql
WorkingDirectory=/Developer/mysql-5.7.37

[Install]
WantedBy=multi-user.target

sudo cp -a mysqld.service /usr/lib/systemd/system/mysqld.service

cp -a /Developer/mysql-5.7.37/support-files/mysql.server /Developer/mysql-5.7.37/bin/mysql.server
sed -i "s;^basedir=.*;basedir=/Developer/mysql-5.7.37;g" /Developer/mysql-5.7.37/bin/mysql.server
sed -i "s;^datadir=.*;datadir=/Developer/mysql-5.7.37/data;g" /Developer/mysql-5.7.37/bin/mysql.server

#Copying the following password the command's generated:
sudo bin/mysqld --initialize --user=mysql --basedir=/Developer/mysql-5.7.37 --datadir=/Developer/mysql-5.7.37/data

#Starting 1
sudo systemctl start mysqld

#Starting 2
#sudo vim support-files/mysql.server
basedir=/Developer/mysql-5.7.37
datadir=/Developer/mysql-5.7.37/data
#Starting MySQL Server
sudo support-files/mysql.server start
sudo support-files/mysql.server stop

#Starting 3
#/works/app/mysql/bin/mysqld_safe --datadir=/works/data/mydata --socket=/works/app/mysql/mysql.sock &
#mysqladmin -uroot -p -S /works/app/mysql/mysql.sock shutdown
/Developer/mysql-5.7.37/bin/mysqld_safe --defaults-file=/etc/my.cnf --socket=/works/app/mysql/mysql.sock &
mysqladmin -uroot -p -S /works/app/mysql/mysql.sock shutdown

#bin/mysql -uroot -p
alter user 'root'@'localhost' identified by 'Aa654321';
FLUSH PRIVILEGES;
grant all privileges on *.* to root@'%' identified by '123456' WITH GRANT OPTION;
#grant all privileges on *.* to root@'localhost' identified by 'Aa654321';
CREATE DATABASE `saas` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
FLUSH PRIVILEGES;

docker安装

1
2
3
4
5
6
7
8
#https://raw.githubusercontent.com/zhaoxunyong/stock-webapp/1.1.x/backend/README.md
docker run -d -p 3306:3306 --restart=always --name mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
# -e MYSQL_DATABASE=test \
-e MYSQL_USER=webase \
-e MYSQL_PASSWORD=123456 \
mysql:5.7.32 \
--character-set-server=utf8 --collation-server=utf8_general_ci --lower_case_table_names=1

Docker

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
systemctl disable iptables
systemctl stop iptables
systemctl disable firewalld
systemctl stop firewalld

#Uninstalling old versions:
sudo apt-get remove docker docker-engine docker.io containerd runc

#Installation from docker offical:
#https://docs.docker.com/engine/install/ubuntu/
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt install docker-ce docker-ce-cli containerd.io

#Or Installation From Aliyun
#https://www.cnblogs.com/763977251-sg/p/11837130.html
#Docker installation
#https://aka.ms/vscode-remote/samples/docker-from-docker
apt-get -y install apt-transport-https ca-certificates software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
# Step 3: 写入软件源信息
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
apt-get -y update
#apt install python3 -y
#apt-get -y install docker-ce
#sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

#History Version:
apt-cache madison docker-ce

#Uninstall
#sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
#Images, containers, volumes, or customized configuration files on your host are not automatically removed. To #delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

#Setting china mirror
#https://www.cnblogs.com/wushuaishuai/p/9984228.html
https://github.com/zhaoxunyong/vagrant/blob/master/boxes/docker/script.sh

sudo tee /etc/docker/daemon.json <<-'EOF'
{
"dns" : [
"8.8.4.4",
"8.8.8.8",
"114.114.114.114"
],
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://3laho3y3.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com"
]
}
EOF

#Proxy
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<-'EOF'
[Service]
Environment="HTTP_PROXY=http://192.168.101.175:1082"
Environment="HTTPS_PROXY=http://192.168.101.175:1082"
Environment="NO_PROXY=127.0.0.1,localhost,10.0.0.0/8,172.0.0.0/8,192.168.0.0/16,*.zerofinance.net,*.aliyun.com,*.163.com,*.docker-cn.com,kubernetes.docker.internal"
EOF

或者:
vim /usr/lib/systemd/system/docker.service
# 在dockerd后面加参数
ExecStart=/usr/bin/dockerd \
--registry-mirror=https://registry.docker-cn.com \
--registry-mirror=https://3laho3y3.mirror.aliyuncs.com \
--registry-mirror=http://hub-mirror.c.163.com;" \
...
以上操作后重启一下 Docker

#开启远程API访问端口
https://cloud.tencent.com/developer/article/1683689
# vim /usr/lib/systemd/system/docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

sudo systemctl daemon-reload
sudo systemctl restart docker
lsof -i:2375
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dockerd 1259648 root 6u IPv6 2709332 0t0 TCP *:2375 (LISTEN)

#Test
docker pull k8s.gcr.io/echoserver:1.4

sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo chmod 666 /var/run/docker.sock
sudo systemctl restart docker
docker info后是否有Registry Mirrors.

测速:
docker rmi node:latest
time docker pull node:latest

History docker installation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
docker version is: 20.10.7:
#https://blog.csdn.net/u011519550/article/details/102688892
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"

apt-cache madison docker-ce
apt install docker-ce-cli=5:20.10.7~3-0~ubuntu-xenial docker-ce=5:20.10.7~3-0~ubuntu-xenial

Ubuntu: Failed to get D-Bus connection: No such file or directory:
cat /etc/rc.local
sudo mkdir /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
#reboot and docker start your container.

Creating centos instance with restrict cpu and memory:

1
docker run -d --privileged=true --cpus=4 --cpu-shares=4000 -m 2048m --memory-reservation=256m --name mycento registry.zerofinance.net/library/centos:7 /usr/sbin/init