Nội dung bài viết
1. Quét virus
Lệnh scan toàn bộ file .PHP để tìm điểm chung giữa các file malware:
grep -r --include=*.php "search string" /path/to/dir
Chỉnh sửa lại file cấu hình Nginx để include cấu hình iThemes Security ngăn không cho chạy .PHP trong thư mục uploads
.
Cuối cùng chạy Reinstall WordPress và upload lại toàn bộ thư mục Plugin.
Nén toàn bộ file .PHP
zip -R foo '*.php'
2. Cài đặt HocVPS Script
– LEMP
curl -sO https://tocdo.net/scripts/7/install && bash install
Những package sẽ cài đặt:
3. Một số lệnh hay dùng
Sao lưu cấu hình PHP
mkdir -p /root/backup/php.d/ mkdir -p /root/backup/php-fpm.d/ cp /etc/php.ini /root/backup/php.ini cp /etc/php-fpm.conf /root/backup/php-fpm.conf cp /etc/php.d/* /root/backup/php.d/ cp /etc/php-fpm.d/www.conf /root/backup/php-fpm.d/www.conf
Nén toàn bộ nội dung site
zip -r bk.zip /home/domain.com/public_html/ -q -x /home/domain.com/public_html/wp-content/cache/**\*
Sao lưu toàn bộ database
mysqldump -u root --all-databases > alldatabases.sql
Sao lưu database
mysqldump -u root databasename > database.sql mysqldump -u root -pmypass databasename > database.sql
Khôi phục database
mysql -u root databasename < database.sql mysql -u root -pmypass databasename < database.sql
Dumping and importing from/to MySQL in an UTF-8 safe way:
https://makandracards.com/makandra/595-dumping-and-importing-from-to-mysql-in-an-utf-8-safe-way
Rsync
yum install rsync rsync -avzhe "ssh -p 2222" --exclude 'wp-content/cache/' /home/canhme.com/public_html/* [email protected]:/home/canhme.com/public_html/
Memcached
yum install memcached php-pecl-memcached php-pecl-memcache -y chkconfig memcached on nano /etc/sysconfig/memcached service memcached start service php-fpm restart # yum remove memcached php-pecl-memcached php-pecl-memcache -y
4. Cài đặt tối ưu
1. MySQL
- MySQLTuner
- Using MySQLTuner to Optimize MySQL configuration
- http://www.mysqlcalculator.com/
- Ten MySQL performance tuning settings after installation
- MySQL 5.7 Performance Tuning Immediately After Installation
Chuyển MYISAM thành INNODB
Kiểm tra table cần chuyển:
SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' ENGINE=InnoDB;') FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE='MyISAM' AND table_schema = 'mydatabase';
Tiến hành chuyển:
USE mydatabase;
2. Nginx & PHP-FPM
Một số site hay get link thì cần điều chỉnh lại thời gian chạy PHP-FPM và Nginx, thấp xuống, từ 600 có thể chỉ còn 30 second
Chỉnh lại pm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers, pm.max_requests, tham khảo php_status để ước lượng con số dùng phù hợp. Tự động tính toán Memory và số lượng process tại đây.
Tắt access và error log với những site high traffic, giảm tải I/O. Xem thêm.
Cài đặt Nginx supports HTTP2 & ngx_cache_purge
- Nginx supports HTTP2: https://www.thuysys.com/toi-uu/cau-hinh-https-dung-chua-chac-da-dung-duoc-http2.html - ngx_cache_purge http://tactosh.com/2014/01/ngx_cache_purge/ yum install gcc-c++ perl pcre-devel zlib-devel epel-release wget nginx -y # Với Nginx 1.18.0 cd /usr/local/src wget http://nginx.org/download/nginx-1.18.0.tar.gz && tar -xzvf nginx-1.18.0.tar.gz wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz && tar -xzvf openssl-1.1.1g.tar.gz wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz && tar -xzvf ngx_cache_purge-2.3.tar.gz cd nginx-1.18.0 ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-openssl=/usr/local/src/openssl-1.1.1g --add-module=/usr/local/src/ngx_cache_purge-2.3 make mv /usr/sbin/nginx /usr/sbin/nginx.bak && cp objs/nginx /usr/sbin/nginx && service nginx restart - WordPress Plugin https://vi.wordpress.org/plugins/nginx-helper/ - PHP Purge Nginx FastCGI Cache <?php array_map('unlink', glob("/var/run/nginx-cache/*/*/*")); array_map('rmdir', glob("/var/run/nginx-cache/*/*")); array_map('rmdir', glob("/var/run/nginx-cache/*")); ?>
Chia nhỏ file và gộp file
split -b 1G $domain.tgz.enc “$domain.tgz.enc.” && rm -f $domain.tgz.enc
#cat gucongnghe.com.tgz.enc.* > gucongnghe.com.tgz.enc
#rm -rf gucongnghe.com.tgz.enc.*
Mã hóa và giải mã với tar & openssl
Encrypt:
tar -cO a/ | openssl enc -aes-256-cbc -md md5 -pass pass:linhtinh > a.bin
Decrypt:
openssl enc -d -aes-256-cbc -md md5 -pass pass:linhtinh -in dulieu.tgz.enc.aa | tar -x
openssl enc -d -aes-256-cbc -md md5 -pass pass:linhtinh -in dulieu.gz.enc.aa -out dulieu.gz && gzip -d dulieu.gz
5. Backup
https://www.itzgeek.com/how-tos/linux/centos-how-tos/ssh-passwordless-login-centos-7-rhel-7.html
– Login SSH vào Synology với account Luan
cat ~/.ssh/id_rsa.pub
– Lên server mới copy public key thêm vào dòng mới
nano ~/.ssh/authorized_keys
– Login thử từ SSH Synology để đồng ý kết nối mới
ssh -p 2222 [email protected]