Skip to main content

Posts

Showing posts with the label Linux

LAMP / LEMP development note 30-Sept-2019

Count Apache's (httpd) concurrent connections https://www.2daygeek.com/linux-check-apache-concurrent-connections-netstat-ss-command/ $htpasswd -b -c ~/temp/password admin test101 https://www.networkworld.com/article/2874387/mission-impossible-memorizing-ipv6-addresses.html  Chrome & Firfox Dark mode seem cool. https://stackoverflow.com/questions/19646567/is-there-a-way-to-get-client-connections-count-in-aws-elb ELB actually runs on EC2 (?), which would only make sense, and would explain why it can't scale up extremely rapidly in response to traffic spikes. YOU CAN’T PROTECT WHAT YOU CAN’T SEE https://medium.com/tenable-techblog/lessons-from-aws-nlb-timeouts-5028a8f65dda https://stackoverflow.com/questions/6375654/how-to-add-date-string-to-each-line-of-a-continuously-written-log-file Difference between ESTABLISHED and LISTENING https://askubuntu.com/questions/854354/difference-between-established-and-listening https://users.cs.northwestern.edu/~agupta/cs...

Note some Laravel, NGINX, NodeJS deploy

Avoid/reduce log output on Laravel Console https://stackoverflow.com/questions/49346700/laravel-disable-artisan-console-output-when-running-tests Gcloud SSH issue Jun 20 06:37:18 instance-3 sshd[12753]: Connection closed by 113.190.235.xxx port 7600 [preauth] Jun 20 06:37:19 instance-3 sshguard[1393]: Blocking 113.190.235.188:4 for >630secs: 40 danger in 4 attacks over 184 seconds (all: 40d in 1 abuses over 184s). sudo service sshguard restart USER=root ; COMMAND=/usr/sbin/service sshguard restart Jun 20 06:45:11 instance-3 sudo: pam_unix(sudo:session): session opened for user root by vandung53cc(uid=0) Jun 20 06:45:11 instance-3 sshguard[1393]: Got exit signal, flushing blocked addresses and exiting... Jun 20 06:45:11 instance-3 sudo: pam_unix(sudo:session): session closed for user root Jun 20 06:45:11 instance-3 sshguard[12902]: Started with danger threshold=40 ; minimum block=420 seconds Jun 20 06:45:15 instance-3 sshd[12909]: Connection closed by 113.190.235.188 por...

Nginx 3

Vhost config ERR_ICANN_NAME_COLLISION when trying to use localhost .dev in Chrome Lỗi liên quan đến tên vhost: 1. /etc/hosts kiểm tra 2. /etc/nginx/sites-available  và /etc/nginx/sites-enabled xem tương ứng và chuẩn chưa. Ko thì unlink rồi tạo lại. Lưu ý khi tạo soft link cần chỉ định absolute path (y thì chưa rõ). sudo ln -s /etc/nginx/....          /etc/nginx/...... Lỗi config server (vhost) hay server block. block chắc đúng cho config / 1 file như CentOS còn Ub (debian) thì tách ra file khác nhau roài. Để ý: servername cần thêm cả www. ở đầu ko thì hay gặp lỗi nhiểu vhost loạn dẫn đến redirect về default vhost. Nó cứ bay về trang đầu tiên cài vhost. Lỗi này thì Apache cũng vậy vì cơ chế set vhost là same. ví dụ cho phpMyAdmin: https://www.digitalocean.com/community/questions/a-working-phpmyadmin-nginx-conf nickfarrow:playbuzz$ cat /etc/nginx/sites-available/padm.local.dev  server {         liste...

rsync 1

http://askubuntu.com/questions/323775/monitor-watch-running-rsync-process/323782 You can do: strace -e open $(ps -o lwp= -LC rsync | sed 's/^/-p/') To see what it's doing, or lsof -ad3-999 -c rsync to see what files it currently has opened.

FFmpeg 2

Ghép nhiều video giống nhau (khung hình frame, frame rate fps, cùng codec...)  làm 1. Lệnh sau đây nó tiện hơn do tốc độ xử lý nhanh. https://trac.ffmpeg.org/wiki/Concatenate ffmpeg -f concat -i <(for f in *.wav; do echo "file '$PWD/$f'"; done) -c copy output.wav ffmpeg -f concat -i <(for f in *.wmv; do echo "file '$PWD/$f'"; done) -c copy output.wmv ffmpeg -f concat -i <(for f in *.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4 Lưu ý là 2 hay nhiểu video phải same nhau, nếu ko thì output ra sẽ có lỗi ở những video phía sau video đầu tiên. Nó sẽ lấy codec, fps, frame ... của video 1 làm chuẩn. Các video same nhau hay có từ sreencapture, smartphone... nói chung cùng 1 device tạo ra video. Với những video khác thông số thì cần mất công qua nhiều bước hơn, vd: ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts...

Image magick crop image 2, convert image to pdf

This command crop all image at size 720x1100 out of original mobile 720x1280 (vertical). This often happen when you take screen shot in mobile device, it also show header of image like android status bar... You also can enter fullscreen mode in mobile before take screenshot but it take time and u can't do in all situation. for file in *.jpg; do convert -crop 720x1100+0+180 $file  $(basename $file .jpg)_croped.jpg; done - for file in *.jpg: loop through all jpg file in current folder. - convert : one of imagemagick command - -crop (crop image) - 720x1100: size to crop - +0+180 : start position to crop: here i crop about 180pixels bellow header. - basename : bash function to get name of filename (eg: extension .jpg) after  Convert image to PDF: http://catlingmindswipe.blogspot.com/2013/11/how-to-convert-jpg-to-pdf-using.html http://catlingmindswipe.blogspot.com/2013/11/how-to-convert-jpg-to-pdf-using.html (Note: this task may be take time be...

Commands 2

How To Create a New User and Grant Permissions in MySQL Tags:  MySQL What the  Red  Means The lines that the user needs to enter or customize will be in  red  in this tutorial! The rest should mostly be copy-and-pastable. About MySQL MySQL is an open source database management software that helps users store, organize, and later retrieve data. It has a variety of options to grant specific users nuanced permissions within the tables and databases—this tutorial will give a short overview of a few of the many options. How to Create a New User In  Part 1 of the MySQL Tutorial , we did all of the editing in MySQL as the root user, with full access to all of the databases. However, in the cases where more restrictions may be required, there are ways to create users with custom permissions. Let’s start by making a new user within the MySQL shell: CREATE USER ' newuser '@'localhost' IDENTIFIED BY ' password '; Sadly, at this point newuser ha...

Cron Job Check-in / Checkout công việc hằng ngày

Một số cty chưa lắp HT vân tay hay tương tự hay dùng checkin/out qua website nội bộ như e2.socicom.vn Nhưng mọi người hay quên và cũng không để ý nên nhiều khi ko checkin/out và phải gửi đề xuất cho quản lý làm hộ. Mình tạo 1 cái cronjob cho việc này. Mục đích : - từ thứ 2-6 (tuỳ lịch các bạn), bật trang checkin lên để check. - 2 lần 1 ngày sáng và chiều. - Nếu có thể thì thêm y/c: cứ tầm 7h-9h mà ko mở trang checkin thì sẽ bật. chiều tầm 5h-6h ko checkout thì bật web. Nếu xịn hơn nữa thì tự động checkin luôn rồi tắt tab này đi. Các bạn thêm như sau vào crontab. Vào terminal gõ crontab -e. (Thường edit = nano, bạn có thể set qua vim (google search)) Ở đây mình mới bật trang e2.scm lên để checkin trong 4 thời điểm   là 8h, 8h15, chiều 17h30 và 17h50. Mình chưa viết bash kiểm tra xem đã mở tab chưa. Cũng chưa tìm cách bât tab e2.scm lên trong khoảng 8h-9h. # m h  dom mon dow   command #0-59/5 * * * * /home/nickfarrow/Ubuntu\ One/cron_pub_ip.sh 0 8 * * 1-5 ...

Cài PAE cho nhân linux

Linux bản 32bit như các bạn đã biết chỉ nhận tối đa cỡ 3GB RAM. Muốn dùng hơn người ta hay cài PAE vào nhân hay cài bản 64bit. Tuy nhiên bản 64bit hiện giờ có hạn chế là có phần mềm không tương thích ... Các bạn làm theo hướng dẫn sau để enable HIGHMEM64G cho linux. enabling-pae-on-a-32-bit-ubuntu-desktop-supporting-up-to-64-gb/ Một số lưu ý: - Dịch lại nhân linux khá mất thời gian, máy mình core i5 đời cũ, 4GB Ram chạy mất 1h cho stage 1, stage 2 mất tầm 30'. - Sau khi dịch ra 2 gói .deb 1 header và 1 image các bạn cài gói image trước thay vì gói header như trong hướng dẫn nếu gặp lỗi đòi header. Ram 4GB hiện giờ cỡ 900k. Đa số lap bây giờ là 4GB = 2x2GB. Cài xong kernel mới các bạn nhớ xóa source đi cho nhẹ, của mình bản 3.2.0-57 là 6GB. Chúc thành công !

Common Command

Mysql: Create database with default character set, encoding: create database DB_NAME default character set utf8 default collate  utf8_general_ci; import mysql -u root -p DB_NAME < dump.sql mysql -u root -p DB_NAME < dump.sql /Application/MAMP/Library/bin/mysql /Application/MAMP/Library/bin/mysqlimport MAMP (MAC OSX + Apache + Mysql + PHP) PostgreSQL Others Export: mysqldump -u root -p Tutorials > tut_backup.sql Dump a table in DB: $ mysqldump -u root -p Tutorials php_tutorials asp_tutorials > tut_backup.sql Link stackoverflow  how-do-you-mysqldump-specific-tables Dump many DB : mysqldump -u root -p --databases Tutorials Articles Comments > content_backup.sql mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT ...

FFmpeg and Imagick

Ghép mặt người vào 1 video cụ thể. Có nhiều trang như  http://www.jibjab.com/ cho phép người dùng đưa mặt mình vào một số video ngộ nghĩnh như rockstar, dance video ... Thậm chí bạn có thể thêm nhiều mặt người vào video để thành cặp hay nhóm. Kỹ thuật làm trang này chủ yếu dựa trên Flash, chi tiết có thể tra GG. Mình muốn giới thiệu một cách khác không dùng Flash và có thể chạy trên mọi thiết bị thông qua web.  Về kỹ thuật video ghép từ nhiều khung hình, thường là 25fps (frames per second, hay video nhanh hơn là 30fps. Do vậy, chỉ cần ghép mặt mình vào từng khung hình hoặc đè lên theo từng thời điểm là OK. Công cụ đã có sẵn FFmpeg ghép ảnh thành video, ImageMagick chỉnh sửa ảnh cơ bản. Và một Tool quan trọng đó là  Adobe AfterEffect (AE) trong bộ Adobe Suites. Tool này chuyên để chỉnh sửa video. Nó có 1 chức năng là Motion Tracking detect vật thể di chuyển theo khung hình. Như vậy là về kỹ thuật là có thể làm được, kết quả vd: https://drive.google.com/file/d/0...