【介绍】
Ubuntu 是一个以桌面应用为主的开源 GNU/Linux 操作系统。
Ubuntu 基于 Debian GNU/Linux,支持x86、amd64(即x64)和ppc架构,由全球化的专业开发团队(Canonical Ltd)打造的。
Ubuntu 基于 Debian 发行版和 GNOME 桌面环境,而从11.04版起,Ubuntu 发行版放弃了 Gnome 桌面环境,改为 Unity 。
【环境】
查看系统版本:
lsb_release -a
输出:
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 24.04.3 LTS Release: 24.04 Codename: noble
【工具】
build-essential:
sudo apt-get install build-essential -y
参考:https://tecadmin.net/install-development-tools-on-ubuntu/
libtool等:
sudo apt-get install make libtool libtool-bin m4 autoconf automake libtool git aptitude htop dos2unix zip unzip -y
【更新】
sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
或者:
sudo aptitude update -y && sudo aptitude upgrade -y && sudo aptitude dist-upgrade -y
参考:https://ubuntuforums.org/showthread.php?t=1222909
【端口】
参考:https://www.jianshu.com/p/95e5cbd37070
安装:
sudo apt-get install iptables
开启:
iptables -I INPUT -p tcp --dport 端口号 -j ACCEPT
查验:
sudo netstat -tlpn | grep 端口号
如果需要部署网站,需要在Ubuntu系统里开启 80 / 443 两个端口。
iptables -I INPUT -p tcp --dport 80 -j ACCEPT iptables -I INPUT -p tcp --dport 443 -j ACCEPT
【排错】
排错:更新系统时出现 E: Repository changed its ‘Label’ value
这是 Ondřej Surý 维护的 PHP PPA 官方迁移提示,表示该仓库已正式迁移至 packages.sury.org,但当前 PPA 仍可继续使用(只是标签变了)。
要正常完成更新,您需要明确接受此变更。执行以下命令即可:
sudo apt update --allow-releaseinfo-change
问题:更新系统时出现 The following packages have been kept back
新开了一个 Ubuntu 22.04 系统,升级系统时出现:
Reading package lists... Done Building dependency tree... Done Reading state information... Done Calculating upgrade... Done The following packages have been kept back: libnss-systemd libpam-systemd libsystemd0 libudev1 systemd systemd-sysv systemd-timesyncd udev 0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
参考:https://itsfoss.com/following-packages-have-been-kept-back/
The fix for this error is really simple. All you have to do is to use the apt install command with package or packages in the question
参考:https://www.codenong.com/f-following-packages-have-been-kept-back/
解决方法:对问题中的一个或多个软件包使用apt install命令
sudo apt install libnss-systemd libpam-systemd libsystemd0 libudev1 systemd systemd-sysv systemd-timesyncd udev
解决方法:方案是运行 sudo apt-get install 。在大多数情况下,这将为保留的软件包提供成功升级所需的内容。
sudo apt-get install python3-update-manager update-manager-core
问题:WinSCP 以预设密码进行验证 拒绝访问
方法:关闭 WinSCP ,重新登录后,再使用 Putty。
参考:https://blog.csdn.net/weixin_42672685/article/details/123824826
第一次连接Ubuntu,使用 WinSCP 以预设密码进行验证,提示拒绝访问
解决方案:
路径:vim /etc/ssh/sshd_config
PermitEmptyPasswords yes
重启服务
service ssh restart
2.更改密码
3.核对密码再次登录
问题:缺少依赖
缺 libtool 时,报错:
:~/ModSecurity# ./build.sh ./build.sh: 6: ./build.sh: libtoolize: not found ./build.sh: 7: ./build.sh: autoreconf: not found ./build.sh: 8: ./build.sh: autoheader: not found ./build.sh: 9: ./build.sh: automake: not found ./build.sh: 10: ./build.sh: autoconf: not found
缺 m4 时,报错:
~/ModSecurity# ./build.sh libtoolize: error: One of these is required: libtoolize: gm4 gnum4 m4 libtoolize: error: Please install GNU M4, or 'export M4=/path/to/gnu/m4'.
参考:https://www.howtoinstall.co/en/ubuntu/trusty/m4
缺 autoconf automake 时,报错:
~/ModSecurity# ./build.sh ... ./build.sh: 7: ./build.sh: autoreconf: not found ./build.sh: 8: ./build.sh: autoheader: not found ./build.sh: 9: ./build.sh: automake: not found ./build.sh: 10: ./build.sh: autoconf: not found
参考:https://blog.csdn.net/x356982611/article/details/70856470
sysv-rc-conf:
参考:https://blog.csdn.net/weixin_42380024/article/details/80614290
参考:https://stackoverflow.com/questions/20680050/how-do-i-install-chkconfig-on-ubuntu
ubuntu中chkconfig已经被sysv-rc-conf替代,具体如下操作如下:
chkconfig: command not found
sysv-rc-conf命令:
sudo apt-get install sysv-rc-conf sysv-rc-conf keepalived on
报错:
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package sysv-rc-conf
参考:https://askubuntu.com/questions/378558/unable-to-locate-package-while-trying-to-install-packages-with-apt/481355
参考:https://www.cnblogs.com/sunyl1982/p/11864241.html
在软件源列表末尾添加如下内容:/etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
更新apt-get:
sudo apt-get update
安装sysv-rc-conf:
sudo apt-get install sysv-rc-conf -y
参考:https://blog.csdn.net/u013554213/article/details/86584705
systemctl:
ubuntu自从15.04版本以后都使用了systemd。Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。
参考:https://blog.csdn.net/philosophyatmath/article/details/88863136
参考:https://stackoverflow.com/questions/20680050/how-do-i-install-chkconfig-on-ubuntu
foobar表示伪变量。
打开服务:
systemctl start foobar
关闭服务:
systemctl stop foobar
重启服务:
systemctl restart foobar
不中断正常功能下重新加载服务:
systemctl reload foobar
设置服务的开机自启动:
systemctl enable foobar
关闭服务的开机自启动:
systemctl disable foobar
查看某个服务的状态:
systemctl status foobar
查看已启动的服务列表:
systemctl list-unit-files|grep enabled
查看活跃的单元:
systemctl list-units
查看启动失败的服务列表:
systemctl --failed
【远程桌面:xfce(推荐)】
https://www.codenong.com/f-install-xfce-desktop-xubuntu/
sudo apt install xrdp sudo apt install xfce4
开启端口:
firewall-cmd --zone=public --add-port=3389/tcp --permanent firewall-cmd --zone=public --add-port=22/tcp --permanent firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent
重新加载:
service firewalld start service firewalld reload firewall-cmd --zone=public --list-ports
【远程桌面:lxde】
参考:https://www.jianshu.com/p/4befb190c94b
参考:https://www.jianshu.com/p/daba3fd81786
sudo apt-get install lxde sudo apt-get install xrdp
打开 Windows 附件自带的远程桌面连接:
参考:https://jingyan.baidu.com/article/cbcede07ce04ee02f40b4d08.html
1. 按 Windows键 + R ,在运行中输入 mstsc
2. 在远程桌面登录框中输入 IP 地址和 Ubuntu 系统的用户名,点击连接,输入密码。
如果无法连结远程桌面:
方案1:关闭防火墙
ufw disable
方案2:配置安全规则
因为没有配置安全规则。添加入出口端口后就行了。
参考:https://blog.csdn.net/blank_tt/article/details/90759891
安全组》配置规则》添加安全组规则
规则方向:入方向
授权策略:允许
协议类型:自定义TCP
端口范围:3389
授权对象:0.0.0.0
之后,在桌面连接中输入凭据即可。
Ubuntu系统缺少中文字体支持时,会出现乱码。
【安装】
1. 安装开源中文字体:
sudo apt install fonts-wqy-zenhei fonts-wqy-microhei fonts-arphic-ukai fonts-arphic-uming
2. 安装中文语言包:
sudo apt install language-pack-zh-hans
3. 配置系统语言,在界面中选择 zh_CN.UTF-8 :
sudo dpkg-reconfigure locales
4. 刷新字体缓存,让系统识别新字体:
sudo fc-cache -fv
5. 重启终端。
6. 安装中文输入法
安装输入法框架和中文引擎:
sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-config-qt fcitx5-configtool
设置系统输入法为 fcitx5:
im-config -n fcitx5
参考:https://www.cnblogs.com/wzzkaifa/p/19080713
【卸载】
把 Ubuntu 服务器的默认语言和字体改为 en_US 是对的,因为服务器本身通常不涉及图形界面或中文显示,用 en_US.UTF-8 能避免很多不必要的编码问题,也更方便搜索英文报错信息。
虽然你提到“字体”,但 Linux 服务器核心的“语言环境”是由 locale 控制的,它决定了系统如何显示字符、编码和消息。服务器一般不需要安装字体,只需把 locale 设为 en_US.UTF-8 即可。
操作步骤
1. 生成并设置 locale
Ubuntu 服务器默认可能没有生成 en_US.UTF-8,需要先确保它存在,再设为默认。
# 检查是否已有 en_US.UTF-8
locale -a | grep en_US.utf8
# 如果没有,直接生成它
sudo locale-gen en_US.UTF-8
# 将系统默认 locale 设为 en_US.UTF-8
sudo update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
这里用 LC_ALL 是为了确保所有子类别都统一为英文,避免部分消息仍为中文的情况。
2. 让设置生效
update-locale 修改的是配置文件,对当前已登录的 shell 不会立即生效。可以选择其中一种:
- 重新登录(推荐):退出 SSH 再连一次,最简单可靠。
- 临时切换:如果不想断开会话,手动 export 一下:
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8
3. 验证
重新登录或 export 后,运行:
locale
应该看到所有 LC_* 和 LANG 都显示为 en_US.UTF-8,没有报错或乱码。
补充说明
- 关于“字体”:在无图形界面的服务器上,终端显示的字体是由你本地 SSH 客户端决定的,服务器端不管理字体。你只需要在本地终端软件(如 SecureCRT、PuTTY、Windows Terminal)里把字符编码设为 UTF-8,并选一个支持等宽英文的字体即可。
- 不要用
dpkg-reconfigure locales:它会弹出交互式全屏选择界面,在服务器上操作反而麻烦。直接用locale-gen+update-locale更简洁。 LC_ALL的影响:把LC_ALL也设为en_US.UTF-8后,系统日志、程序输出都会变成英文。如果你习惯看中文日志,可以只设LANG,不设LC_ALL,但那样部分消息可能仍是中文。
执行完后,用 locale 确认一下,如果所有项都指向 en_US.UTF-8,就说明改好了。