Debian 6(Squeeze)升级至Debian 7(Wheezy)

Debian GNU/Linux支持滚动更新,出于安全方面的考虑,当新版Debian发行后,我们一般会将现有版本的Debian升级至最新的稳定版的Debian。升级除了可以提升系统的安全性以外,同时还可以获得由更新版本的应用软件带来的新功能及其它好处。这就是我们为什么要将Debian 6(Squeeze)升级至Debian 7(Wheezy)的原因。

1. 编辑/etc/apt/source.list文件

编辑/etc/apt/source.list文件,将文件中的squeeze全部换成wheezy即可,之后查看/etc/apt/source.list文件,其内容应大致如下:

1
2
3
4
5
6
7
8
9
10
cat /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ wheezy main
deb-src http://ftp.us.debian.org/debian/ wheezy main

deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main

wheezy-updates, previously known as 'volatile'
deb http://ftp.us.debian.org/debian/ wheezy-updates main
deb-src http://ftp.us.debian.org/debian/ wheezy-updates main

2.更新软件包列表

1
apt-get update

如果更新软件包列表时,提示:
W: There is no public key available for the following key IDs:
8B48AD6246925553
则需要导入Debian 7(Wheezy)的Archive Keys。

Debian Archive Signing Keys下载页面:http://ftp-master.debian.org/keys.html

1
2
wget http://ftp-master.debian.org/keys/archive-key-7.0.asc
apt-key add archive-key-7.0.asc

之后重新更新软件包列表就不会提示该警告了。

1
apt-get update

3.更新最小化的基本系统

1
apt-get upgrade

4.升级剩下的系统

1
apt-get dist-upgrade

5.重启系统

1
reboot

6.验证系统

1
2
lsb_release -a
cat /etc/debian_version

7.检查内核

1
uname -msr

8.删除不再需要的软件包

1
apt-get autoremove && apt-get autoclean

Debian修改ssh端口和禁止root远程登陆设置

linux修改端口22

1
vi /etc/ssh/sshd_config

找到#port 22
将前面的#去掉,然后修改端口 port 1234
重启服务就OK了

1
service sshd restart

1
/etc/init.d/ssh restart

为增强安全
先增加一个普通权限的用户,并设置密码

1
2
useradd test
passwd test

然后禁止ROOT远程SSH登录:

1
vi /etc/ssh/sshd_config

把其中的

1
PermitRootLogin yes

改为

1
PermitRootLogin no

重启sshd服务

1
service sshd restart

1
/etc/init.d/ssh restart

远程管理用普通用户test登录,然后用

1
su root

切换到root用户就可以拿到最高权限

Debian或Ubuntu运行php5-fpm报错connect() to unix:/var/run/php5-fpm.sock

在ubuntu12.04中安装配置LNMP时 出现在php5-fpm的错误

1
2
3
4
5
6
7
8
2013/04/26 04:01:05 [crit] 6119#0:
 *4 connect() to unix:/var/run/php5-fpm.sock failed
(2: No such file or directory) while connecting to upstream,
client: 159.53.110.141,
server: 216.238.88.42,
request: "GET / HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:",
host: "216.238.88.42:9090

nginx中是这样配置的

1
2
3
4
5
6
7
8
9
10
11
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-cgi alone:
    fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

我个人的配置是想用sock的方法 毕竟sock方式对于高并发来说 还是比使用cgi方式好的
问题其实出现在 fastcgi_pass得配置上面。在ubuntu 12.10安装了php5-fpm之后。我们可以去

1
/etc/php5/fpm/pool.d/www.conf

里面找到这样一段代码:

1
listen = 127.0.0.1:9000

在这上面代码的下面添加一行:

1
listen = /var/run/php5-fpm.sock

保存后启动php5-fpm

1
/etc/init.d/php5-fpm restart

这时就可以正常访问了

另外有可能是sock文件的执行权限有问题,对sock文件执行

1
chmod 777 php5-fpm.sock

再启动php5-fpm问题解决。

Ubuntu/Debian安装Nginx和upstream-fair

在ubuntu或debian上安装nginx,可以直接采用使用指令安装

1
apt-get install nginx

假定工作操作目录为用户根目录即~或者/home/uname(当前你是uname用户),如果你是root用户,那么你的根目录应该是/root

获取nginx及安装依赖包
使用官方源安装可能不能满足选择版本的需求,手动安装nginx首先安装依赖包
apt-get指令需要root权限,确保你使用root用户或者获得root权限

1
2
3
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libpcre3 libpcre3-dev libssl-dev libxslt-dev libgd2-xpm-dev libgeoip-dev

nginx源码可以访问nginx官方网站的下载页面:http://nginx.org/en/download.html
比如选择 Stable version nginx-1.2.7
复制下载地址,然后使用命令下载tar包

1
wget http://nginx.org/download/nginx-1.2.7.tar.gz

解压缩

1
tar zxvf nginx-1.2.7.tar.gz

upstream-fair模块
upstream-fair是比内建的负载均衡更加智能的负载均衡模块,一般google关键词nginx-upstream-fair可以找到相关资源和文章,这里不详述了。它采用的不是内建负载均衡使用的轮换的均衡算法,而是可以根据页面大小、加载时间长短智能的进行负载均衡。
可以通过github获取,地址是https://github.com/gnosek/nginx-upstream-fair
googlecc上也有http://wcoserver.googlecc.com/files/gnosek-nginx-upstream-fair-2131c73.tar.gz
注意:这个版本可能已经过时,推荐使用github上的master zip包
获取到nginx-upstream-fair-master.zip或者gnosek-nginx-upstream-fair-2131c73.tar.gz后解压缩

1
2
unzip nginx-upstream-fair-master.zip
tar zxvf gnosek-nginx-upstream-fair-2131c73.tar.gz

为了方便起见,把加压缩后得到文件夹更改一下名字,比如upstream

1
2
mv nginx-upstream-fair-master upstream
mv gnosek-nginx-upstream-fair-2131c73 upstream

如果你喜欢用rename也行,具体可以自己操作。

编译安装nginx
接下来进入解压缩之后的目录

1
cd nginx-1.2.7/

配置参数

1
./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/home/uname/upstream/

注意最后一个参数–add-module=/home/uname/upstream/的路径,之前假定的工作目录为/home/uname(uname为你的用户根目录),我们下载的gnosek-nginx-upstream-fair压缩包在这里解压并且更名未upstream,此处填写绝对路径。
配置结束应该不会报错,我在ubuntu12.04和debian6上都做过安装,并且作为开发和生产环境一直在运行,如果有问题可以联系我。
接下来编译安装

1
2
sudo make
sudo make install

等待编译结束,安装完成
执行文件被安装在/etc/nginx/sbin/nginx,如果你想安装到/usr下可以更改前面的配置参数,这里可以这样在/usr/sbin中建立软链接

1
2
cd /usr/sbin
sudo ln -s /etc/nginx/sbin/nginx

然后你在任意位置执行

1
nginx -v

应该能看到nginx版本信息

1
nginx version: nginx/1.2.7

查看详细配置信息

1
nginx -V

显示详细信息

1
2
3
4
nginx version: nginx/1.2.7
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-ipv6 --with-mail --with-mail_ssl_module --add-module=/home/uname/upstream/

附一个nginx使用upstream-fair的配置文件示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
upstream your-site {
    server 127.0.0.1:5550;
    server 127.0.0.1:5551;
    fair;
}
server {
    listen 80;
    server_name yoursite.com www.yoursite.com;
    access_log /var/log/nginx/access.log;
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 60s;
        proxy_send_timeout 90s;
        proxy_read_timeout 90s;
        proxy_buffering off;
        proxy_temp_file_write_size 64k;
        proxy_pass http://your-site;
        proxy_redirect off;
    }
}