ubuntu服务器配置
防火墙
# 查看服务器防火墙状态 ufw status
# 将防火墙设置为可用状态 ufw enable
# 将防火墙设置为关闭状态 ufw disbale
# 放行端口 ufw allow 22
# 指定ip为192.168.1.1的计算机操作所有端口 ufw allow from 192.168.1.1
# 开放指定ip为192.168.1.2的计算机访问本机的3306端口 ufw allow from 192.168.1.2 to any port 3306
# 重启防火墙,使配置生效 ufw reload
# 关闭端口 ufw delete allow 21
# 查看编号 ufw status numbered
# 删除编号 ufw delete 4
# 重置防火墙ufw reset
常用命令
-
系统命令
- 查看已安装的软件相关软件包:dpkg =l|grep ‘php’
-
网卡
- 重启网卡:sudo service networking restart
- ubuntu 闭关无线网卡
在Ubuntu系统中,可以通过命令行来关闭无线网卡。以下是一个简单的方法,使用rfkill命令来管理无线设备。
查看所有设备的状态,包括无线设备:rfkill list all
关闭无线网卡:rfkill block wifi
打开无线网卡:rfkill unblock wifi - ubuntu修改IP地址
在Ubuntu中修改IP地址,您可以通过命令行界面使用netplan或nmtui工具。以下是使用netplan的方法:找到配置文件,通常在/etc/netplan/目录下。文件名可能是01-netcfg.yaml,50-cloud-init.yaml或类似。修改配置以设置静态IP或其他网络设置。
例如,设置静态IP的配置可能如下所示:
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
dhcp4: no
addresses:
– 192.168.1.10/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4] 保存文件并应用配置:sudo netplan apply
-
网络相关
- netstat -tuln | grep :80
-
休眠
- 查看休眠状态:systemctl status sleep.target
- 关闭休眠功能:sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
-
查看版本号:lsb_release -a
- Ubuntu systemd 禁止服务自启动
- # 停止软件
sudo systemctl stop runsunloginclient.service
# 禁止开机自启动
sudo systemctl disable runsunloginclient.service - # 禁止开机启动
systemctl disable xxxx.service
# 开机启动
systemctl enable xxxx.service
# 查看状态
systemctl is-enabled xxxx.service
# 启动/停止
systemctl start/stop xxxx.service
- # 停止软件
- 1
安装后配置
-
设置root密码
- :sudo passwd root
-
journald CPU 占用率高
- 停止服务sudo systemctl stop systemd-journald systemd-journald-dev-log.socket systemd-journald.socket systemd-journald-audit.socket
- 禁止自启动:sudo systemctl disable systemd-journald
-
如何解决dbus-daemon占用cpu
Ubuntu 是一个基于 Linux 的操作系统,而 dbus-daemon 是 D-Bus 消息总线系统的核心守护进程,它负责在 D-Bus 系统中管理应用程序之间的通信。不建议删除 dbus-daemon,因为这可能会导致系统不稳定甚至无法启动图形用户界面。dbus-daemon 是 Ubuntu 系统启动时自动启动的重要服务,它负责系统消息的传递,包括启动应用程序、监听系统事件等。
停止 dbus-daemon 服务:sudo systemctl stop dbus
禁用:sudo systemctl disable dbus
删除 dbus-daemon:sudo apt-get remove dbus-daemon - 112
- 23
-
如何解决systemd-logind占用cpu
发现服务器上systemd-logind导致cpu 100%的问题,使得登录异常缓慢,并且消耗资源。
1.systemd-logind主要功能是为每一个登陆session创建一个systemd角度的cgroup管理对象,更方便对session使用cgroup,在实际场景中没有什么用处,关闭不会影响正常ssh登陆
2.在有crond任务时,触发systemd-logind回收不及时的bug
3.闭systemd-logind
systemctl stop systemd-logind
systemctl disable systemd-logind
常用工具
- 安装apt install net-tools可使用ifconfig查看ip
ubuntu 安装指定版本mysql
在Ubuntu上安装指定版本的MySQL,你可以使用APT(高级包装工具)来完成。以下是安装指定版本MySQL的步骤:
更新APT的包索引:
sudo apt update
查找可用的MySQL版本:
apt list -a mysql-server
安装指定版本的MySQL服务器,替换<version>为你想要安装的版本号:
sudo apt install mysql-server=<version>
例如,如果你想要安装MySQL 5.7,你可以使用以下命令:
sudo apt install mysql-server=5.7.*
VIM配置
/etc/vim/vimrc 5534840
syntax on ” Set syntax highlighting
set number ” Set the line number
set tabstop=4 ” Set an indent to account for 4 spaces
set autoindent ” Set up automatic indentation
set mouse=a ” Set mouse is always available, set mouse= (empty) cancel
set cc=80 ” Column 80 highlighted, set cc=0 cancellation
set cursorline ” Settings to highlight the current row
set cindent ” Format C language
set st=4 ” Set the width of the soft tab to 4 spaces
set shiftwidth=4 ” The width automatically indented when setting a new line is 4 spaces
set sts=4 ” Set the number of spaces inserted when the Tab key is pressed in insertion mode to 4
set ruler ” Show the status of the last line
set showmode ” The status of this row is displayed in the lower left corner.
set bg=dark ” Show different background tones
set hlsearch ” Enable Search Highlight
set laststatus=2 ” Always display the status bar
set ignorecase #大小写
ubuntu笔记本合上盖子不休眠设置
- 修改配置:sudo sed -i ‘s/#HandleLidSwitch=suspend/HandleLidSwitch=ignore/g’ /etc/systemd/logind.conf
- 重启服务:systemctl restart systemd-logind
允许root用户远程登录
/etc/ssh/sshd_config
PermitRootLogin yes
创建管理员账号
sudo adduser username
sudo usermod -aG sudo username
DDNS-GO
https://github.com/jeessy2/ddns-go/releases
如何在ubuntu服务器上禁用ipv6
来源:有益网络时间:2023-08-17阅读:17824次
在众多Linux服务器操作中,禁用IPv6可能是一项常见的需求。本文将详细指导您如何在Ubuntu服务器上彻底禁用IPv6。不管您是新手还是资深用户,只需按照以下简单步骤,即可顺利完成。前言:操作前建议备份相关文件,以防止误操作导致的不必要的麻烦。
步骤1:使用Sysctl命令禁用IPv6
查看IPv6状态:打开终端,输入 ip a 查看是否启用了IPv6。
暂时禁用IPv6:输入以下命令,临时禁用IPv6:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
3. 持久化禁用IPv6:为了确保每次开机都自动禁用IPv6,需要修改/etc/sysctl.conf配置文件。可以选择您熟悉的编辑器(如vim、nano)进行编辑,并加入以下内容:
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
然后保存并退出。再次执行sudo sysctl -p使设置生效。
步骤2:使用GRUB禁用IPv6
编辑GRUB配置:使用您喜欢的编辑器打开/etc/default/grub文件,并找到GRUB_CMDLINE_LINUX_DEFAULT和GRUB_CMDLINE_LINUX条目。
修改配置:将这两个条目修改为:
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash ipv6.disable=1″
GRUB_CMDLINE_LINUX=”ipv6.disable=1″
3. 更新GRUB:保存文件后,运行sudo update-grub命令以应用新配置。
Wordpress
- 要执行请求的操作,WordPress 需要访问您网页服务器的权限。
解决方式:登录远程服务器,将这个wordpress站点的用户权交给www-data 然后提升权限就可以了。
sudo chown-R www-data /var/www/wordpress sudo
chmod 775 /var/www/wordpress
- qw
- 2