ubutnu装机配置
Server配置
源地址
http://mirrors.aliyun.com/ubunut
盒盖不休眠
sudo vim /etc/systemd/logind.conf
HandleLidSwitch=ignore
sudo service systemd-logind restart
网络配置
ip a
wifi配置
network:
version: 2
wifis:
wlp2s0:
access-points:
rs.tang:
password: tang16966
dhcp4: true
网口
vim /etc/netplan/00-router-config.yaml
network:
ethernets:
wan:
dhcp4: true
match:
macaddress: 60:be:b4:10:66:5c
set-name: wan
lan0:
dhcp4: false
optional: true
match:
macaddress: 60:be:b4:10:66:5d
set-name: lan0
lan1:
dhcp4: false
optional: true
match:
macaddress: 60:be:b4:10:66:5e
set-name: lan1
lan2:
dhcp4: false
optional: true
match:
macaddress: 60:be:b4:10:66:5f
set-name: lan2
bridges:
br0:
interfaces: [lan0,lan1,lan2]
addresses: [192.168.100.1/24]
dhcp4: false
dhcp6: false
parameters:
stp: true
forward-delay: 4
optional: true
version: 2
sudo netplan try
sudo netplan apply
DHCP和DNS服务
安装
sudo apt install dnsmasq
由于dnsmasq 在启动时会因为 53 端口被占用而失败,需要先停止 systemd-resolved 服务
sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
删除现有的 resolv.conf 文件,重新设置新的 resolv.conf 文件,我这里继续用回路由器的DNS,方便统一管理:
sudo rm /etc/resolv.conf
echo nameserver 114.114.114.114 | sudo tee /etc/resolv.conf
安装 resolvconf
sudo apt install resolvconf
sudo systemctl status resolvconf.service
echo nameserver 114.114.114.114 | sudo tee /etc/resolvconf/resolv.conf.d/head
sudo systemctl restart resolvconf.service
sudo systemctl restart systemd-resolved.service
配置
sudo vi /etc/dnsmasq.conf
listen-address=127.0.0.1,192.168.100.1 # 监听 127.0.0.1 和 网桥的地址
port=53 # DNS 服务端口
interface=br0 # DNS & DHCP 服务网卡,有几个就重复几行
dhcp-range=192.168.100.100,192.168.100.105,255.255.255.0,12h # DHCP 的IP范围,子网掩码,租期
dhcp-option=option:router,192.168.100.1 # 网关地址(网桥)
dhcp-option=option:dns-server,192.168.100.1 # DNS 地址
dhcp-option=option:netmask,255.255.255.0
resolv-file=/etc/resolv.conf
dhcp-host=58:47:CA:71:C0:63,192.168.100.101 #固定ip
重启
sudo systemctl restart dnsmasq.service
连接外网
sudo vi /etc/sysctl.conf
# 并取消下面这行的注释,开启端口转发功能
net.ipv4.ip_forward=1
# 这行命令会报错不用管
sudo sysctl –p
配置iptablse
iptables -F
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o wan -j SNAT --to-source 192.168.0.111
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j MASQUERADE
安装应用
安装docker
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt update
sudo apt install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo gpasswd -a $USER docker
newgrp docker
sudo vim /etc/docker/daemon.json
{
"registry-mirrors":[
"https://hub-mirror.c.163.com/",
"https://docker.mirrors.ustc.edu.cn/"
]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
frp程序开机启动
sudo vim /etc/systemd/system/frp.service
[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target
[Service]
Type = simple
User=ruisong
Group=ruisong
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /home/ruisong/project/frp/frpc -c /home/ruisong/project/frp/frpc.ini
Restart=always
[Install]
WantedBy = multi-user.target
sudo chmod 664 /etc/systemd/user/frp.service
sudo systemctl daemon-reload
sudo systemctl enable frp
sudo systemctl start frp
添加用户
sudo adduser ruisong
sudo usermod -aG sudo ruisong
ssh-keygen -t rsa -b 4096 -C "ruisongtang@163.com"
vim authorized_keys
EMQX
docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 6010:18083 emqx/emqx:latest
Mysql
导出数据库
# 导出整个数据库
mysqldump -u 用户名 -p 数据库名 > 导出路径/导出文件名
mysqldump -u root -p merging_base > /home/ruisong/sql/merging_base.sql
mysqldump -u root -p merging-data4 > /mnt/data/sql/merging-bak.sql
# 导出部分表
mysqldump -u root -p --databases merging-data4 --tables ams_accounts ams_admins chinese_medicines western_medicines > /home/ruisong/sql/merging-data4.sql
# 只导出数据库表结构,不包含数据
mysqldump -uroot -p --no-data --databases merging-data4 > merging.sql
mysqldump -u root -p merging_13848420875 > merging_13848420875.sql
#导出整个数据库结构(不包含数据)
mysqldump -uroot -pAtang16966 -d merging-data3 > /home/ruisong/sql/merging-data5.sql
导入数据库
mysql -u root -p
drop database merging_data5;
create database merging_18990238722;
use merging_data5;
merging_18990238722
source /home/ruisong/sql/merging.sql
挂载磁盘
手动挂载
# 查看磁盘
sudo fdisk -l
# 创建挂载目录
sudo mkdir /mnt/data
# 挂载
sudo mount /dev/sdb1 /mnt/data
# 检查
df -h
启动自动挂载
# 查看UUID
sudo blkid /dev/sda
sudo vim /etc/fstab
#尾行加入
UUID=6****-22d7-4*b-a**4-c****8b1c /mnt/data ext4 defaults 0 0
分区并格式化
# https://zhuanlan.zhihu.com/p/658144022
# https://blog.csdn.net/qq_19253847/article/details/129198661
sudo fdisk /dev/sda
sudo mkfs -t ext4 /dev/sda