冷月蔷薇 發表於 2024-7-11 14:40:00

Ubuntu 24.04 安装配置

<h1 id="ubuntu-2404-安装配置">Ubuntu 24.04 安装配置</h1>
<h2 id="1安装基本优化">1、安装基本优化</h2>
<h3 id="11-关闭cloud-init进程">1.1 关闭cloud-init进程</h3>
<p>cloud init进程在云计算中,开机的时候会去访问一个固定的IP地址,来获取主机的元数据信息,比如初始化的脚本,重置操作系统密码等功能。单独装不需要可以关闭。</p>
<pre><code class="language-bash">echo 'network: {config: disabled}' &gt; /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

systemctl stop cloud-init.service
systemctl disable cloud-init.service
</code></pre>
<h3 id="12-修改ip">1.2 修改IP</h3>
<pre><code class="language-bash">cat /etc/netplan/50-cloud-init.yaml
network:
version: 2
renderer: networkd
ethernets:
    ens160:   # 替换为实际的网卡名称
      dhcp4: no
      addresses:
      - 192.168.21.242/24
      routes:
      - to: default
          via: 192.168.21.1
      nameservers:
      addresses:
          - 223.5.5.5
          - 8.8.8.8

# 应用配置
netplan apply

systemctl restart systemd-networkd
</code></pre>
<h3 id="13-关闭防火墙">1.3 关闭防火墙</h3>
<pre><code class="language-bash">systemctl stop ufw.service
systemctl disable ufw.service
</code></pre>
<h3 id="14-设置时间同步">1.4 设置时间同步</h3>
<p>修改24h格式时间。</p>
<pre><code class="language-bash">echo 'LC_TIME=en_DK.UTF-8' &gt;&gt; /etc/default/locale

</code></pre>
<pre><code class="language-bash">systemd-analyze cat-config systemd/timesyncd.conf

# 修改24h制
echo 'LC_TIME=en_DK.UTF-8' &gt;&gt; /etc/default/locale

vim /etc/systemd/timesyncd.conf

NTP=ntp1.aliyun.com
FallbackNTP=ntp.ubuntu.com # 主失效,备用源
RootDistanceMaxSec=5       # 与主服务器最大差距,大于会摒弃掉
PollIntervalMinSec=32      # 向 NTP 服务器发送同步请求的最短时间间隔
PollIntervalMaxSec=2048    # 服务器发送同步请求的最长时间间隔
ConnectionRetrySec=30
SaveIntervalSec=60

timedatectl set-ntp true
timedatectl set-timezone Asia/Shanghai

timedatectl status

# 服务会在不用的时候自动结束
systemctl start systemd-timedated.service
</code></pre>
<h3 id="15-安装常用软件包">1.5 安装常用软件包</h3>
<pre><code class="language-bash">apt update
apt -y install bash-completion vim wget lvm2 unzip net-tools dnsutils sysstat rsync inetutils-pingpartedlrzsz
</code></pre>
<h3 id="16-修改问价打开数">1.6 修改问价打开数</h3>
<pre><code class="language-bash">cat &gt; /etc/security/limits.conf &lt;&lt;EOF
* soft noproc 65535
* hard noproc 65535

* soft nofile 65535
* hard nofile 65535
EOF
</code></pre>
<pre><code class="language-bash">echo 'ulimit -SHn 65535' &gt;&gt; /etc/profile

ulimit -n 65535
ulimit -u 65536
</code></pre>
<h3 id="17-内核优化">1.7 内核优化</h3>
<pre><code class="language-bash">cat&gt;&gt;/etc/sysctl.conf&lt;&lt;EOF
# 缓存优化
vm.swappiness=0

# tcp优化
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_max_syn_backlog=16384
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_fin_timeout=10

net.ipv4.tcp_keepalive_time=600
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=3

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_announce=2
net.ipv4.conf.all.arp_announce=2
net.ipv4.ip_local_port_range=1024 65000

net.ipv4.ip_forward=1
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_synack_retries=2

net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.netfilter.nf_conntrack_max=2310720
net.ipv6.neigh.default.gc_thresh1=8192
net.ipv6.neigh.default.gc_thresh2=32768
net.ipv6.neigh.default.gc_thresh3=65536
net.core.netdev_max_backlog=16384
net.core.rmem_max=16777216
net.core.wmem_max=16777216

net.core.somaxconn = 32768
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=524288
fs.file-max=52706963
fs.nr_open=52706963
kernel.pid_max = 4194303
net.bridge.bridge-nf-call-arptables=1

vm.overcommit_memory=1
vm.panic_on_oom=0
vm.max_map_count=262144
EOF

sysctl -p
</code></pre>
<h2 id="2系统管理">2、系统管理</h2>
<h3 id="21-查看发行版本">2.1 查看发行版本</h3>
<pre><code class="language-bash"># 查看发行版本
lsb_release -a
</code></pre>
<h3 id="22-包管理">2.2 包管理</h3>
<pre><code class="language-bash"># 查看已安装所有的包
dpkg -l

# 查看包有关的文件
dpkg -L openssh-server
</code></pre>
<h3 id="23-查看包的所有可用版本">2.3 查看包的所有可用版本</h3>
<pre><code class="language-bash">apt-cache policy kubectl
apt-cache madison docker-ce
</code></pre><br><br>
来源:https://www.cnblogs.com/gshelldon/p/18296165
頁: [1]
查看完整版本: Ubuntu 24.04 安装配置