Ubuntu 软件仓库

 
change source.list 
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
    

 

    

 

    

 
在 Ubuntu 24.04 之前,Ubuntu 的软件源配置文件使用传统的 One-Line-Style,
路径为 /etc/apt/sources.list;

从 Ubuntu 24.04 开始,Ubuntu 的软件源配置文件变更为 DEB822 格式,
路径为 /etc/apt/sources.list.d/ubuntu.sources。

    

24.04 LTS

 
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ noble-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse

23.04,之前旧版本的源已不再更新,皆使用新版本

 
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse

 


 
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble noble-updates noble-backports
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# Types: deb-src
# URIs: http://security.ubuntu.com/ubuntu/
# Suites: noble-security
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 预发布软件源,不建议启用

# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

 


ubantu 常用依赖包安装

 
安装程序被锁定,重启也不管用时执行以下操作
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/cache/apt/archives/lock-frontend
sudo  rm /var/lib/dpkg/lock-frontend

apt update 

gcc软件包
sudo apt install build-essential
apt install cmake

apt install net-tools vim pkg-config  git  ntpdate alsa-utils  libxft-dev curl

apt install libxinerama-dev libcairo-gobject2  libpango1.0-dev  libpangoxft-1.0-0 libpangocairo-1.0-0 libxcursor-dev libcairo2-dev libbz2-dev 

apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev

apt-get install libaio-dev tcl tk expect  libldap2-dev libsasl2-dev

apt-get install libssl-dev  #openssl

apt-get install p7zip-full

apt-get install unixodbc unixodbc-dev
apt-get install libmysqlclient-dev

apt install daemonize fontconfig




sudo apt install fcitx fcitx-table-wbpy  # 小企鹅五笔输入法
sudo apt-get install fcitx-googlepinyin  # 小企鹅拼音输入法


软件卸载
$ sudo dpkg --list |grep baidu
ii  baidunetdisk                                  4.11.5                              amd64        
ii  fcitx-baidupinyin:amd64                       1.0.1.0                             amd64        Fcitx wrapper for Baidu Pinyin IM engine

$ sudo apt-get --purge remove baidunetdisk

视频软件安装

视频播放

 
sudo apt-get install vlc

sudo apt-get install mpv
sudo apt-get install mplayer

sudo apt-get install smplayer

如果是视频学习,则推荐smplayer,可以设置播放速度,快捷键],每次增加10%的播放速度

可以后退,可以一次后退10秒,1分钟等


apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
        gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
        gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \
        gstreamer1.0-libav libgstrtspserver-1.0-dev libges-1.0-dev

apt-get install libgstreamer-plugins-bad1.0-dev

视频录制

 
SimpleScreenRecorder

sudo add-apt-repository -y ppa:maarten-baert/simplescreenrecorder

sudo apt-get update

sudo apt-get install simplescreenrecorder

设置开始结束快捷键:Alt+X

录制结束后,点击一下 "Save recording"

录制出来的视频非常大... 

ubantu版本说明

Ubuntu 22.04.2 LTS

 
https://ubuntu.com/download/desktop
The latest LTS version of Ubuntu, for desktop PCs and laptops. 
LTS stands for long-term support — 
which means five years of free security and maintenance updates, guaranteed until April 2027.


Ubuntu 23.04

 
https://ubuntu.com/download/desktop

The latest version of the Ubuntu operating system for desktop PCs and laptops, 
Ubuntu 23.04 comes with nine months of security and maintenance updates, until January 2024.

Recommended system requirements are the same as for Ubuntu 22.04 LTS.

挂载磁盘

查看uuid

 
blkid

root@ai:~# blkid |grep 56d2
/dev/sda2: UUID="ae7fc523-4434-4543-a4c7-89890f4556d2" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="2b41b80d-02"

root@ai:~# cat /etc/fstab |grep 56d2
UUID=ae7fc523-4434-4543-a4c7-89890f4556d2 /var            ext4    defaults        0       2

开发软件安装

 
ubantu安装python3
---------------------------------------------------------------------------------
sudo apt install python3.9         # version 3.7.3-1, or
sudo apt install python2.7          # version 2.7.16-1
sudo apt install python-minimal  # version 2.7.16-1

ln -s /usr/bin/python2.7 /bin/python
或 更改默认值,谁的值高谁优先
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

或者按各自版本设定顺序
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

用到哪个时,再设为100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100

pip安装注意区别python2与python3
apt install python-pip
apt install python3-pip


Ubuntu Docker 简易安装
-------------------------------------------------------------------
sudo apt-get update
sudo apt install docker.io

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

sudo systemctl start docker
sudo systemctl enable docker
docker -v



数据库安装
========================================================

mysql
-------------------------------------------------------------------
sudo apt-get install mysql-server

修改配置文件
vim /etc/mysql/my.cnf
[mysqld]
server-id = 100  # 不限制具体数值
log_bin = mysql-bin
binlog_format = row
character-set-server=utf8

需要以root用户启动
/etc/init.d/mysql start
mysql -uroot -p
Enter password:
默认密码为空

用户创建
create user 'automng'@'%' ;
GRANT ALL PRIVILEGES ON *.* TO 'automng'@'%' identified by 'Automng_123'  WITH GRANT OPTION;
create user 'automng'@'127.0.0.1' ;
GRANT ALL PRIVILEGES ON *.* TO 'automng'@'127.0.0.1' identified by 'Automng_123'  WITH GRANT OPTION;
create user 'automng'@'localhost' ;
GRANT ALL PRIVILEGES ON *.* TO 'automng'@'localhost' identified by 'Automng_123'  WITH GRANT OPTION;
flush privileges;

create user 'root'@'127.0.0.1' ;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' identified by '123456' WITH GRANT OPTION;
flush privileges;


/etc/init.d/mysql restart

mysql -uautomng -pAutomng_123
alias root="mysql -uroot -p123456"


redis
-------------------------------------------------------------
sudo apt-get install redis-server
vim /etc/redis/redis.conf
# bind 192.168.1.100 10.0.0.1
bind 0.0.0.0

/etc/init.d/redis-server start
redis-cli
127.0.0.1:6379>


mongodb
----------------------------------------------------------------------------
sudo apt-get install mongodb

vim /etc/mongodb.conf
bind_ip = 0.0.0.0

/etc/init.d/mongodb start
netstat -tunlp |grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      16750/mongod


/etc/init.d/mongodb restart
# mongo
MongoDB shell version v3.6.8
connecting to: mongodb://127.0.0.1:27017

cetons
https://www.imooc.com
https://www.imooc.com/article/22072

GPU驱动安装

 
网络不好时,最好配置一个国内的ubantu源,此次安装Ubantu20.04.4
sudo add-apt-repository ppa:graphics-drivers/ppa  
sudo apt update  
sudo apt upgrade

使用ubuntu-drivers工具检测可用的NVIDIA驱动,并安装推荐的驱动:
ubuntu-drivers devices  
sudo ubuntu-drivers autoinstall
    

 
root@ai:~# nvidia-smi
Tue May  7 10:25:43 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.171.04             Driver Version: 535.171.04   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 4070 ...    Off | 00000000:01:00.0 Off |                  N/A |
| N/A   47C    P3              12W /  55W |      1MiB /  8188MiB |      3%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                            
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

    

 

    

 

    

 


 

  

 


ubantu常用设置

 
ubantu sudo 免密码
------------------------------------------------------------
# cat /etc/sudoers.d/xt
%xt ALL=(ALL) NOPASSWD:ALL

echo '%xt ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/xt


ubantu开机执行脚本
# crontab -e
@reboot ( sleep 30 ; bash /opt/scripts/os_init.sh )


不锁屏
---------------------------------------
settings-->Privacy-->Automatic Screen Lock--> OFF
或者
下三角-->个人用户--> UNLOCK 


添加用户并修改其属组
adduser bml
root@kl:~# sudo usermod -g xt bml
root@kl:~# id bml
uid=1001(bml) gid=1000(xt) groups=1000(xt)

echo '%bml ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/bml

ssh安装
ssh安装及使用

ubantu20 ssh安装

 
sudo apt install openssh-server

sudo service ssh status

sudo service ssh restart 

systemctl status ssh.service

 

    

 
远程服务器为root@px-asia-3.matpool.com,SSH端口为29825,需要将远程的11434端口挂载到本地的11435端口。
    
ssh -L 11435:localhost:11434 root@px-asia-3.matpool.com -p 29825 

可以使用以下命令实现SSH端口转发并以后台方式运行:
ssh -L 11435:localhost:11434 root@px-asia-3.matpool.com -p 29825 -N -q 

netstat -tuln | grep 11435

 

    

 

    

 


 

  

 


ssh配置

远程

 
ssh-keygen -t rsa

$ sudo su - root
# vim /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2 
    
# 出现Permission denied (publickey)时,进行如下设置,打通密钥之前还是需要密码来验证的
PermitRootLogin yes
PasswordAuthentication yes

重启远程服务器或者重启ssh服务

密钥文件传送完毕后,再将下面两项关闭,后续使用密钥文件更安全一些
PermitRootLogin no
PasswordAuthentication no


本地

 
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub remoteuser@remoteip 

ssh-copy-id 命令的作用:
scp id_rsa.pub文件到远程,并将之加入authorized_keys,
远程服务器.ssh目录没有authorized_keys文件时,会先创建 



ubantu共享目录给windows

 
sudo apt-get update
sudo apt-get install samba

设置要共享的目录

 
创建一个要共享的目录,并设定权限
sudo mkdir /home/share
sudo chown -R xt:xt /home/share/

文件追加
sudo vim /etc/samba/smb.conf
[share]
comment = xt share
path = /home/share
browsable = yes
writable = yes
    

 
设置访问密码
sudo smbpasswd -a  xt

重启服务 
sudo service smbd restart

如果重启失败,可查看日志,再根据日志中的错误信息搜索解决方案
tail -f /var/log/samba/log.smbd

 
右击我的电脑  --  网络映射器 -- 浏览  

sshfs挂载远程目录

通过 SSH 文件传输协议(SFTP)挂载远程的文件系统

 
sshfs安装,客户端安装
sudo apt install sshfs 

打通ssh,后面要用基于ssh的秘钥认证 

客户端创建挂载目录
mkdir -p /opt/www/web73 
​
客户端挂载远程的文件系统
sshfs txip:/opt/www/web73 /opt/www/web73  


添加开机启动脚本 , 注意任务要加在打通ssh的用户下
$ cat /opt/scripts/os_init.sh 
#!/bin/bash
sshfs txip:/opt/www/web73 /opt/www/web73

$ crontab -e
@reboot ( sleep 30 ; bash /opt/scripts/os_init.sh )

增加swap

 
dd if=/dev/zero of=./swap1 bs=20M count=1024
dd if=/dev/zero of=./swap2 bs=20M count=1024

mkswap ./swap1 
mkswap ./swap2 

chmod 600 ./swap1 
chmod 600 ./swap2 

swapon ./swap1 
swapon ./swap2 

vi /etc/fstab
/opt/swap1 swap swap defaults 0 0
/opt/swap2 swap swap defaults 0 0

swapoff ./swap1 

ubantu挂载windows共享目录

 
这里有个前提,网络是互通的;如果是windows安装的虚拟机,那么最好有一个桥接模式的网卡,就可以保证网络互通了

root挂载
mount -t cifs -o username=Administrator,password=******,vers=2.0,dir_mode=0777,file_mode=0777,gid=0,uid=0 //192.168.35.220/tpf /opt/tpf

普通用户挂载
xt@xt:/opt/tpf$ id xt
uid=1000(xt) gid=1000(xt) groups=1000(xt),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),122(lpadmin),134(lxd),135(sambashare)

sudo mount -t cifs -o username=Administrator,password=******,vers=2.0,dir_mode=0777,file_mode=0777,gid=1000,uid=1000 //192.168.35.220/tpf /opt/tpf

进入用户时挂载共享目录


$ cat .bashrc  
if [ ! -f "/opt/tpf/soft/ai_func.tar.gz" ];then
sudo mount -t cifs -o username=AS,password=Tanpf_410u,vers=3.0,dir_mode=0777,file_mode=0777,gid=1000,uid=1000 //192.168.1.133/tpf /opt/tpf
fi
    
ubantu添加用户
adduser liu
xt@xt:/opt/tpf$ adduser liu
Adding user `liu' ...
Adding new group `liu' (1001) ...
Adding new user `liu' (1001) with group `liu' ...
Creating home directory `/home/liu' ...
Copying files from `/etc/skel' ...
New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for liu
Enter the new value, or press ENTER for the default
    Full Name []: 
    Room Number []: 
    Work Phone []: 
    Home Phone []: 
    Other []: 
Is the information correct? [Y/n] Y



添加sudo权限

vim /etc/sudoers.d/liu
%liu ALL=(ALL) NOPASSWD:ALL

 

    

 
sudo addgroup -g 1006 groupname
sudo groupdel groupname

用户添加到组内
sudo adduser py1 xt
或 
usermod -a -G xt py1 

sudo adduser py1 root 

$ id py1
uid=1003(py1) gid=1003(py1) groups=1003(py1),0(root),100(users),1001(xt)
    
删除用户user2
userdel user2
usermod -a -G xt py1 


 
chmod 764 file1
chmod 777 -R dir

sudo chmod -R 764 aitpf/

sudo chmod -R 777 aitpf/



 


 

  

 


JDK

下载 
https://jdk.java.net/java-se-ri/11
cd /opt/app
tar -xvf openjdk-11+28_linux-x64_bin.tar.gz 
mv jdk-11/ jdk11

root@ai1:~# vim /etc/profile
export JAVA_HOME=/opt/app/jdk11/
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH

root@ai1:~# source /etc/profile

root@ai1:~# java --version
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

输入法安装

ubantu20 俄语输入法安装

 
设置 --> Region & Language 
--> Manage Installed Languages 
--> Install / Remove Languages 
--> 勾选 Russian 
--> 安装小企鹅五笔输入法(因为本人用五笔,所以是在这个输入法基础上用的Russian),
    sudo apt install fcitx fcitx-table-wbpy
    小企鹅也有拼音输入法,比如
    sudo apt-get install fcitx-googlepinyin
--> Manage Installed Languages,原来选择ibus的地方改为fcitx4
--> 重启电脑右上角会出现一个键盘,选择configure
--> 点击+号,添加 Keyboard-Russian 
--> 点击键盘图标,选择Input Method 
--> Keyboard-Russian  
这样就安装好俄语输入法了,аоуэы

如果操作下来后,出现了Keyboard-Russian ,但键盘输入的依然是英文,重启一次电脑,
然后再多等待一会就好了,比如等上1小时... 

参考文章
    ubuntu挂载windows下的文件目录的步骤