Pear Admin二次开发之linux系统基本配置

本篇继上篇《Pear Admin二次开发之linux系统安装》完成Linux系统基本设置。
Centos7 采用Mini模式安装完毕后,需要对Linux系统做些基本设置,比如IP地址设置、安装anaconda虚拟环境、防火墙基本设置等。

IP地址设置

Centos7系统默认的网卡配置文件存放在/etc/sysconfig/network-scripts/ifcfg-xxx,下面通过编辑网卡配置文件完成ip地址、子网掩码、网关、dns等内容设置。
vi /etc/sysconfig/network-scripts/ifcfg-ens33

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=51e16773-8bc5-453c-8c9f-a84921c56e19
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.11.200
NETMASK=255.255.255.0
GATEWAY=1921.68.11.2
DNS1=114.114.114.114
DNS2=8.8.8.8

编辑好配置文件后,重启网络服务,使配置生效。

[root@localhost ~]# service  network restart
Restarting network (via systemctl):                        [  OK  ]
[root@localhost ~]# 

可以使用ip addr验证配置网卡的配置信息。

[root@localhost ~]#  ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:27:c5:4f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.200/24 brd 192.168.1.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe27:c54f/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# 
[root@localhost ~]# ping www.baidu.com
PING www.baidu.com (110.242.69.21) 56(84) bytes of data.
64 bytes from 110.242.69.21 (110.242.69.21): icmp_seq=1 ttl=128 time=16.2 ms
64 bytes from 110.242.69.21 (110.242.69.21): icmp_seq=2 ttl=128 time=15.5 ms
64 bytes from 110.242.69.21 (110.242.69.21): icmp_seq=3 ttl=128 time=16.9 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 15.575/16.255/16.971/0.589 ms
[root@localhost ~]# 

因为centos 7 min模式默认没有安装net-tool、wget、bind-client软件包,接下来挂在光盘安装软件包。

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/Packages/
[root@localhost Packages]# rpm -ivh net-tools-2.0-0.25.20131004git.el7.x86_64.rpm 
warning: net-tools-2.0-0.25.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:net-tools-2.0-0.25.20131004git.el################################# [100%]
[root@localhost Packages]# rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm 
warning: wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:wget-1.14-18.el7_6.1             ################################# [100%]

[root@localhost Packages]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.200  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe27:c54f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:c5:4f  txqueuelen 1000  (Ethernet)
        RX packets 1923  bytes 202004 (197.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 682  bytes 130921 (127.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
[root@localhost Packages]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1395/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2250/sshd           
tcp        0      0 192.168.1.200:22        192.168.1.112:63114     ESTABLISHED 2252/sshd: root@pts 
tcp6       0      0 ::1:25                  :::*                    LISTEN      1395/master         
tcp6       0      0 :::22                   :::*                    LISTEN      2250/sshd           
[root@localhost Packages]# 

关闭无用端口服务

25端口为邮件服务器端口我们并不需要,可以将其关闭并设置开机不启动。

[root@localhost Packages]# systemctl  disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@localhost Packages]# systemctl  stop postfix
[root@localhost Packages]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2250/sshd           
tcp        0     96 192.168.1.200:22        192.168.1.112:63114     ESTABLISHED 2252/sshd: root@pts 
tcp6       0      0 :::22                   :::*                    LISTEN      2250/sshd           
[root@localhost Packages]# 

开启root账户ssh登陆权限

为了方便远程登录该linux主机,设置sshd配置文件,允许root远程登录。

[root@localhost ~]# cat /etc/ssh/sshd_config | grep PermitRoot
PermitRootLogin yes

[root@localhost ~]# 
[root@localhost ~]# systemctl  restart sshd.service

安装mimiconda虚拟环境

下载安装mimiconda环境,后续可以为不同的开发需求设置独立的开发环境,相互隔离,互不影响。
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
指定安装路径并安装
bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda
设置环境变量
echo ‘export PATH=“/opt/miniconda/bin:$PATH”’ >> ~/.bashrc
source ~/.bashrc

[root@localhost ~]# wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
--2025-06-25 21:39:48--  https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.32.241, 104.16.191.158, 2606:4700::6810:20f1, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.32.241|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 159476510 (152M) [application/octet-stream]
Saving to: ‘Miniconda3-latest-Linux-x86_64.sh’

100%[=========================================================================>] 159,476,510 7.75MB/s   in 21s    

2025-06-25 21:40:10 (7.12 MB/s) - ‘Miniconda3-latest-Linux-x86_64.sh’ saved [159476510/159476510]

[root@localhost ~]# bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda
Unpacking payload ...
entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.
entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.

Installing base environment...

Preparing transaction: ...working... done
Executing transaction: ...working... done
entry_point.py:256: DeprecationWarning: Python 3.14 will, by default, filter extracted tar archives and reject files or modify their metadata. Use the filter argument to control this behavior.
installation finished.
[root@localhost ~]# echo 'export PATH="/opt/miniconda/bin:$PATH"' >> ~/.bashrc
[root@localhost ~]# 
[root@localhost ~]# source ~/.bashrc

指定国内conda源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --set show_channel_urls yes

关闭⾃动进⼊虚拟环境

conda init
conda config --set auto_activate_base false

到此基本环境已准备就绪。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

候鸟-南飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值