In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to use ACK and NAS to quickly build flexible NGINX sites". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Scene introduction
This article describes how to build a simple elastic and highly available NGINX website through Ali Cloud Container ACK service and File Storage NAS service within half an hour. After completing all the operations in this article, you will get a single-page website, and users' requests will be scattered to multiple container nodes, and the capacity will be automatically expanded and reduced according to the business load. Even if a container node goes down, user access will not be affected. In addition, you can quickly update locally edited pages to the site.
Background knowledge
The cloud products used in this tutorial are as follows:
CVM ECS
Elastic Compute Service (ECS) is an IaaS (Infrastructure as a Service) level cloud computing service with excellent performance, stability and reliability, and elastic expansion provided by Aliyun. CVM ECS eliminates the preparation for purchasing IT hardware, allowing you to use the server as easily and efficiently as water, electricity, natural gas and other public resources, realizing ready-to-use and auto scaling of computing resources. Aliyun ECS continues to provide innovative servers to address a variety of business needs and help your business development.
File storage NAS
Aliyun Network Attached Storage (NAS) is a file storage service for computing nodes such as Aliyun ECS instance, E-HPC and container service. NAS provides simple scalable file storage for use with ECS, multiple ECS instances can access the NAS file system at the same time, and storage capacity automatically resiliently grows and shrinks as you add and delete files, providing a common data source for workloads and applications running on multiple instances or servers.
Kubernetes version of CCS
Ali Cloud CCS Kubernetes ACK (Alibaba Cloud Container Service for Kubernetes) is the world's first Kubernetes-certified service platform, providing high-performance container application management services and supporting the lifecycle management of enterprise-class Kubernetes containerized applications, allowing you to easily and efficiently run Kubernetes containerized applications on the cloud.
There are seven steps in this tutorial, the first five steps can be completed to achieve a resilient and highly available NGINX website, and the last two steps verify the elasticity and high availability properties of the site.
Step 1: create resources step 2: mount file system NAS to ECS server step 3: upload files to NAS step 4: configure NAS mount information step 5: create NGINX application step 6: visit test website step 7: verify service high availability step 8: verify elastic scaling
Step 1: start the experience
Cloud product resource experience address: https://developer.aliyun.com/adc/scenario/57f4d9ac091a4b539a261ff2ef657ff0
Open cloud product resources
Step 2: Mount the file system NAS to the ECS server
Aliyun File Storage NAS is a distributed file system with shared access, flexible extension, high reliability and high performance. It can provide persistent storage services for containers. In the next operation, your web page files will be saved in the NAS file system. When the container pod is created, you can directly call the files in the NAS, and after the pod is destroyed, the files in the NAS will continue to be retained. 1. Log in to the NAS file system console using the sub-account provided by the resource (you can use the browser's seamless mode). two。 Click the list of file systems in the left boot bar, and then click file system ID to enter the file system details page. 3. Click Mount use, view the mount point information, and copy the mount command. 4. Open the terminal tool and enter the connection command ssh [username] @ [ipaddress] in the terminal. You need to replace the username and ipaddress with the public network IP of the ECS server provided by the resource. For example:
Ssh root@123.123.123.123
The command displays the following results: 5. Execute the following command in the terminal to mount the NAS to the ECS server. Install the NFS client.
Sudo yum install nfs-utils
Execute the mount command copied in step 3 to mount NAS to the / mnt directory of ECS.
Sudo mount-t nfs-o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport 3*7.cn-shanghai.nas.aliyuncs.com:/ / mnt step 3: upload files to NAS
After building the NGINX service using the ACK cluster, when you open the home page of the website, the container will read the uploaded web page file from the NAS file system and return it to the browser. After the website has been built, you can update the files in NAS in the same way. 1. Create an index.html file locally.
Windows system: open a text editor, type test index page for nginx-nas-demo, and save the file type as a HTML file.
MacOS or Linux: open the command line tool and execute the following command.
Mkdir-p ~ / Documents/nginx-nas-demoecho "test index page for nginx-nas-demo" > ~ / Documents/nginx-nas-demo/index.html
two。 Download and install the SFTP client, for example: FileZilla. 3. Upload the index.html file to NAS.
Double-click to run FileZila.
According to the following information, connect to the server. Host: ECS public network IP provided by resources. User name: root password: ECS password provided by the resource. Port: 22.
Find the locally created index.html file in the left directory tree, enter / mnt in the right directory tree, and enter the NAS directory.
Drag the index.html from the left area to the right area to upload the local file to NAS. 4. You can use step 2 to remotely connect to ECS and view the index.html file you just uploaded in the / mnt directory.
Step 4: configure NAS mount information
To mount using NAS using ACK services, you need to configure container storage volume PV and storage declaration PVC information, which will be used when you deploy NGINX applications. 1. Configure storage volumes. Enter the ACK cluster list and click the ACK cluster name to enter the cluster details page. Click the storage volume in the left boot bar. Click the Storage Volume tab, and then click create. Select the NAS storage volume type, fill in the storage volume name, select the NAS mount point, and then click create. The operation flow is shown in the figure below. Figure 1: figure 2: 2. Configure the storage declaration. 1. Click the storage volume in the left navigation bar. two。 Click the storage declaration, and then click create. 3. Configure the storage declaration according to the following information. Storage declaration type: select NAS. Name: fill in the storage declaration name, for example: nas-pvc. Allocation mode: select an existing storage volume. Existing storage volume: select the storage volume created in the previous step. Total amount: this column has no practical restriction meaning for NAS, just keep the default value.
Step 5: create a NGINX application
1. To enter the cluster details page, click the workload in the left boot bar, and in the default stateless tab, click create using Mirror.
two。 On the Application basic Information page, fill in the application name, and then click next. 3. Container configuration. a. "on the Container configuration page, click Select Image." b. In the pop-up dialog box, click search, select Docker image, fill in nginx, and then click search. c. Select the nginx official image in the search results and click OK. d. Pull the container configuration page to the bottom, click add Cloud Storage statement (PersistentVolumeClaim) in the data volume bar, select the storage declaration created in step 2 as the mount source, and enter / usr/share/nginx/html/ in the container path. Indicates that this configuration mounts NAS to the / usr/share/nginx/html/ path of the container, which is the directory where NGINX stores index.html by default.
e. Other configurations on this page can be configured with default values. Click the next button to continue.
Advanced configuration. a. On the Advanced configuration page, click create to the right of Service (Service). Set the following information in the port mapping of the pop-up create service dialog box, and then click create. Name: http (http must be all lowercase, otherwise the creation will fail). Service port: 80. Container port: 80. Protocol: TCP. Indicate that other options can be kept at their default values.
b. Click create to the right of the Ingress. Configure the following information in the rule entry of the create dialog box that pops up, and then click create.
Domain name: your website domain name, for example: foo.bar.com. If you don't have a domain name, you can fill in a test domain name at will.
Service: select the nginx-nas-svc service created in the previous step. Indicate that other options can be kept at their default values. At this point, the routing column should display information about the domain name and the corresponding service. The routing function will scatter user requests to multiple container nodes for processing through a simple fan out method. c. Check the box behind the horizontal scaling of the container group, and then wait for the creation to succeed in the minimum pair.
Step 6: visit the test website
After waiting for the configuration of the NAS and the container, you can use your local computer to access the test website. 1. Configure the hosts file for the office computer. Note: if you are using the official website domain name in the NGINX application configuration and have been approved for the record, you can skip this step and open the website directly through the browser. If you are using a test domain name (such as foo.bar.com), you need to configure the hosts file on your local computer to have the browser transfer the request for the domain name to the IP address of the ACK cluster. a. Go to the workload page of the ACK console. b. Click the name of the NGINX service created in step 3. c. Click the access method tab and copy the IP address of the endpoint of the route to the pasteboard. This IP address is the IP address used by the public network access website. d. Open the local C:\ Windows\ System32\ drivers\ etc\ hosts file with administrator privileges, add the endpoint IP and the domain name set in step three to the hosts file, and then save and exit, as shown in the following figure. Description: for Linux and Mac systems, please modify the / etc/hosts file.
two。 Open the website using a browser. Note: if you cannot access it properly, you can try emptying the browser cache or accessing it in seamless browsing mode.
Step 7: verify that the service is highly available
Because when deploying NGINX applications, the minimum number of copies of the container group is 2, so when one container host node is down, the website can still be served by another container host node, ensuring the high availability of the service. 1. Simulate node failure. a. Click the left guide bar node management on the cluster details page to enter the node management page. b. Select 2 of the nodes, then click the Action Bar Node maintenance below to check the empty node in the pop-up dialog box, and then click OK. At this point, you can see that the node status is unschedulable. c. Open the website using a browser and find that it can still be accessed normally. two。 Restore the node. a. Click OK below in the pop-up dialog box on the upper line of the action bar node. b. Open the website using a browser and find that it can still be accessed normally.
Step 8: verify elastic expansion
1. View the initial state of the container group. a. Go to the workload page of the ACK console and click the name of the NGINX service created in step 3. b. Click the container group horizontal scaler to view the current number of copies and the current CPU utilization of the container group. two。 Simulate the high load of the container. a. Click on the top right of the cluster details page to manage the cluster through CloudShell to enter the CloudShell command line. b. On the command line, execute the following command to view the node.
Kubectl get pod
c. Execute the following command to enter the container.
Kubectl exec-it lalala-***pod-name****-kxjbg bashd. Execute the following command to simulate the high load of the container. Fulload () {dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null &}; fulload; read
3. Confirm automatic expansion. a. Go to the workload page of the ACK console and click the name of the NGINX service created in step 3. b. Click the container group horizontal scaler to view the current number of copies and the current CPU utilization of the container group. If you wait a little longer, you can see a significant increase in current CPU usage. Wait a few minutes and check again and find that the current number of copies has changed to 10. c. At this point, open the website using a browser and find that it can still be accessed normally. 4. Release the high load of the container. a. Enter the CloudShell command line. b. Execute the following command on the command line.
That's all for "how to use ACK and NAS to quickly build a flexible NGINX website". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.