Công cụ thành viên

Công cụ trang web


web_server:cai-dat-server-chi-tai-cao

Khác biệt

Đây là những khác biệt giữa hai phiên bản của trang.

Liên kết đến bản xem so sánh này

Phiên bản trước của cả hai bênPhiên bản trước
Phiên bản sau
Phiên bản trước
web_server:cai-dat-server-chi-tai-cao [2015/12/06 18:36] vuthaoweb_server:cai-dat-server-chi-tai-cao [2015/12/11 11:19] (hiện tại) vuthao
Dòng 6: Dòng 6:
 ===== 1) Mô hình áp dụng: ===== ===== 1) Mô hình áp dụng: =====
  
-Mô hình này được bạn Việt bên 123host đưa ra+Mô hình này được bạn Việt bên 123host đưa ra. Vũ Thảo là người thực hiện
  
 {{:web_server:sodo.png|}} {{:web_server:sodo.png|}}
Dòng 17: Dòng 17:
 Mô hình này là mô hình này mình cố tình làm đơn giản nhất để phù hợp với cộng đồng. Ngoài các chú thích đã có trên hình, có một số lưu ý như sau: Mô hình này là mô hình này mình cố tình làm đơn giản nhất để phù hợp với cộng đồng. Ngoài các chú thích đã có trên hình, có một số lưu ý như sau:
  
-**Server lb1.nukeivet.vn:**+**Server lb1.nukeviet.vn:**
    
 Hiện chỉ chạy 1 mình, chưa có server dự phòng cho nó (HA - high availability). Nếu cần, mình sẽ lên một mô hình HA đầy đủ, tuy nhiên sẽ sử dụng thêm một số công nghệ phức tạp nên ban đầu mình sẽ không đưa vào. Hiện chỉ chạy 1 mình, chưa có server dự phòng cho nó (HA - high availability). Nếu cần, mình sẽ lên một mô hình HA đầy đủ, tuy nhiên sẽ sử dụng thêm một số công nghệ phức tạp nên ban đầu mình sẽ không đưa vào.
Dòng 39: Dòng 39:
 Nukeviet sử dụng default session của server thì có thể dùng Memcache để lưu session tập trung tại server lb1.nukeviet.vn (cấu hình session.handler và session.save_path tại php.ini) Nukeviet sử dụng default session của server thì có thể dùng Memcache để lưu session tập trung tại server lb1.nukeviet.vn (cấu hình session.handler và session.save_path tại php.ini)
  
 +===== 3) Tiến hành Cài đặt  =====
  
-===== 3) Cấu hình server lb1.nukeivet.vn =====+''Ghi chú: Hiện tại project này đang xây dựng, hiện tại các phần sau chưa xử lý được'' 
 +  - Xây dựng hệ thống MySQL master/slave (Phần này làm sau cùng do hiện tại nếu tách MySQL ra 1 máy chủ riêng thì CPU, IO load rất thấp). 
 + 
 +==== Cài đặt Nginx trên lb1.nukeviet.vn ====
 Sử dụng hệ điều hành CentOS 7.1, server này có 2 cạc mạng Sử dụng hệ điều hành CentOS 7.1, server này có 2 cạc mạng
 <code> <code>
 Public Network 192.168.100.101 để nối thẳng ra internet Public Network 192.168.100.101 để nối thẳng ra internet
-Private Network 192.168.200.100 để kết nối với các server nội bộ.+Private Network 192.168.56.100 để kết nối với các server nội bộ.
 </code> </code>
  
Dòng 110: Dòng 114:
 Khởi động lại nginx: sudo systemctl restart nginx sau đó truy cập vào địa chỉ IP để kiểm tra Khởi động lại nginx: sudo systemctl restart nginx sau đó truy cập vào địa chỉ IP để kiểm tra
  
 +==== Cài đặt Memcached  ====
 +Có thể cài đặt trên lb1.nukeviet.vn, hoặc tạo thêm máy memcached.nukeviet.vn
 +<code>
 +yum install -y memcached
 +sudo systemctl start memcached
 +sudo systemctl enable memcached
 +</code>
  
-**Bước 5: Cài đặt PHP**+Open Memcached Port (11211) on Firewall: 
 +<code> 
 +firewall-cmd --zone=internal --add-source=192.168.56.101/32 --permanent 
 +firewall-cmd --zone=internal --add-source=192.168.56.102/32 --permanent 
 +firewall-cmd --zone=internal --add-source=192.168.56.103/32 --permanent 
 +firewall-cmd --zone=internal --add-port=11211/tcp --permanent 
 +firewall-cmd --reload 
 +</code> 
 + 
 +==== Cài đặt PHP trên webapp1.nukeviet.vn ==== 
 +Trước khi cài đặt, hãy tiến hành tắt SELinux đi bằng cách mở file /etc/sysconfig/selinux và tìm  
 + 
 +SELINUX= rồi sửa thành như dưới đây: 
 +<code> 
 +SELINUX=disabled 
 +</code> 
 +Sửa xong, hãy gõ lệnh reboot để khởi động lại máy chủ và đăng nhập vào lại SSH.
  
 Cài CentOS 7.1 epel repository Cài CentOS 7.1 epel repository
Dòng 122: Dòng 149:
  
 <code> <code>
-yum --enablerepo=remi,remi-php56 install php-fpm php-mysql php-common php-mbstring php-mcrypt php-gd -y+yum --enablerepo=remi,remi-php56 install -y php-fpm php-mysql php-common php-mbstring php-mcrypt php-gd php-xml  php-memcached php-opcache
 </code> </code>
  
Dòng 138: Dòng 165:
 </code> </code>
  
 +Open Port on Firewall:
 +<code>
 +firewall-cmd --zone=internal --add-source=192.168.56.100/32 --permanent
 +firewall-cmd --zone=internal --add-port=9000/tcp --permanent
 +firewall-cmd --reload
 +</code>
 ** Thiết lập lại user và group chạy PHP ** ** Thiết lập lại user và group chạy PHP **
 +
 Mặc định PHP-FPM sẽ chỉ định user tên là apache và group tên apache để chạy nó, nhưng ở đây chúng ta không sử dụng Apache mà là NGINX nên bạn cần mở file /etc/php-fpm.d/www.conf lên và tìm: Mặc định PHP-FPM sẽ chỉ định user tên là apache và group tên apache để chạy nó, nhưng ở đây chúng ta không sử dụng Apache mà là NGINX nên bạn cần mở file /etc/php-fpm.d/www.conf lên và tìm:
  
Dòng 156: Dòng 190:
  
 Bây giờ bạn hãy mở file default.conf trong thư mục /etc/nginx/conf.d/ Bây giờ bạn hãy mở file default.conf trong thư mục /etc/nginx/conf.d/
 +Thêm lên trên cùng đoạn:
 +<code>
 +upstream fpm_nukeviet {
 + #ip_hash;
 + server 192.168.56.101:9000;
 + server 192.168.56.102:9000;
 + server 192.168.56.103:9000;
 +}
 +</code>
 +
 Tìm đoạn Tìm đoạn
 <code> <code>
Dòng 188: Dòng 232:
     location ~ \.php$ {     location ~ \.php$ {
         root           /usr/share/nginx/html;         root           /usr/share/nginx/html;
-        fastcgi_pass   127.0.0.1:9000;+        #fastcgi_pass   127.0.0.1:9000
 +        fastcgi_pass fpm_nukeviet;
         fastcgi_index  index.php;         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
Dòng 197: Dòng 242:
 Khởi động lại PHP-FPM Khởi động lại PHP-FPM
 <code> <code>
-service php-fpm restart+sudo systemctl restart php-fpm 
 +sudo systemctl restart nginx
 </code> </code>
 +
 +Sửa  lỗi không tạo được session
 +<code>
 +chmod -R 777 /var/lib/php/session
 +</code>
 +
 +Hoặc sửa file /etc/php.ini chuyển thư mục session sang /tmp/
 +
 +**Sử dụng session trên memcache**
 +Hoặc sửa file /etc/php.ini chuyển thư mục session sang /tmp/
 +<code>
 +session.save_handler = memcached
 +session.save_path = '192.168.56.100:11211'
 +</code>
 +
 +**Làm tương tự cho 2 máy webapp2.nukeviet.vn, webapp3.nukeviet.vn**
 +
 +==== Cài đặt MariaDB trên db1.nukeviet.vn ====
 +Tạo repo cho MariaDB
 +<code>
 +vi /etc/yum.repos.d/Mariadb.repo
 +</code>
 +Với nội dung
 +
 +<code>
 +# MariaDB 10.1 CentOS repository list - created 2015-12-06 14:53 UTC
 +# http://mariadb.org/mariadb/repositories/
 +[mariadb]
 +name = MariaDB
 +baseurl = http://yum.mariadb.org/10.1/centos7-amd64
 +gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
 +gpgcheck=1
 +</code>
 +
 +Chạy lệnh dưới để cài đặt MariDB
 +<code>
 +sudo yum install MariaDB-server MariaDB-client
 +</code>
 +
 +Kích hoạt MariDB ứng dụng này vào danh sách ứng dụng tự khởi động nếu reboot server
 +
 +<code>
 +sudo systemctl start mariadb
 +sudo systemctl enable mariadb
 +</code>
 +
 +**Cấu hình MariaDB**
 +<code>
 +    Set (Change) root password
 +    Remove anonymous users
 +    Disallow root login remotely
 +    Remove test database and access to it
 +    Reload privilege tables
 +</code>
 +
 +– Bắt đầu cài đặt
 +<code>
 +/usr/bin/mysql_secure_installation
 +</code>
 +
 +Ngay bước đầu tiên bạn sẽ bị hỏi root password, do mới cài đặt nên tất nhiên chưa có password, nhấn Enter để tiếp tục. Output tương tự như sau:
 +<code>
 +NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
 +SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
 +
 +In order to log into MariaDB to secure it, we\'ll need the current
 +password for the root user. If you\'ve just installed MariaDB, and
 +you haven\'t set the root password yet, the password will be blank,
 +so you should just press enter here.
 +
 +Enter current password for root (enter for none):
 +OK, successfully used password, moving on...
 +
 +Setting the root password ensures that nobody can log into the MariaDB
 +root user without the proper authorisation.
 +
 +Set root password? [Y/n] y
 +New password:
 +Re-enter new password:
 +Password updated successfully!
 +Reloading privilege tables..
 +... Success!
 +
 +
 +By default, a MariaDB installation has an anonymous user, allowing anyone
 +to log into MariaDB without having to have a user account created for
 +them. This is intended only for testing, and to make the installation
 +go a bit smoother. You should remove them before moving into a
 +production environment.
 +
 +Remove anonymous users? [Y/n] y
 +... Success!
 +
 +Normally, root should only be allowed to connect from \'localhost\'. This
 +ensures that someone cannot guess at the root password from the network.
 +
 +Disallow root login remotely? [Y/n] y
 +... Success!
 +
 +By default, MariaDB comes with a database named \'test\' that anyone can
 +access. This is also intended only for testing, and should be removed
 +before moving into a production environment.
 +
 +Remove test database and access to it? [Y/n] y
 +- Dropping test database...
 +... Success!
 +- Removing privileges on test database...
 +... Success!
 +
 +Reloading the privilege tables will ensure that all changes made so far
 +will take effect immediately.
 +
 +Reload privilege tables now? [Y/n] y
 +... Success!
 +
 +Cleaning up...
 +
 +All done! If you\'ve completed all of the above steps, your MariaDB
 +installation should now be secure.
 +
 +Thanks for using MariaDB!
 +</code>
 +
 +===== 4) Thiết lập NFS Server: =====
 +Xem chi tiết tại: http://www.unixmen.com/setting-nfs-server-client-centos-7/
 +
 +===== 5) Cài đặt Session trên memcached, Thiết lập cache trên memcached=====
 +Cài đặt NukeViet 4 mới nhất.
 +Cấu hình file /config.php.
 +<code>
 +Sửa dòng $global_config['cached'] = 'files';
 +thành $global_config['cached'] = 'memcached';
 +</code>
 +
 +Thêm các dòng sau vào cuối file:
 +<code>
 +define( 'NV_MEMCACHED_HOST', '192.168.56.100' );
 +define( 'NV_MEMCACHED_PORT', 11211 );
 +
 +ini_set( 'session.save_handler', 'memcached' );
 +ini_set( 'session.save_path', NV_MEMCACHED_HOST . ':' . NV_MEMCACHED_PORT );
 +</code>
 +(memcached đang được đặt tại: 192.168.56.100)
 +
 +===== 5) Kiểm thử lần 1: =====
 +Kết quả lần 1 khi tạo 3  máy ảo:
 +  * Máy lb1.nukeviet.vn  chạy engix, mysql, memcache
 +  * Máy webapp1.nukeviet.vn, webapp2.nukeviet.vn xử lý PHP.
 +  * Dùng apache-jmeter-2.13 từ 1 máy khác cho 1000 kết nối đồng thời, thực hiện xong trong 8 giây.
 +
 +{{:web_server:thutai.jpg|}}
 +
 +Tham khảo: 
 +
 +  - http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/
 +  - https://www.scalescale.com/tips/nginx/store-php-sessions-memcached/
 +  - https://www.digitalocean.com/community/tutorials/how-to-share-php-sessions-on-multiple-memcached-servers-on-ubuntu-14-04
 +  - https://www.scalescale.com/tips/nginx/install-php-zend-opcache-cache-web-stats-nginx/
 +  - https://www.scalescale.com/tips/nginx/mount-directory-into-ram-memory-better-performance/
 +  - https://www.scalescale.com/tips/nginx/nfs-server-centos-6-nginx/
 +  - https://www.scalescale.com/tips/nginx/lsyncd-live-file-syncronization-linux/
 +  - http://www.if-not-true-then-false.com/2013/install-mariadb-on-fedora-centos-rhel/
 +  - https://www.scalescale.com/tips/nginx/remote-mysql-database/
 +  - https://www.scalescale.com/tips/nginx/enable-mysql-log-slow-queries-linux/
 +  - https://www.scalescale.com/tips/nginx/minify-css-javascript/
web_server/cai-dat-server-chi-tai-cao.1449401793.txt.gz · Sửa đổi lần cuối: 2015/12/06 18:36 bởi vuthao