在 ubuntu 上安裝 nginx 很簡單, 只要下 apt-get ... 指令, 待指令返回時 nginx 就已經安裝好了. 然而我們要設定 rtmp 後重新啟動 nginx, 卻發現 nginx 異常. 這是怎麼一回事呢? 

# apt-get install nginx nginx-extras

 

# vi /etc/nginx/nginx.conf
....
rtmp {
    server {
        listen 1935;
        notify_method get;
        buflen 100ms;
        chunk_size 65536;
        timeout 60s;
        max_streams 1024;

        application live {
            live on;
            play_restart on;
            allow publish all;
        }

        # Video on demand
        #application vod {
        #    play /var/www/html/videos;
        #}
    }
}
...

 

# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
...
Process: 4835 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAIL)
...

原來 ubuntu 官方 release 的 packages 裡面並沒有 nginx-rtmp 這個 package. 看起來必須要自己 build. 


 

步驟1: Get nginx apt source & build-dep
 

# vim /etc/apt/sources.list
...
[....]
deb http://ftp.uk.debian.org/debian wheezy-backports main
deb-src http://ftp.uk.debian.org/debian wheezy-backports main
...
# Ubuntu 14 是 trusty ; Ubuntu 16 是 wheezy ; .... 
...

 

# apt-get update
...

 

# apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
...
# mkdir -p build ; cd build
# apt-get source nginx
...

 

# apt-get build-dep nginx

 

步驟2: Git clone nginx-rtmp-module source
 

# git clone git://github.com/arut/nginx-rtmp-module.git

 

步驟3: 編輯 debian/rules
 

# cd nginx-1.10.0/
vi debian/rules
...

增加 --add-module=/root/build/nginx-rtmp-module 這一行 (下述紅字部分). 
 

...
extras_configure_flags := \
                        $(common_configure_flags) \
                        --with-http_addition_module \
                        --with-http_dav_module \
                        --with-http_flv_module \
                        --with-http_geoip_module \
                        --with-http_gunzip_module \
                        --with-http_gzip_static_module \
                        --with-http_image_filter_module \
                        --with-http_mp4_module \
                        --with-http_perl_module \
                        --with-http_random_index_module \
                        --with-http_secure_link_module \
                        --with-http_v2_module \
                        --with-http_sub_module \
                        --with-http_xslt_module \
                        --with-mail \
                        --with-mail_ssl_module \
                        --with-stream \
                        --with-stream_ssl_module \
                        --with-threads \
                        --add-module=$(MODULESDIR)/headers-more-nginx-module \
                        --add-module=$(MODULESDIR)/nginx-auth-pam \
                        --add-module=$(MODULESDIR)/nginx-cache-purge \
                        --add-module=$(MODULESDIR)/nginx-dav-ext-module \
                        --add-module=$(MODULESDIR)/nginx-development-kit \
                        --add-module=$(MODULESDIR)/nginx-echo \
                        --add-module=$(MODULESDIR)/ngx-fancyindex \
                        --add-module=$(MODULESDIR)/nginx-http-push \
                        --add-module=$(MODULESDIR)/nginx-lua \
                        --add-module=$(MODULESDIR)/nginx-upload-progress \
                        --add-module=$(MODULESDIR)/nginx-upstream-fair \
                        --add-module=$(MODULESDIR)/ngx_http_substitutions_filter_module \
                        --add-module=/root/build/nginx-rtmp-module
...

 

步驟4: 開始編譯/build package
 

# cd ..
# dpkg-buildpackage -b
...
# dpkg-buildpackage -uc -us
...

 

步驟5: 安裝 package
 

# cd ..
# dpkg --install nginx-extras_1.10.0-0ubuntu0.16.04.2_amd64.deb
(Reading database ... 208049 files and directories currently installed.)
Preparing to unpack nginx-extras_1.10.0-0ubuntu0.16.04.2_amd64.deb ...
Unpacking nginx-extras (1.10.0-0ubuntu0.16.04.2) over (1.10.0-0ubuntu0.16.04.2) ...
Setting up nginx-extras (1.10.0-0ubuntu0.16.04.2) ...
Processing triggers for man-db (2.7.5-1) 
...

 

步驟6: 重新啟動 nginx
 

# mkdir -p /var/www/html/videos
# apt-get install nginx nginx-common
...
# service nginx restart
# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2016-08-10 15:10:45 CST; 40s ago
  Process: 5721 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 5747 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 5737 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 5758 (nginx)
   CGroup: /system.slice/nginx.service
           ├─5758 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─5760 nginx: worker process

 8月 10 15:10:45 smart systemd[1]: Starting A high performance web server and a reverse proxy server...
 8月 10 15:10:45 smart systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
 8月 10 15:10:45 smart systemd[1]: Started A high performance web server and a reverse proxy server.
...

 

步驟7: 測試 RTMP

 

Demo H.264 CLIP (http://downloads.dvdloc8.com/trailers/divxdigest/fantastic_four_rise_of_the_silver_surfer-trailer.zip) . 

 

# wget -O http://downloads.dvdloc8.com/trailers/divxdigest/fantastic_four_rise_of_the_silver_surfer-trailer.zip
...
# unzip fantastic_four_rise_of_the_silver_surfer-trailer.zip
...
# mv Fantastic\ Four\ -\ Rise\ of\ the\ Silver\ Surfer\ -\ Trailer.mp4 /var/www/html/videos/poster.mp4
...

 

RTMP URL: 

 

rtmp://192.168.3.33/live/poster

 

Ffmpeg: (trusty-media for Ubuntu14)

 

# add-apt-repository ppa:mc3man/trusty-media
...
# apt-get update
...
# apt-get install ffmpeg
...
# ffmpeg -re  -stream_loop 99 -i /var/www/html/videos/poster.mp4 -c copy -f flv rtmp://192.168.3.33/live/poster
...

 

VLC Player:

 

poster.png

 

 

Embed HDW Player in HTML: 

 

https://www.hdwplayer.com/rtmp-player/

 

# vi /var/www/html/index.html

 

<html>
<head>
        <title>Sample Integration</title>
        <script src="/player/js/hdwplayer.js"></script>
</head>
<body>

<div id="player"></div>

<script>
hdwplayer({
        id        : 'player',
        swf       : '/player/player.swf',
        width     : '705',
        height    : '400',
        type      : 'rtmp',
        streamer  : 'rtmp://192.168.3.33/live',
        video     : 'poster',
        autoStart : 'true'
});
</script>

</body>

 

hdwplayer.png

 

black_dot.jpg

 

 

安裝 Cvs Pserver on Ubuntu 14 LTS

 

安裝 cvs 很簡單; INSTALL 如下:   順便連同 tftp, tftpd 一起 INSTALL. 

 

# apt-get install cvs tftp tftpd

 

Cvs pserver 通常是由 xinetd 來啟動:   

 

# apt-get install xinetd
...
# ls /etc/xinetd.d/
chargen  cvspserver  daytime  discard  echo  tftp  tim

 

/etc/xinetd.d/cvspserver 內容如下:   

 

service cvspserver
{
    port        = 2401
    socket_type = stream
    protocol    = tcp
    wait        = no
    user        = root
    passenv     = PATH
    server      = /usr/bin/cvs
    server_args = -f --allow-root=/home/cvs pserver
}

 

/etc/xinetd.d/tftp 內容:  

 

# service tftp
{
    protocol        = udp
    port            = 69
    socket_type     = dgram
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = /home/tftp
    disable         = no
}

 

開機預設關閉 xinetd .    

 

# update-rc.d -f xinetd remove

 

開機預設啟動 xinetd .    

 

# update-rc.d xinetd defaults
...
# service xinetd restart
...

 

還需要 CVSROOT 環境變數

 

# vi ~/.profile
...
export CVSROOT=:pserver:jason@127.0.0.1:/home/cvs
...

 

安裝 Apache on Ubuntu 14 LTS

 

Apt-cache 搜尋 : 

 

# apt-cache search apache2
...
# apt-cache show apache2
...

 

列出 package files : 

 

# apt-file list apache2
...

 

移除 apache2 . 

 

# apt-get autoremove --purge apache2
...
# apt-get update
...

 

安裝 apache2 + PHP . 

 

# apt-get install apache2 apache2-doc apache2-utils libc6-dev libapache2-mod-php5 libapache2-mod-php5 php5-mcrypt php5-cli php-common php5-fpm php5 
...

 

安裝 mysql-server . 

 

# apt-get install mysql-server php5-mysql libmysqlclient-dev
...

 

安裝 perl . 

 

# apt-get install spawn-fcgi fcgiwrap ... 
# apt-get install libfcgi-perl perl libapache2-mod-perl2 libapache2-mod-python
...

 

讓 apache2 perl cgi 生效, 最簡單的方式是使用 a2enmod 指令: 

 

# a2enmod cgi

 

安裝 ruby . 

 

# apt-add-repository ppa:brightbox/ruby-ng
# apt-get update
# apt-get install ruby2.4

 

Apache 2 我讓它 listen port 81 . 

 

# vi /etc/apache2/ports.conf

 

...
Listen 81
...

 

# /etc/apache2/sites-available/000-default.conf

 

<VirtualHost *:81>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

 

# service apache2 restart

 

Apache2 web server CGI-BIN 預設位於 /usr/lib/cgi-bin/ 下; 使用以下 perl script 來測試 CGI : 

 

# vi /usr/lib/cgi-bin/hello

 

#!/usr/bin/perl -w
     # Tell perl to send a html header.
     # So your browser gets the output
     # rather then <stdout>(command line
     # on the server.)
print "Content-type: text/html\n\n";
     # print your basic html tags.
     # and the content of them.
print "<html><head><title>Hello World!! </title></head>\n";
print "<body><h1>Hello world</h1></body></html>\n";

 

# curl http://127.0.0.1:81/cgi-bin/hello
<html><head><title>Hello World!! </title></head>
<body><h1>Hello world</h1></body></html>
# 

 

 

Apache error "Could not reliably determine the server's fully qualified domain name"

 

碰到這個問題怎麼辦呢? 首先查一下 hostname ;

 

# cat /etc/hostname
bebop

 

接下來產生一個 /etc/apache2/conf-available/servername.conf 檔案. 

 

# rm -rf /etc/apache2/conf-available/servername.conf
# echo "ServerName bebop" | sudo tee /etc/apache2/conf-available/servername.conf
#

 

讓 ServerName 生效的指令是: 

 

# a2enconf servername

 

# service apache2 reload
...
# service apache2 restart
 * Restarting web server apache2
#

 

 

安裝 cvsweb

 

# apt-get install cvsweb
...

 

設定如下: 

 

# vi /etc/cvsweb/cvsweb.conf

 

...
#
@CVSrepositories = (
        'local'   => ['Local Repository', '/home/cvs'],
#       'freebsd' => ['FreeBSD',          '/var/ncvs'],
#       'openbsd' => ['OpenBSD',          '/var/ncvs'],
#       'netbsd'  => ['NetBSD',           '/var/ncvs'],
#       'ruby'    => ['Ruby',             '/var/anoncvs/ruby'],
);
...

 

小圖示 (icons) 以及 CSS (Cascading Style Sheets) 網頁樣式表:  

 

# ln -s /usr/share/cvsweb /var/www/html/cvsweb

 

Ubuntu 14 cvsweb 是有問題的. 請見 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733054, 必需要修正. Error Log 如下: 

 

vi /var/log/apache2/error.log

 

...
[Sun Oct 29 00:40:45.105187 2017] [core:notice] [pid 29022] AH00094: Command line: '/usr/sbin/apache2'
[Sun Oct 29 01:01:15.454616 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: "my" variable $tmp masks earlier declaration in same statement at /usr/lib/cgi-bin/cvsweb line 1340.
[Sun Oct 29 01:01:15.454712 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1197, near "$v qw(hidecvsroot hidenonreadable)"
[Sun Oct 29 01:01:15.454732 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: Global symbol "$v" requires explicit package name at /usr/lib/cgi-bin/cvsweb line 1199.
[Sun Oct 29 01:01:15.454749 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: Global symbol "$v" requires explicit package name at /usr/lib/cgi-bin/cvsweb line 1199.
[Sun Oct 29 01:01:15.454761 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1278, near "}"
[Sun Oct 29 01:01:15.454773 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1291, near "}"
[Sun Oct 29 01:01:15.454785 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1297, near "}"
[Sun Oct 29 01:01:15.454797 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1304, near "}"
[Sun Oct 29 01:01:15.454808 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1314, near "}"
[Sun Oct 29 01:01:15.454820 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1338, near "}"
[Sun Oct 29 01:01:15.454833 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: syntax error at /usr/lib/cgi-bin/cvsweb line 1340, near ""$tmp,v" }"
[Sun Oct 29 01:01:15.454843 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] AH01215: /usr/lib/cgi-bin/cvsweb has too many errors.
[Sun Oct 29 01:01:15.456794 2017] [cgi:error] [pid 29028] [client 192.168.1.102:56630] End of script output before headers: cvsweb
[Sun Oct 29 09:33:15.610825 2017] [mpm_prefork:notice] [pid 29022] AH00169: caught SIGTERM, shutting down
...

 

修正方式如下: 

1. 找到 for my $v qw(hidecvsroot hidenonreadable) {  這一行
  換為 for my $v (qw(hidecvsroot hidenonreadable)) {

2. 找到 if (defined @mytz) { 這一行
  換為 if (defined @mytz) {

 

vi /usr/lib/cgi-bin/cvsweb

 

--- cvsweb.orig    2013-12-24 09:58:09.333520125 -0500
+++ cvsweb    2013-12-24 09:58:50.222171067 -0500
@@ -1194,7 +1194,7 @@
 <legend>General options</legend>
 <input type="hidden" name="copt" value="1" />
 EOF
-    for my $v qw(hidecvsroot hidenonreadable) {
+    for my $v (qw(hidecvsroot hidenonreadable)) {
       printf(qq{<input type="hidden" name="%s" value="%s" />\n},
              $v, $input{$v} || 0);
     }
@@ -2953,7 +2953,7 @@
   print "<br />\n";
 
   print '<i>';
-  if (defined @mytz) {
+  if (@mytz) {
     my ($est) = $mytz[(localtime($date{$_}))[8]];
     print scalar localtime($date{$_}), " $est</i> (";
   } else {

 

這樣就 OK 了. 

 

cvsweb.png

 

PHP 也 OK 了. 

 

php-apache.png

 

 

Nginx + PHP + PERL-CGI + WEBCVS 設定

 

# apt-get install nginx nginx nginx-common fcgiwrap spawn-fcgi
...
# vi /etc/nginx/sites-available/default
...
# /etc/init.d/nginx restart
...

 

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        #root /usr/share/nginx/html;
        root /var/www/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;
...
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        # 很重要, 不然你密碼可能被其他人取走了
        location ~ /\.ht {
                deny all;
        }
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
        location ~ \.cgi$ {
                gzip off;
                include fastcgi_params;
                #fastcgi_pass  127.0.0.1:8999; 
                fastcgi_pass unix:/var/run/fcgiwrap.socket;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
        location ~ \.pl$ {
                gzip off;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/fcgiwrap.socket; # or 127.0.0.1:8999
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_index index.pl;
        }
        #location ~ ^/cgi-bin {
        #       gzip off;
        #       root /usr/lib/cgi-bin;
        #       rewrite ^/cgi-bin/(.*) /$1 break;
        #       include fastcgi_params;
        #       fastcgi_pass unix:/var/run/fcgiwrap.socket;
        #       fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #}
        location ~ ^/cgi-bin {
                proxy_pass   http://127.0.0.1:81;

                # Other proxy configurations
                proxy_redirect          off;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size    10m;
                client_body_buffer_size 128k;
                proxy_connect_timeout   90;
                proxy_send_timeout      90;
                proxy_read_timeout      90;
                proxy_buffers           32 4k;
        }
        location /phpmyadmin {
                auth_basic "Restricted Files"; 
                auth_basic_user_file /etc/phpmyadmin/.htpasswd; 
                root /usr/share/;
                index index.php index.html index.htm;
                location ~ ^/phpmyadmin/(.+\.php)$ {
                        try_files $uri =404;
                        root /usr/share/;
                        fastcgi_pass unix:/var/run/php5-fpm.sock; # or 127.0.0.1:9000
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include /etc/nginx/fastcgi_params;
                }
                location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                        root /usr/share/;
                }
        }
        location /phpMyAdmin {
                rewrite ^/* /phpmyadmin last;
                auth_basic "Restricted Files";
                auth_basic_user_file /etc/phpmyadmin/.htpasswd;
        }
...
}
...

 

root@bebop:~# ls -l /etc/init.d/
total 288
...
-rwxr-xr-x 1 root root 9974  1月  7  2014 apache2
...
-rwxr-xr-x 1 root root 7283 10月 29 22:58 fcgiwrap
...
-rwxr-xr-x 1 root root 5491  2月 20  2014 mysql
...
-rwxr-xr-x 1 root root 4710  7月 30  2015 nginx
...
-rwxr-xr-x 1 root root 4403  2月 18  2014 php5-fpm
...
-rwxr-xr-x 1 root root 2443 10月 26  2013 xinetd
...

 

Fcgiwap 可以使用 unix sockets 或 tcp sockets ; 它們的設定分別如下: (系統預設是 unix)

 

# vi /etc/init.d/fcgiwrap
...
# /etc/init.d/fcgiwrap restart
...

 

...
# FCGI_APP Variables
FCGI_CHILDREN="1"
FCGI_SOCKET="/var/run/$NAME.socket"
FCGI_USER="www-data"
FCGI_GROUP="www-data"
...

 

...
# FCGI_APP Variables
FCGI_CHILDREN="1"
FCGI_PORT="8999"
FCGI_ADDR="127.0.0.1"
FCGI_USER="www-data"
FCGI_GROUP="www-data"
...

 

這樣子設定 Nginx 也可以使用 cgi , perl , php 以及 cvsweb 了. 

 

 

cvsweb-nginx.png

 

 

php-nginx.png

 

 

Mysql test_db

 

Mysql test_db 說明文件請見 https://github.com/datacharmer/test_db 

 

# git clone https://github.com/datacharmer/test_db.git
...
# cd test_db

 

Installation:

 

# mysql -uroot -pXXXXX < employees.sql

 

# mysql -uroot -pXXXXX < employees_partitioned.sql

 

Testing installation:

 

# mysql -uroot -pXXXXX -t < test_employees_md5.sql
+----------------------+
| INFO                 |
+----------------------+
| TESTING INSTALLATION |
+----------------------+
+--------------+------------------+----------------------------------+
| table_name   | expected_records | expected_crc                     |
+--------------+------------------+----------------------------------+
| employees    |           300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
| departments  |                9 | d1af5e170d2d1591d776d5638d71fc5f |
| dept_manager |               24 | 8720e2f0853ac9096b689c14664f847e |
| dept_emp     |           331603 | ccf6fe516f990bdaa49713fc478701b7 |
| titles       |           443308 | bfa016c472df68e70a03facafa1bc0a8 |
| salaries     |          2844047 | fd220654e95aea1b169624ffe3fca934 |
+--------------+------------------+----------------------------------+
+--------------+------------------+----------------------------------+
| table_name   | found_records    | found_crc                        |
+--------------+------------------+----------------------------------+
| employees    |           300024 | 4ec56ab5ba37218d187cf6ab09ce1aa1 |
| departments  |                9 | d1af5e170d2d1591d776d5638d71fc5f |
| dept_manager |               24 | 8720e2f0853ac9096b689c14664f847e |
| dept_emp     |           331603 | ccf6fe516f990bdaa49713fc478701b7 |
| titles       |           443308 | bfa016c472df68e70a03facafa1bc0a8 |
| salaries     |          2844047 | fd220654e95aea1b169624ffe3fca934 |
+--------------+------------------+----------------------------------+
+--------------+---------------+-----------+
| table_name   | records_match | crc_match |
+--------------+---------------+-----------+
| employees    | OK            | ok        |
| departments  | OK            | ok        |
| dept_manager | OK            | ok        |
| dept_emp     | OK            | ok        |
| titles       | OK            | ok        |
| salaries     | OK            | ok        |
+--------------+---------------+-----------+
+------------------+
| computation_time |
+------------------+
| 00:00:07         |
+------------------+
+---------+--------+
| summary | result |
+---------+--------+
| CRC     | OK     |
| count   | OK     |
+---------+--------+
#

 

# mysql -uroot -pXXXXX -t < test_employees_sha.sql
+----------------------+
| INFO                 |
+----------------------+
| TESTING INSTALLATION |
+----------------------+
+--------------+------------------+------------------------------------------+
| table_name   | expected_records | expected_crc                             |
+--------------+------------------+------------------------------------------+
| employees    |           300024 | 4d4aa689914d8fd41db7e45c2168e7dcb9697359 |
| departments  |                9 | 4b315afa0e35ca6649df897b958345bcb3d2b764 |
| dept_manager |               24 | 9687a7d6f93ca8847388a42a6d8d93982a841c6c |
| dept_emp     |           331603 | d95ab9fe07df0865f592574b3b33b9c741d9fd1b |
| titles       |           443308 | d12d5f746b88f07e69b9e36675b6067abb01b60e |
| salaries     |          2844047 | b5a1785c27d75e33a4173aaa22ccf41ebd7d4a9f |
+--------------+------------------+------------------------------------------+
+--------------+------------------+------------------------------------------+
| table_name   | found_records    | found_crc                                |
+--------------+------------------+------------------------------------------+
| employees    |           300024 | 4d4aa689914d8fd41db7e45c2168e7dcb9697359 |
| departments  |                9 | 4b315afa0e35ca6649df897b958345bcb3d2b764 |
| dept_manager |               24 | 9687a7d6f93ca8847388a42a6d8d93982a841c6c |
| dept_emp     |           331603 | d95ab9fe07df0865f592574b3b33b9c741d9fd1b |
| titles       |           443308 | d12d5f746b88f07e69b9e36675b6067abb01b60e |
| salaries     |          2844047 | b5a1785c27d75e33a4173aaa22ccf41ebd7d4a9f |
+--------------+------------------+------------------------------------------+
+--------------+---------------+-----------+
| table_name   | records_match | crc_match |
+--------------+---------------+-----------+
| employees    | OK            | ok        |
| departments  | OK            | ok        |
| dept_manager | OK            | ok        |
| dept_emp     | OK            | ok        |
| titles       | OK            | ok        |
| salaries     | OK            | ok        |
+--------------+---------------+-----------+
+------------------+
| computation_time |
+------------------+
| 00:00:08         |
+------------------+
+---------+--------+
| summary | result |
+---------+--------+
| CRC     | OK     |
| count   | OK     |
+---------+--------+
# 

 

 

安裝 phpMyAdmin

 

# apt-get update
# apt-get install phpmyadmin
...

 

■ For the server selection, choose apache2. 

■ Select yes when asked whether to use dbconfig-common to set up the database

■ You will be prompted for your database administrator's password

■ You will then be asked to choose and confirm a password for the phpMyAdmin application itself

 

# php5enmod mcrypt

 

我們需要 enable php5-mcrypt . 

 

# service apache2 restart
 * Restarting web server apache2                                                                                                       [ OK ]
#

 

http://192.168.3.39:81/phpmyadmin

 

此時 phpMyAdmin 已經可以 work 了. 上述已經建立的 test_db 我們已經可以流覽/更新其中 tables 裡面的個別資料了. 

 

myadmin_login_screen.png

 

employee_tables.png

 

我們再進一步設定 .htaccess 覆寫 (AllowOverrides) ; /etc/apache2/conf-available/phpmyadmin.conf 新增一行如下述紅字的部份. 

 

# vi /etc/apache2/conf-available/phpmyadmin.conf

 

...
<Directory /usr/share/phpmyadmin>
    Options FollowSymLinks
    DirectoryIndex index.php
    AllowOverride All
    ...

 

產生一個 .htaccess 檔案, 內容如下: 

 

# vi /usr/share/phpmyadmin/.htaccess

 

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

 

真正的 AuthUserFile 位於 /etc/phpmyadmin/.htpasswd ; 由 htpasswd 產生. 

 

# htpasswd -c /etc/phpmyadmin/.htpasswd root
New password:
Re-type new password:
Adding password for user root
#

 

這樣 phpmyadmin 就會受到 /etc/phpmyadmin/.htpasswd 密碼的保護. 

 

 

phpMyAdmin 在 nginx 上的設定

 

# vi /etc/nginx/sites-available/default

 

server {
...
        location ~ /\.ht {
                deny all;
        }
...
        location /phpmyadmin {
                auth_basic "Restricted Files";
                auth_basic_user_file /etc/phpmyadmin/.htpasswd;
                root /usr/share/;
                index index.php index.html index.htm;
                location ~ ^/phpmyadmin/(.+\.php)$ {
                        try_files $uri =404;
                        root /usr/share/;
                        fastcgi_pass unix:/var/run/php5-fpm.sock; # or 127.0.0.1:9000
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include /etc/nginx/fastcgi_params;
                }
                location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                    root /usr/share/;
                }
        }
        location /phpMyAdmin {
            auth_basic "Restricted Files";
            auth_basic_user_file /etc/phpmyadmin/.htpasswd;
            rewrite ^/* /phpmyadmin last;
        }
...

 

# service nginx restart

 

這樣就搞定了. 

 

http://logout.logout@192.168.3.39/phpmyadmin

 

 

 

black_dot.jpg

 

 

參考: 

 

http://blog.faq-book.com/?p=6725

 

https://dotblogs.com.tw/grayyin/2017/01/04/211514

 

https://www.digitalocean.com/community/tutorials/how-to-add-ngx_pagespeed-module-to-nginx-in-debian-wheezy

 

https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/

 

https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp

 

https://wiki.debian.org/DhyanNataraj/RtmpVideoStreamingViaNginx

 

https://icicimov.github.io/blog/devops/NGINX-Naxsi-PageSpeed-LDAP/

 

https://www.linode.com/docs/web-servers/nginx/nginx-phpfastcgi-ubuntu-14-04

 

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04

 

https://blog.toright.com/posts/3890/%E7%84%A1%E5%A0%85%E4%B8%8D%E6%91%A7%EF%BC%8C%E5%94%AF%E5%BF%AB%E4%B8%8D%E7%A0%B4%EF%BC%81%E5%BF%AB%E6%94%B9%E7%94%A8-nginx-php-fpm-%E5%8F%96%E4%BB%A3-apache-%E5%90%A7%EF%BC%81.html

 

https://www.scalescale.com/tips/nginx/run-cgi-scripts-thttpd-nginx/

 

 

 

 

 

 

black_dot.jpg

 

 

 

 

 

 

 

 

z.png
 

Email: jasonc@mail2000.com.tw

 

 

 

 

 

 

arrow
arrow

    Lexra 發表在 痞客邦 留言(0) 人氣()