centos 7 使用pyenv 安装 python 3 出现“ModuleNotFoundError: No module named ‘_ctypes’”的问题解决

 python  centos 7 使用pyenv 安装 python 3 出现“ModuleNotFoundError: No module named ‘_ctypes’”的问题解决已关闭评论
10月 232019
 

centos 7 下使用pyenv 安装python 3.7时错误如下;

Downloading Python-3.7.4.tar.xz…
-> https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
Installing Python-3.7.4…

BUILD FAILED (CentOS Linux 7 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20191023165632.13343
Results logged to /tmp/python-build.20191023165632.13343.log

Last 10 log lines:
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py”, line 12, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py”, line 6, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py”, line 6, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py”, line 20, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py”, line 37, in <module>
File “/tmp/tmpgvoc4sao/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py”, line 3, in <module>
File “/tmp/python-build.20191023165632.13343/Python-3.7.4/Lib/ctypes/__init__.py”, line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named ‘_ctypes’
make: *** [install] Error 1

 

解决方法如下:

  1. 先安装: yum install libffi-devel -y
  2. 再安装python: pyenv install 3.7.4

DONE!

如果安装成功后有WARNING提示:

WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?

为避免后续使用中问题,可进一步安装其它依赖包

yum install readline readline-devel readline-static -y

yum install sqlite-devel -y

yum install bzip2-devel bzip2-libs -y

yum install openssl openssl-devel openssl-static -y

OK!!

云服务器EC2配置Swap分区解决Cannot Allocate Memory

 centos  云服务器EC2配置Swap分区解决Cannot Allocate Memory已关闭评论
9月 192019
 

今天在EC2(Centos 7)上使用nvm 安装node时出现下面错误提示:

# nvm install 8.16.1
Downloading and installing node v8.16.1…
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1-linux-x64.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Binary download failed, trying source.
Downloading https://nodejs.org/dist/v8.16.1/node-v8.16.1.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
xz: (stdin): Cannot allocate memory
tar: Child returned status 1
tar: Error is not recoverable: exiting now
nvm: install v8.16.1 failed!

这台EC2内存只有1G,看来需要配个交换分区。

 

步骤

# 创建一个全0填充的2GB文件。InputFile利用Linux系统的/dev/zero。bs是BlockSize。

sudo dd if=/dev/zero of=/mnt/2GB.swap bs=1M count=2048

 

# 把该文件格式化为Swap文件

sudo mkswap /mnt/2GB.swap

 

# 把该Swap文件挂载为Swap分区

sudo swapon /mnt/2GB.swap

 

# 检查是否成功挂载。Swap那一行现在就不是0了。

$ free -m

total        used        free      shared  buff/cache   available

Mem:            963         677          74          78         211          52

Swap:          2047          84        1963

# 配置fstab,使开机时自动挂载Swap文件为Swap分区

sudo vim /etc/fstab

 

# 在/ect/fstab中添加

/mnt/2GB.swap none swap sw 0 0

 

centos 7 升级内核 安装 BBR

 bbr  centos 7 升级内核 安装 BBR已关闭评论
3月 272019
 

BBR介绍

Google BBR (Bottleneck Bandwidth and RTT) 是一种新的TCP拥塞控制算法,它可以高效增加吞吐和降低网络延迟,并且Linux Kernel4.9+已经集成该算法。开启BBR也非常简单,因为它只需要在发送端开启,网络其他节点和接收端不需要任何改变。

升级内核

1. 打开Terminal

输入

# uname -r 

查看内核版本,如果输出类似

3.10.0-514.21.2.el7.x86_64

则表示小于4.9,需要升级内核,
而如果内核大于等于4.9则跳过至开启Google BBR

2. 升级内核

  • 安装 ELRepo 仓库

    # rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org # rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm 
  • 安装最新版kernel

    # yum --enablerepo=elrepo-kernel install kernel-ml -y 
  • 确认是否安装成功

    # rpm -qa | grep kernel 

    如果输出类似如下,包含kernel-ml-4.13.10-1.el7.elrepo.x86_64,则表示安装成功

    kernel-3.10.0-693.el7.x86_64
    kernel-tools-3.10.0-693.el7.x86_64
    kernel-ml-4.13.10-1.el7.elrepo.x86_64
    kernel-tools-libs-3.10.0-693.el7.x86_64

  • 设置开机默认启动项

    # egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \' 

    输出结果类似如下

    CentOS Linux 7 Rescue f212d2d7754a4a6bb2b98950c20cc0b5 (4.13.10-1.el7.elrepo.x86_64)
    CentOS Linux (4.13.10-1.el7.elrepo.x86_64) 7 (Core)
    CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
    CentOS Linux (0-rescue-d1f142097d497f24c021d7de9b81cab4) 7 (Core)

    该列表从0开始索引,所以4.13内核索引为1

  • 设置启动项

    # grub2-set-default 1 
  • 重启

    # reboot 

    查看内核版本

    # uname -r 

    如果输出类似

    4.13.10-1.el7.elrepo.x86_64

    则表示升级完成

开启Google BBR

  • 修改sysctl配置

    # echo 'net.core.default_qdisc=fq' | tee -a /etc/sysctl.conf # echo 'net.ipv4.tcp_congestion_control=bbr' |  tee -a /etc/sysctl.conf # sysctl -p 
  • 检查是否加载BBR

    # lsmod | grep bbr 

    如果输出结果包含tcp_bbr,则表示开启成功

    tcp_bbr 20480 0

转自:https://www.jianshu.com/p/52815c34215e