换源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list
注:在nano中,用ctrl+k批量删除,ctrl+o保存,ctrl+x退出
Ubuntu 18.04 ARM64 可用的国内源(太垃圾了,建议换20.04) deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security universe deb http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security multiverse
Ubuntu 20.04 ARM64 可用的国内源 deb https://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse deb https://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse deb https://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse deb https://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse deb https://mirror.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
更新源
sudo apt-get update
sudo apt-get upgrade
创建文件夹
mkdir repository
mkdir store
开机启动(推荐)
sudo nano /etc/systemd/system/op.service
写入以下文段
[Unit]
Description=Own Service
After=network.target
[Service]
User=(你的用户名)
Group=(你的用户组)
Type=forking
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/bin/bash /usr/local/bin/op.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
然后执行下列命令给权限
sudo chmod 664 /etc/systemd/system/op.service
接着写入你想要开机启动的内容
sudo nano /usr/local/bin/op.sh
给一个755的权限
sudo chmod 755 /usr/local/bin/op.sh
重新加载开机启动项
sudo systemctl daemon-reload
最后添加op至开机启动
#systemctl --user enable op.service
sudo systemctl enable op.service
开机启动
sudo nano /etc/systemd/system/rc-local.service
写入以下文段
※默认添加Unit和Service:
[Unit] Description=/etc/rc.local Compatibility Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no [Install] WantedBy=multi-user.target Alias=rc-local.service
执行创建
sudo nano /etc/rc.local
写入(开机自动挂载硬盘,创建screen并注入服务等) #!/bin/bash -e sudo mount /dev/sda1 /home/ubuntu/repository sudo mount /dev/sdb1 /home/ubuntu/store sudo sleep 5 sudo mount --bind /home/ubuntu/store/ruoyi_upload/mysql /var/lib/mysql sudo systemctl start nginx sudo systemctl start mysql sudo systemctl start redis-server sudo systemctl start docker sudo docker container start hch_rabbitmq sudo sleep 120 screen_name="frp" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/frp\n./frpc -c frpc.ini\n' screen_name="invoice_python" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'sudo sleep 60\ncd /home/ubuntu/ruoyi/invoice_python\nsudo python3 write_invoice.py\n' screen_name="ruoyi" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/ruoyi\nsudo java -jar ruoyi-admin.jar\n' sudo mount -t nfs 192.168.3.41:/volume1/hks-matrix /home/ubuntu/matrix -o proto=tcp -o nolock screen_name="clash" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/clash\n./clash-linux-armv8 -d .\n' screen_name="ytb_update" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/python_project\nsudo python3 update_ytb_video/ytb_update_clock.py\n' screen_name="clip_master" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/python_project\nsudo python3 clip_storage_processing/transit_unit.py\n' screen_name="audio_master" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/python_project\nsudo python3 audio_processing/audio_master.py\n' screen_name="image_master" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/python_project\nsudo python3 image_processing/image_master.py\n' exit 0
(总之一个原则,前置服务没起起来就让后置任务可劲儿等,sleep走起)
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
reboot
sudo systemctl status rc-local.service
安装python之安装pip3
sudo apt install python3-pip
安装java8
sudo apt-get install openjdk-8-jdk
安装Nginx
sudo apt install nginx
sudo systemctl status nginx
修改配置文件
sudo nano /etc/nginx/nginx.conf
如有需要可以重启
sudo systemctl restart nginx
安装mysql
sudo apt-get install mysql-server
sudo systemctl restart mysql
修改配置以方便远程管理
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
将bind-address = 127.0.0.1改为bind-address = 0.0.0.0
mysql -uroot -p
输入登陆密码(有的时候怎么输都出错,这个时候直接把「skip-grant-tables」加入配置文件,然后免密码登陆)
use mysql;
update user set host='%' where user ='root';
grant all privileges on *.* to 'root'@'%';
FLUSH PRIVILEGES;
修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
安装docker
sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
安装消息队列(下文中的*请自行去「https://cr.console.aliyun.com/」申请)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://*.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker pull rabbitmq:management
镜像列表
sudo docker image ls
删除镜像
sudo docker rmi 镜像名称
容器列表
sudo docker ps
停止容器
sudo docker stop 容器名称
sudo docker kill 容器名称
删除容器
sudo docker rm
启用消息队列
sudo docker run -d -p 5672:5672 -p 15672:15672 --name hch_rabbitmq rabbitmq:management
安装redis
sudo apt install redis-server
sudo systemctl status redis-server
如有需要可以重启
sudo systemctl restart redis-server
安装mangoDB
sudo screen -S mongodb
开启服务
cd /home/ubuntu/mongodb/bin
./mongod --bind_ip=0.0.0.0 --auth --port=27017
linux管理
sudo ./mongo
鉴权
db.auth('账号','密码')
show users
use admin
安装字体
sudo apt-get -y install fontconfig xfonts-utils
sudo cp /home/ubuntu/repository/font/* /usr/share/fonts/
cat /etc/issue
fc-list
cd /usr/share/fonts/
sudo mkfontscale
sudo mkfontdir
fc-cache
连接wifi(20.04以上版本)
sudo apt update
sudo apt install net-tools
sudo ifconfig wlan0 up
sudo apt install wireless-tools
sudo apt install iw
sudo apt-get install wpasupplicant
sudo apt-get install network-manager
cd /etc/netplan/
ls
sudo nano 你的文件名
输入
network: ethernets: eth0: dhcp4: true optional: true version: 2 wifis: wlan0: dhcp4: true access-points: "你的wifi的ssid": password: "你的密码"
保存
sudo netplan generate
sudo netplan apply
拔掉网线后重启
接着等待足够长的时间后
用wifi连ssh重启即可
查看网络配置
ifconfig -a
设置ffmpeg全局变量
sudo chmod -R 777 /home/ubuntu/ffmpeg
sudo ln -s /home/ubuntu/ffmpeg/ffmpeg /usr/bin/ffmpeg
sudo ln -s /home/ubuntu/ffmpeg/ffprobe /usr/bin/ffprobe
ffmpeg
ffprobe
运行SpringBoot后端
sudo java -jar ruoyi-admin.jar
frp相关
客户端
sudo chmod -R 777 frp文件夹
cd frp文件夹
sudo nano frpc.ini
# 这个别改 [common] server_addr = 你的ip server_port = 7000 token = 你的鉴权秘钥 # 随便写一个名字 [article] type = tcp local_ip = 127.0.0.1 local_port = 本地端口 remote_port = 服务端转发的端口 # 相当于你访问服务端的remote_port就能访问到客户端的local_port
./frpc -c frpc.ini
服务端
cd frp文件夹
sudo nano frps.ini
[common] server_addr = 0.0.0.0 # frp 服务所使用的端口(TCP) bind_port = 7000 # frp看板端口 dashboard_port = 6443 # 无连接延迟时间 authentication_timeout = 9000 dashboard_user = 看板用户名 dashboard_pwd = 看板密码 token = 你的鉴权秘钥(和客户端一致)
重启相关
断电重启之前需要执行的操作
进入每个screen停止服务
sudo shutdown -h now
断电重启之后需要执行的操作
(统统写道开机自启里了,不需要执行任何操作)
#!/bin/bash -e screen_name="mongo" sudo screen -dmS $screen_name sudo screen -x -S $screen_name -p 0 -X stuff $'cd /home/ubuntu/mongodb/bin\n./mongod --bind_ip=0.0.0.0 --auth --port=27017\n' exit 0
挂载nfs硬盘
sudo apt install -y cifs-utils
sudo apt-get install nfs-common
实现自动挂载U盘
sudo apt-get install usbmount
sudo nano /etc/usbmount/usbmount.conf
还需要配置udev——
Create file:
sudo mkdir /etc/systemd/system/systemd-udevd.service.d
sudo nano -w /etc/systemd/system/systemd-udevd.service.d/00-my-custom-mountflags.conf
and add content:
[Service]
PrivateMounts=no
restart udev (or reboot instead):
sudo systemctl daemon-reexec
sudo service systemd-udevd restart
可以使用
tail -f /var/log/syslog
来debug
使用rsync备份
sudo apt-get install rsync xinetd
sudo nano /etc/rsyncd.conf
编辑为:
[migo] comment = public archive path = /www/backup use chroot = yes lock file = /var/lock/rsyncd read only = no list = yes uid = nobody gid = nogroup comment = public archive path = /www/backup use chroot = yes # max connections=10 lock file = /var/lock/rsyncd # the default for read only is yes... read only = no list = yes uid = nobody gid = nogroup strict modes = yes ignore errors = yes ignore nonreadable = yes transfer logging = no timeout = 600 refuse options = checksum dry-run
sudo nano /etc/rsyncd.secrets
账号+:+密码
sudo nano /etc/default/rsync
RSYNC_ENABLE=inetd
sudo nano /etc/xinetd.d/rsync
# 写入内容 service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
sudo chmod 600 /etc/rsyncd.passwd
sudo chmod 600 /etc/rsyncd.secrets
sudo /etc/init.d/xinetd restart
sudo chmod 775 -R /www/backup
mcsm相关
systemctl start mcsm-{web,daemon}