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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list

#For ubuntu 24.04
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse

#deb http://cz.archive.ubuntu.com/ubuntu jammy main universe


#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
28
29
30
#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就可以

sudo apt install menulibre


#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

配置环境变量

kubectl:

1
2
3
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv kubectl /usr/local/bin/

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"
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
#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

中文输入法 for linux

搜狗输入法

https://zhuanlan.zhihu.com/p/1924444784191313056

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 更新系统软件包
sudo apt update

# 卸载 Fcitx5 和 IBus(如果存在)
sudo apt remove --purge fcitx5* ibus*

# 清理系统残留
sudo apt autoremove && sudo apt autoclean

# 安装 Fcitx4 输入法框架
sudo apt install fcitx

# 设置 Fcitx 开机自启动
sudo cp /usr/share/applications/fcitx.desktop /etc/xdg/autostart/

https://shurufa.sogou.com/linux/guide

1
2
3
4
5
6
7
打开系统设置:Settings → Region & Language
点击 Manage Installed Languages
在弹出的"语言支持"窗口中:
点击 Install / Remove Languages...
勾选 Chinese (simplified),点击 Apply
在 Keyboard input method system 下拉菜单中选择 fcitx
点击 Apply System-Wide

1
2
3
4
5
6
# 安装必要的依赖包
sudo apt install libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2
sudo apt install libgsettings-qt1

# 安装搜狗输入法
sudo apt install ./sogoupinyin_4.2.1.145_amd64.deb

解决不能输入中文:

https://blog.csdn.net/wesleyflagon/article/details/131564216

1
2
3
4
5
6
7
8
9
10
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Qml.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Qml.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5DBus.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5DBus.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Gui.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Widgets.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Core.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Network.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Network.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Quick.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Quick.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5QuickWidgets.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5QuickWidgets.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5Svg.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5Svg.so.5
sudo cp /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5 /opt/sogoupinyin/files/bin/../lib/qt5/lib/libQt5XcbQpa.so.5

重启电脑

fcitx5中文拼音输入法

1
2
#https://zhuanlan.zhihu.com/p/675895900
sudo apt install fcitx5 fcitx5-chinese-addons

系统快捷键

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
8
#https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
. ~/.bashrc
#显示有远端的版本
nvm ls-remote
#安装对应的版本
nvm install v12.22.6
nvm install 22

安装常用工具:

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
sudo mkdir -p /Developer/java /Developer/workspace
sudo chown -R dave.dave /Developer

sudo vim /etc/profile.d/java.sh

1
2
3
4
5
6
7
export JAVA_HOME=/Developer/java/jdk-11.0.9
#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

Disable Wayland

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

1
2
3
4
5
6
7
8
##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 vim /etc/gdm3/custom.conf
WaylandEnable=false

##Restart
sudo systemctl restart gdm3

plugin

1
2
3
4
5
6
7
8
9
10
11
12
#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/

Theme

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#https://www.pling.com/p/1403328
#https://help.zorin.com/docs/system-software/third-party-themes/
#https://github.com/vinceliuice/WhiteSur-gtk-theme
#https://github.com/vinceliuice/WhiteSur-icon-theme
git clone https://github.com/vinceliuice/WhiteSur-gtk-theme.git --depth=1
cd WhiteSur-gtk-theme/
./install.sh
./install.sh --help
./install.sh -l
./tweaks.sh
sudo apt install gnome-tweaks chrome-gnome-shell gnome-shell-extension-manager
./install.sh -N mojave
cd ..
git clone https://github.com/vinceliuice/WhiteSur-icon-theme.git
cd WhiteSur-icon-theme/
./install.sh
./install.sh -a
./install.sh -b

VPN

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

Tabby

https://github.com/Eugeny/tabby

1
sudo apt install ./tabby-1.0.229-linux-x64.deb

字体

Windows字体

https://rrroger.github.io/notebook/linux/Ubuntu%E5%AE%89%E8%A3%85%E5%BE%AE%E8%BD%AF%E5%AD%97%E4%BD%93.html

https://www.cnblogs.com/liutongqing/p/7923297.html

1
2
3
4
5
6
7
8
9
git clone https://github.com/fernvenue/microsoft-yahei.git
sudo cp ./microsoft-yahei/* /usr/share/fonts/truetype/windows-font/
sudo chmod -R 777 /usr/share/fonts/truetype/windows-font
cd /usr/share/fonts/truetype/windows-font
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv
#查看已经安装的中文字体
fc-list :lang=zh

MacOS字体

1
2
3
4
5
6
7
8
9
sudo git clone https://github.com/AppleDesignResources/SanFranciscoFont /usr/share/fonts/truetype/macos-font/
sudo chmod -R 777 /usr/share/fonts/truetype/macos-font/
cd /usr/share/fonts/truetype/macos-font/
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv
#查看已经安装的中文字体
fc-list | grep -i Francisco
#San Francisco Text Medium

WPS字体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# #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

#https://blog.csdn.net/qq_34965596/article/details/132848356
git clone https://github.com/iamdh4/ttf-wps-fonts.git
mkdir /usr/share/fonts/wps-fonts
sudo mkdir /usr/share/fonts/wps-fonts
sudo cp ttf-wps-fonts/* /usr/share/fonts/wps-fonts
sudo chmod 644 /usr/share/fonts/wps-fonts/*
sudo fc-cache -vfs
wget http://ftp.de.debian.org/debian/pool/main/f/freetype/libfreetype6_2.12.1+dfsg-5+deb12u4_amd64.deb
sudo dpkg -i libfreetype6_2.12.1+dfsg-5+deb12u4_amd64.deb

ytdlp-gui

https://github.com/BKSalman/ytdlp-gui

1
sudo apt install ./ytdlp-gui_3.1.2-1_amd64.deb

xunlei

https://www.bilibili.com/video/BV1E54y1m7Gx/

https://parallel.lanzoul.com/ij7qxgle7ud

1
sudo apt install ./xunlei_1.0.0.1-myubuntu_amd64.deb

开机画面

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
sudo apt  install docker.io

#History Version:
apt-cache madison docker.io

#Uninstall
#sudo apt-get purge docker.io
dpkg -l |grep -i docker.io
sudo dpkg -P docker.io

#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/wwkjs/p/18757415/dockerhub
#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://docker.1ms.run",
"https://docker.mybacc.com",
"https://dytt.online",
"https://lispy.org",
"https://docker.xiaogenban1993.com",
"https://docker.yomansunter.com",
"https://aicarbon.xyz",
"https://666860.xyz",
"https://docker.zhai.cm",
"https://a.ussh.net",
"https://hub.littlediary.cn",
"https://hub.rat.dev",
"https://docker.m.daocloud.io"
]
}
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

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

simple-http-server

https://github.com/TheWaWaR/simple-http-server

1
2
3
4
wget https://github.com/TheWaWaR/simple-http-server/releases/download/v0.6.13/x86_64-unknown-linux-musl-simple-http-server
mv x86_64-unknown-linux-musl-simple-http-server simple-http-server
chmod +x simple-http-server
./simple-http-server -iu -p 8080 /Developer/workspace/