在Ubuntu上安装Chrome浏览器和ChromeDriver

一.安装Chrome浏览器

1.安装依赖

1
sudo apt-get install libxss1 libappindicator1 libindicator7

2.下载Chrome安装包

1
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

3.安装

1
2
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f

二.安装ChromeDriver

1.安装xvfb以便我们可以无头奔跑地运行Chrome

1
sudo apt-get install xvfb

2.安装依赖

1
sudo apt-get install unzip

3.下载安装包

1
wget -N http://chromedriver.storage.googleapis.com/对应版本/chromedriver_linux64.zip

 
chromedriver与chrome的对应关系表:
各个版本的下载地址:淘宝镜像

chromedriver版本 支持的Chrome版本
v2.41 v67-69
v2.40 v66-68
v2.39 v66-68
v2.38 v65-67
v2.37 v64-66
v2.36 v63-65
v2.35 v62-64
v2.34 v61-63
v2.33 v60-62
v2.32 v59-61
v2.31 v58-60
v2.30 v58-60
v2.29 v56-58
v2.28 v55-57
v2.27 v54-56
v2.26 v53-55
v2.25 v53-55
v2.24 v52-54
v2.23 v51-53
v2.22 v49-52
v2.21 v46-50
v2.20 v43-48
v2.19 v43-47
v2.18 v43-46
v2.17 v42-43
v2.13 v42-45
v2.15 v40-43
v2.14 v39-42
v2.13 v38-41
v2.12 v36-40
v2.11 v36-40
v2.10 v33-36
v2.9 v31-34
v2.8 v30-33
v2.7 v30-33
v2.6 v29-32
v2.5 v29-32
v2.4 v29-32

4.解压缩+添加执行权限

1
unzip chromedriver_linux64.zip

5.移动

1
sudo mv -f chromedriver /usr/local/share/chromedriver

6.建立软连接

1
2
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

三.无头运行Chrome

1.安装Python依赖

1
2
pip3 install selenium
pip3 install pyvirtualdisplay

2.开整

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from selenium import webdriver
from selenium.webdriver.chrome.options import Options 
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(url)
iframe=driver.find_elements_by_tag_name('iframe')
    if len(iframe)>0:
        iframe = iframe[0]        
        driver.switch_to.frame(iframe)        
        ibody = driver.find_elements_by_tag_name('body')        
        if len(ibody)>0:            
            ibody=ibody[0]            
            video =ibody.find_element_by_tag_name('video')            
            if video is not None:                
                src = video.get_attribute("src")                
                if src !"" and src is not None:                    
                    res = {'src':src}                    
                    return str(res)

 

Ubuntu Server配置SVN

1.安装SVN

1
apt-get install subversion

2.创建项目目录

1
2
3
4
mkdir svn //创建一个文件夹,用来存放一个或多个项目
cd ./svn //进入这个目录
mkdir project//创建一个新的项目目录
svnadmin create ./svn/project //创建svn文件仓库(这一步是让这个新的文件夹变成svn的版本库)

3.权限设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd ./svn/project/conf
vim passwd //添加用户设置密码
root = 123456
user1 = 123456
user2 = 123456
vim authz //编辑用户权限
admin = user1,user2,root
@admin=rw
*=r
vim svnserve.conf //控制访问权限
anon-access = none #匿名用户(anonymous users)的访问权限
auth-access = write #授权用户(authenticated users)的访问权限
password-db = passwd #密码数据库文件的位置,这里指向同级目录下的passwd文件
authz-db = authz #用户授权规则文件的位置,这里指向同级目录下的authz文件

4.启动SVN
启动svn

1
svnserve -d -r /svn 

这里的/svn 的目录就是你第一步创建用来存放项目的那个目录

关闭svn
在配置过程中如果需要关闭svn则kill

1
2
3
4
ps aux | grep svn
root 21618 0.0 0.0 69596 616 ? Ss 19:07 0:00 svnserve -d -r /svn
root 21927 0.0 0.2 11748 2156 pts/0 S+ 19:10 0:00 grep –color=auto svn
kill 21618

5.配置钩子
在这里svn提供了好的钩子模板,你可以根据自己的情况选择模板,一般都是选择post-commit.tmpl(提交后更新)

1
2
cd ./svn/project/hooks
vim post-commit //新建文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
EPOS="$1"
REV="$2"
TXN_NAME="$3"
export.UTF-8
SVN=/usr/bin/svn
WEB=/home/wwwroot/projectDIR
LOG=/tmp/www.log
$SVN update $WEB –username svnuser–password yourpasswd > $LOG || exit 1
chown wwwroot:www $WEB -R
exit 0
ifthen
echo "ok" >> /tmp/www.out
fi

6.设置模板执行权限

1
chmod 755 post-commit

7.上传代码纳入版本管理

1
svn import -m "import" /home/project svn://192.168.213.31/project

8.检出到WEB目录

1
/usr/bin/svn checkout svn://serverIP/project/ /home/wwwroot/project

Ubuntu下搭建FTP服务器

在Linux中ftp服务器的全名叫 vsftpd,我们需要利用相关命令来开启安装ftp服务器,然后再在vsftpd.conf中进行相关配置,下面我来介绍在Ubuntu中vsftpd安装与配置增加用户的方法。

1.首先用命令检查是否安装了vsftpd

1
vsftpd -version

这里写图片描述
如果未安装用一下命令安装

1
sudo apt-get install vsftpd

安装完成后,再次输入vsftpd -version命令查看是否安装成功

2.新建一个文件夹用于FTP的工作目录

1
mkdir /home/ftp

这里写图片描述

3.新建FTP用户并设置密码以及工作目录
ftpname为你为该ftp创建的用户名

1
sudo useradd -d /home/ftp -s /bin/bash ftpname

这里写图片描述

为新建的用户设置密码

1
passwd ftpname

【注释:用cat etc/passwd可以查看当前系统用户】

4.用命令打开vsftpd.conf

1
vi vsftpd.conf

这里写图片描述
设置属性值

1
2
3
anonymous_enable=NO #禁止匿名访问
local_enable=YES
write_enable =YES

保存返回
5.启动vsftpd服务

1
service vsftpd start

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;
    }
}