每次的从头配置是最烦的(然而已经习惯了都

0x00.前言

还记得“续……”吗?

1
[root@localhost ~]# rpm -q centos-release
2
centos-release-7-7.1908.0.el7.centos.x86_64

0x01.配置

1. 查看IP

搁这VNC?里干一件事情就足够了,就再也不用进来了(grub除外

1
yum install net-tools -y

意外发现了镜像地址是neusoft,还真是最近的hhh

记下 ipv4 地址
记下 ipv4 地址

然后就可以回到日常使用的XShell了(妙
注:还不确定设定静态ip会不会有影响(其实是不会),所以就先不设了……

1
[root@localhost ~]# ip addr
2
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
3
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4
    inet 127.0.0.1/8 scope host lo
5
       valid_lft forever preferred_lft forever
6
    inet6 ::1/128 scope host 
7
       valid_lft forever preferred_lft forever
8
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
9
    link/ether 00:0c:29:28:a6:ad brd ff:ff:ff:ff:ff:ff
10
    inet 192.168.25.42/24 brd 192.168.25.255 scope global noprefixroute dynamic ens32
11
       valid_lft 603442sec preferred_lft 603442sec
12
    inet6 <rm> scope global noprefixroute dynamic 
13
       valid_lft 5844sec preferred_lft 2244sec
14
    inet6 <rm> scope global noprefixroute dynamic 
15
       valid_lft 6964sec preferred_lft 3364sec
16
    inet6 <rm> scope link noprefixroute 
17
       valid_lft forever preferred_lft forever
18
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
19
TYPE="Ethernet"
20
PROXY_METHOD="none"
21
BROWSER_ONLY="no"
22
BOOTPROTO="dhcp"
23
DEFROUTE="yes"
24
IPV4_FAILURE_FATAL="no"
25
IPV6INIT="yes"
26
IPV6_AUTOCONF="yes"
27
IPV6_DEFROUTE="yes"
28
IPV6_FAILURE_FATAL="no"
29
IPV6_ADDR_GEN_MODE="stable-privacy"
30
NAME="ens32"
31
UUID="9e2d678d-9e9b-48b3-a8d5-9ea7baa81c39"
32
DEVICE="ens32"
33
ONBOOT="yes"
34
[root@localhost ~]#

就先BOOTPROTO="dhcp"好了

2. 修改主机名

1
[root@localhost ~]# hostnamectl set-hostname py.yuangezhizao.cn
2
[root@localhost ~]# cat /etc/hosts
3
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
5
[root@localhost ~]# vi /etc/hosts
6
[root@localhost ~]# cat /etc/hosts
7
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 py.yuangezhizao.cn py.yuangezhizao.cn
8
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 py.yuangezhizao.cn py.yuangezhizao.cn
9
[root@localhost ~]#

3. 安装常用软件

yum update -y
yum install vim git wget -y

yum install epel-release -y
yum install htop axel -y

0x02.编译安装python380环境

  1. 查看现有位置

    1
    [root@py ~]# whereis python
    2
    python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
  2. 安装编译工具

    1
    yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel

    这里面有一个包很关键libffi-devel,因为只有3.7才会用到这个包,如果不安装这个包的话,在make阶段会出现如下的报错:# ModuleNotFoundError: No module named '_ctypes'

  3. 下载源码包

    1
    wget --no-check-certificate https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
    下载卡爆,proxy 中转爽到!
    下载卡爆,proxy 中转爽到!
  4. 解压

    1
    tar xvJf Python-3.8.0.tar.xz 
    2
    cd Python-3.8.0
  5. 编译

    1
    sudo ./configure --prefix=/usr/local/python3
    2
    sudo make && make install
    全新路径
    全新路径
  6. 修改默认为Python 3
    /usr/bin中的python备份,然后创建python3的软链接,这样默认的Python版本就替换为Python 3

    1
    [root@py ~]# sudo mv /usr/bin/python /usr/bin/python.bak
    2
    [root@py ~]# sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python
    3
    [root@py ~]# python
    4
    Python 3.8.0 (default, Nov  7 2019, 22:54:02) 
    5
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
    6
    Type "help", "copyright", "credits" or "license" for more information.
    7
    >>> exit()

    这样做在使用yum的时候会出现bug,需要自行修复……

    1
    [root@py bin]# cd ~
    2
    [root@py ~]# yum update -y
    3
      File "/usr/bin/yum", line 30
    4
        except KeyboardInterrupt, e:
    5
                                ^
    6
    SyntaxError: invalid syntax
    7
    [root@py ~]#
  7. 创建软链接(python3&pip3

    1
    [root@txy ~]# sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    2
    [root@txy ~]# sudo ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
    3
    4
    [root@txy ~]# python -V
    5
    Python 2.7.5
    6
    [root@txy ~]# python2 -V
    7
    Python 2.7.5
    8
    [root@txy ~]# python3 -V
    9
    Python 3.8.0
    10
    11
    [root@py ~]# pip -V
    12
    -bash: pip: command not found
    13
    [root@py ~]# pip2 -V
    14
    -bash: pip2: command not found
    15
    [root@py ~]# pip3 -V
    16
    pip 19.3.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)

    这样就可以通过python/python2命令使用Pythonpython3来使用Python 3

  8. 升级pip3

    1
    [root@py Python-3.8.0]# cd /usr/local/python3/bin
    2
    [root@py bin]# ./pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
    3
    Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
    4
    Collecting pip
    5
      Downloading https://pypi.tuna.tsinghua.edu.cn/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
    6
         |████████████████████████████████| 1.4MB 1.0MB/s 
    7
    Installing collected packages: pip
    8
      Found existing installation: pip 19.2.3
    9
        Uninstalling pip-19.2.3:
    10
          Successfully uninstalled pip-19.2.3
    11
    Successfully installed pip-19.3.1
    12
    [root@py bin]# ./pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    13
    Writing to /root/.config/pip/pip.conf

0x03.git配置

1
git config --global user.name "yuangezhizao-serveraccount"
2
git config --global user.email yuangezhizao@gmail.com
3
git commit --amend --reset-author
4
5
git config --global credential.helper store

0x04.NTP配置

网络时间协议(Network Time Protocol,NTP),用于同步网络中各个计算机的时间的协议。其用途是将计算机的时钟同步到世界协调时UTC。在NTP设计时考虑到了各种网络延迟,当您通过公共网络同步时,误差可以降低到10毫秒以内;当您通过本地网络同步时,误差可以降低到1毫秒
腾讯云提供了内网NTP服务器供腾讯云内网设备使用,对于非腾讯云设备,可以使用腾讯云提供的公网NTP服务器

NTPD(Network Time Protocol daemon)Linux操作系统的一个守护进程,用于校正本地系统与时钟源服务器之前的时间,完整的实现了NTP协议。NTPDNTPDate的区别是NTPD是步进式的逐渐校正时间,不会出现时间跳变,而NTPDate是断点更新

公网好评
公网好评

安装NTPD
yum -y install ntp
配置NTP
vim /etc/ntp.conf

修改
修改
1
# Use public servers from the pool.ntp.org project.
2
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
3
# server 0.centos.pool.ntp.org iburst
4
# server 1.centos.pool.ntp.org iburst
5
# server 2.centos.pool.ntp.org iburst
6
# server 3.centos.pool.ntp.org iburst
7
server time1.cloud.tencent.com
8
server time2.cloud.tencent.com
9
server time3.cloud.tencent.com
10
server time4.cloud.tencent.com
11
server time5.cloud.tencent.com

运行NTPD并自启

1
[root@py ~]# rpm -qa | grep ntp
2
ntpdate-4.2.6p5-29.el7.centos.x86_64
3
ntp-4.2.6p5-29.el7.centos.x86_64
4
fontpackages-filesystem-1.44-8.el7.noarch
5
[root@py ~]# systemctl restart ntpd.service
6
[root@py ~]# systemctl enable ntpd.service
7
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

查看NTP服务端口UDP 123端口是否被正常监听

1
[root@py ~]# netstat -nupl
2
Active Internet connections (only servers)
3
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
4
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1069/dhclient       
5
udp        0      0 192.168.25.42:123       0.0.0.0:*                           77501/ntpd          
6
udp        0      0 127.0.0.1:123           0.0.0.0:*                           77501/ntpd          
7
udp        0      0 0.0.0.0:123             0.0.0.0:*                           77501/ntpd          
8
udp6       0      0 240e:<rm>::123 :::*                                77501/ntpd          
9
udp6       0      0 fe80::<rm>:123 :::*                                77501/ntpd          
10
udp6       0      0 240e:<rm>::123 :::*                                77501/ntpd          
11
udp6       0      0 ::1:123                 :::*                                77501/ntpd          
12
udp6       0      0 :::123                  :::*                                77501/ntpd          
13
udp6       0      0 fe80::<rm>:546 :::*                                1595/dhclient

查看NTPD状态

1
[root@py ~]# service ntpd status
2
Redirecting to /bin/systemctl status ntpd.service
3
● ntpd.service - Network Time Service
4
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
5
   Active: active (running) since Thu 2019-11-07 23:18:57 CST; 16s ago
6
  Process: 77500 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
7
 Main PID: 77501 (ntpd)
8
   CGroup: /system.slice/ntpd.service
9
           └─77501 /usr/sbin/ntpd -u ntp:ntp -g
10
11
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 2 lo 127.0.0.1 UDP 123
12
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 3 ens32 192.168.25.42 UDP 123
13
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 4 lo ::1 UDP 123
14
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 5 ens32 240e:<rm>:...123
15
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 6 ens32 fe80::<rm>...123
16
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listen normally on 7 ens32 240e:<rm>...123
17
Nov 07 23:18:57 py.yuangezhizao.cn ntpd[77501]: Listening on routing socket on fd #24 for interface...tes
18
Nov 07 23:18:58 py.yuangezhizao.cn ntpd[77501]: 0.0.0.0 c016 06 restart
19
Nov 07 23:18:58 py.yuangezhizao.cn ntpd[77501]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
20
Nov 07 23:18:58 py.yuangezhizao.cn ntpd[77501]: 0.0.0.0 c011 01 freq_not_set
21
Hint: Some lines were ellipsized, use -l to show in full.

查看NTP是否正常启动以及是否配置到正确的NTP时钟源服务器:输出当前NTP时钟源服务器的IP地址,此IP地址应为上述配置的NTP时钟源服务器的IP地址

1
[root@py ~]# ntpstat
2
unsynchronised
3
  time server re-starting
4
   polling server every 8 s

获取更详细的NTP服务信息

1
[root@py ~]# ntpq -p
2
     remote           refid      st t when poll reach   delay   offset  jitter
3
==============================================================================
4
 139.199.215.251 100.122.36.4     2 u   32   64    1   57.452   -1.940   0.000
5
 111.230.189.174 100.122.36.196   2 u   32   64    1   59.803   -1.716   0.000
6
 139.199.214.202 100.122.36.4     2 u   31   64    1   57.946    0.590   0.000
7
 134.175.254.134 100.122.36.4     2 u   31   64    1   57.897   -2.392   0.000
8
 134.175.253.104 100.122.36.4     2 u   32   64    1   59.239   -0.167   0.000

过了一会儿重新来看

1
[root@py ~]# ntpstat
2
synchronised to NTP server (134.175.254.134) at stratum 3
3
   time correct to within 45 ms
4
   polling server every 64 s
5
[root@py ~]# ntpq -p
6
     remote           refid      st t when poll reach   delay   offset  jitter
7
==============================================================================
8
+139.199.215.251 100.122.36.196   2 u   71  128  377   56.945   -1.334   0.556
9
*111.230.189.174 100.122.36.196   2 u   53  128  377   59.046    1.035   1.348
10
-139.199.214.202 100.122.36.4     2 u   52  128  377   57.424    3.607   0.707
11
-134.175.254.134 100.122.36.196   2 u  193  128  376   57.452    2.038   0.768
12
+134.175.253.104 100.122.36.196   2 u  126  128  377   58.659   -0.204   0.623

然后顺便去看了眼txy机子

1
[root@txy bt]# ntpq -p
2
     remote           refid      st t when poll reach   delay   offset  jitter
3
==============================================================================
4
*10.237.208.123  100.122.36.196   2 u  861 1024  377   32.771    0.215   0.555

0x04.引用

ifconfig命令不存在command not found
Linux 实例设置 NTP 服务

未完待续……