DirectAdmin: Cải thiện hiệu suất và bảo mật 1
DirectAdmin

DirectAdmin: Cải thiện hiệu suất và bảo mật

Trong hướng dẫn này, tôi sẽ cải thiện môi trường DirectAdmin, làm cho nó nhanh hơn và an toàn hơn. Tôi giả sử rằng bạn đã cài đặt DirectAdmin trên máy chủ của bạn (cho hướng dẫn này, tôi sử dụng CentOS 7 64bit). Một sự hiểu biết tốt các vấn đề cơ bản về Linux là cần thiết để làm theo hướng dẫn này. Bây giờ chúng ta bắt đầu:

Cài đặt Nginx reverse proxy

Hiệu suất có thể được cải thiện bởi proxy ngược xử lý nội dung tĩnh và từ các yêu cầu ứng dụng. Nếu máy chủ web của bạn không được đặt ở chế độ này, hãy làm theo các lệnh dưới đây:

cd /usr/local/directadmin/custombuild
./build update
./build set webserver nginx_apache
./build nginx_apache

Khôi phục IP khách truy cập ban đầu nếu đến từ CloudFlare

vi /etc/nginx/nginx-includes.conf

Thêm dòng sau đây vào

set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;

# use any of the following two
real_ip_header CF-Connecting-IP;
#real_ip_header X-Forwarded-For;

Sử dụng PHP7

PHP7 cho ta hiệu suất nhanh hơn đến 2.x lần và tiêu thụ bộ nhớ tốt hơn 50% so với PHP 5.6.Mặc định nếu bạn cài mới từ đầu thì PHP 7.2 đã được cài đặt. Nếu bạn đang ở phiên bản dưới PHP7 thì bạn có thể update lên bằng cách sau:

cd /usr/local/directadmin/custombuild
./build set php1_release 7.2
./build set php1_mode php-fpm
./build update
./build php d

Nếu bạn sử dụng Cloudlinux thì dùng lệnh sau:

./build set php1_mode lsphp
./build update
./build php d

Chỉnh sửa file /usr/local/php72/lib/php.ini và tăng gấp đôi các thông số sau: memory_limit, max_execution_time, max_input_time

Kích hoạt OpCache

OpCache có thể cải thiện hiệu suất của PHP, chạy các lệnh sau:

cd /usr/local/directadmin/custombuild
./build set opcache yes
./build opcache

** lưu ý: OpCache không được sử dung chung với suPHP

Nâng cấp và sử dụng MariaDB

Có rất nhiều cải tiến và tối ưu hóa trong MariaDB, nếu máy chủ của bạn không được thiết lập để sử dụng MariaDB, hãy làm theo điều này:

cd /usr/local/directadmin/custombuild
./build set mariadb 10.2
./build set mysql_inst mariadb
./build set mysql_backup yes
./build update
./build mariadb

Tăng khả năng xử lý của MariaDB:

vi /etc/my.cnf.d/server.cnf

Thêmmax_allowed_packet = 256M , innodb_log_file_size = 256M và bind-address = 127.0.0.1 trong [mysqld] . thêm max_allowed_packet=256M trong [mysqldump] .

Dùng hostname cho alias

cd /usr/local/directadmin/custombuild
./build update
./build set use_hostname_for_alias yes
./build set redirect_host_https yes
./build rewrite_confs

Kích hoạt DKIM

Kích hoạt tính năng này giúp bạn khi gửi email từ máy chủ DirectAdmin đáp ứng yêu của các tổ chức và ngăn email của bạn không vào thư mục  Spam, tải file dkim.conf từ:

cd /etc
wget -O exim.dkim.conf http://files.directadmin.com/services/exim.dkim.conf

Sửa /etc/exim.conf, tìm dòng code sau:

remote_smtp:
 driver = smtp

Thay đổi nó thành:

remote_smtp: 
  driver = smtp
  .include_if_exists /etc/exim.dkim.conf

cập nhập exim.conf với CustomBuild:

cd /usr/local/directadmin/custombuild
./build update 
./build set eximconf yes 
./build set eximconf_release 4.5 
./build set blockcracking yes 
./build set easy_spam_fighter yes 
./build set spamassassin yes 
./build set exim yes 
./build exim 
./build set dovecot_conf yes 
./build dovecot_conf 
./build spamassassin 
./build update 
./build exim_conf

sau đó chạy lại exim:

systemctl restart exim

sau đó ta chỉnh sửa file directadmin.conf :

vi /usr/local/directadmin/conf/directadmin.conf

chỉnhdkim=1 hide_outlook=1 và restart DirectAdmin

Bây giơi ta tạo DKIM cho máy chủ DA với hostname:

cd /usr/local/directadmin/scripts
./dkim_create.sh server.domain.com

Sau đó ta vào DirectAdmin > DNS Administration và kích vào hostname để kiểm tra DKIM key, và SPF record .

Sửa file /etc/hosts file, Chúng ta không muốn hiện localhost trong dòng ::1 (localhost6 và các  “6” khác không cần thay đổi) “localhost” chỉ nên để trong dòng 127.0.0.1 .

Kích hoạt auto update

cài đặt yum-cron:

yum -y install yum-cron
sed -ie 's/apply_updates = no/apply_updates = yes/' /etc/yum/yum-cron.conf

Chạy dịch vụ yum-cron :

systemctl start yum-cron.service

kích hoạt DA cron:

vi /usr/local/directadmin/custombuild/options.conf

Cấu hình cron kiểm tra cập nhập mỗi tháng như sau:

cron=yes
cron_frequency=monthly
email=your@email.com
notifications=yes
da_autoupdate=yes
updates=yes
webapps_updates=yes

cuối cùng ta build cron:

cd /usr/local/directadmin/custombuild/
./build cron

Bây giờ bạn có thể sử dụng tốt, chúc bạn thành công

Avatar of jamesblackvn

Tui là jamesblackvn!

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Website này sử dụng Akismet để hạn chế spam. Tìm hiểu bình luận của bạn được duyệt như thế nào.