Linux编程环境常见坑及解决方案

一、PIP 踩坑 

Ubuntu 中pip 10 更新后常常出现执行错误,通过下面方式可修复并升级到最新版本:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py

二、Docker 踩坑 -- Docker常见问题及解决方法

1.kernel:unregister_netdevice:...

kernel:unregister_netdevice: waiting for lo to become free. Usage count = 1
这是个从 2014 年就出现了的老 BUG,不管是 RHEL、CentOS、Ubuntu 还是 Debian 都会碰到。这实际上是 Linux 内核的一个 BUG,目前仍未彻底解决,尽量升级最新的 Linux 内核吧。

2. Failed to get D-Bus connection:...

Failed to get D-Bus connection: Operation not permitted
在 Docker 中执行 systemctl 命令时触发这个错误,常见于使用 Systemd 的 Linux 发行版,比如 CentOS 7 全系列。

# systemctl start vsftpd

Failed to get D-Bus connection: Operation not permitted

2.1 解决方案

方案1. 官方解决方案

官方解决方案 是创建一个中间镜像,然后在这个镜像基础上构建你的镜像。

方案2. 避免使用 systemctl 命令

比如直接通过 /usr/sbin/sshd & (& 表示后台运行程序)来执行命令。

方案3. 开启特权模式

可以在创建容器时通过 --privileged=true 开启特权模式。

创建容器:

# docker run -d --name centos7 --privileged=true centos7:last /usr/sbin/init

进入容器:

# docker exec -it centos7 /bin/bash

这样可以使用 systemctl 启动服务了。

2.2 根本原因

Docker 的设计理念是将每个容器作为宿主机上一个独立的主进程运行,在容器内部不运行后台服务。容器的生命周期是围绕一个主进程存在,所以正确的使用容器方法是将里面的服务运行在前台。

systemd 是主流 Linux 发行版默认的服务管理程序,取代了传统的 SystemV 风格服务管理。systemd 维护系统服务程序,需要特权才能会访问 Linux 内核。而容器并不是一个完整的操作系统,只有一个文件系统,而且启动时默认使用普通用户权限访问 Linux 内核,自然用不了 systemd!

因此,请遵守容器设计原则,一个容器里运行一个前台服务!

3. 当遇到不能解决的问题时,记得用命令
docker stop $(docker ps -aq)
docker rm -f $(docker ps -aq)
docker network prune
清理你的Docker网络。这将会清除你之前的网络并且给你一个全新的环境:

三、防火墙

    查看:service iptables status 或/etc/init.d/iptables status
    开启:service iptables start
    关闭:service iptables stop
四、翻墙

1、安装python

linux下的shadowsocks是采用python开发,因此需要先安装python,如已经安装可以跳过此步骤。

使用以下命令安装python :

sudo apt-get install python 
安装python的包管理器pip:

sudo apt-get install python-pip 
2、安装shadowsocks客户端

安装python-pip后,能通过pip直接安装客户端

sudo pip install shadowsocks 
3、配置shadowsocks客户端配置

新建一个配置文件shawdowsocks.json,根据你的shadowsocks服务提供的参数,配置以下相应的参数: 

“server”: “111.111.111.111”, 
“server_port”: 443, 
“local_port”: 1080, 
“password”: “111111”, 
“timeout”: 600, 
“method”: “rc4-md5” 

4、启动shadowsocks客户端服务

通过以下命令:

sudo sslocal -c shawdowsocks.json -d start

5.但在linux下并不能直接通过上述设置翻墙,因为shawdowsocks是socks 5代理,需要客户端配合才能翻墙。

apt-get install privoxy

6.配置privoxy 
vi /etc/privoxy/config

1336 forward-socks5t / 127.0.0.1:1080 .

监听接口默认开启的 localhost:8118

7.启动privoxy 
//开启privoxy 服务就行 
sudo service privoxy start 
// 设置http 和 https 全局代理 
export http_proxy=’http://localhost:8118’ 
export https_proxy=’https://localhost:8118’ 
test : 
wget www.google.com 
如果把返回200 ,并且把google的首页下载下来了,那就是成功了


猜你喜欢

转载自blog.csdn.net/sinat_34070003/article/details/80028635