26_Linux Basics-Project Outline-Review ansible-dns-nfs-nginx

1. ansible#


What is it? What does it consist of?
What is its purpose?
paramiko --> This library/module enables ssh functionality in ansible

What is it?

ansible is the name of an automation operations tool

What does it consist of?

Components of ansible:

  1. Host inventory -- defines the clients and categorizes them: db, web, etc.

  2. Playbook -- a script that instructs the hosts to perform certain tasks according to the given script

  3. Module -- a program that implements individual functions

  4. Plugin -- implements additional small functions

What is its purpose?

Installing software, uninstalling software, modifying configurations, applying patches, creating backups, running scripts (operations work)

ansible is written in Python and uses ssh as the underlying protocol

paramiko --> This library/module enables ssh functionality in ansible

sshpass module --> Linux command that enables ssh login

[root@cPen_A ~]# ansible --version # Note: Check version
ansible 2.9.15

2. grep#

# grep related commands
[root@cPen_B network-scripts]# cat /etc/passwd|grep -B 5 mail # Note: View the previous 5 lines
[root@cPen_B network-scripts]# cat /etc/passwd|grep -A 5 mail # Note: View the next 5 lines
[root@cPen_B network-scripts]# cat /etc/passwd|grep -C 5 mail # Note: View the previous and next 5 lines

[root@cPen_A ~]# vim /etc/ansible/ansible.cfg # Note: ansible configuration file
forks = 5 # Note: Start 5 processes to handle -f option

IP address not displayed
service NetworkManager stop # Note: This service affects it
service network restart

template template --> Most of it is fixed, with a few variables based on values retrieved from ansible

[root@cPen_A ansible]# ansible web -m setup # Note: View information of the node server in dictionary format | SUCCESS => {
    "ansible_facts": {
[root@cPen_A ansible]# ansible web -m setup -a "filter=ansible_all_ipv4_addresses"
# Note: Filter to obtain specific information
# Note: Get the IPV4 address of the ansible-demo3 host | SUCCESS => {
    "ansible_facts": { # Note: ansible facts
        "ansible_all_ipv4_addresses": [
        "discovered_interpreter_python": "/usr/bin/python"
    "changed": false

ssh = paramiko.SSHClient()
ssh.connect("IP address", 22, "username", "password")
Solving the problem of needing to enter "yes" when using password connection for the first ssh

[root@C ansible]# vim hosts
[db] ansible_ssh_user=root ansible_ssh_pass=123456

[root@C ansible]# vim ansible.cfg
# uncomment this to disable SSH key host checking
host_key_checking = False

api interface --> application interface
# Note: Write interface
json What is it used for? Lightweight data exchange format

[root@cPen_A ansible]# ansible-doc -l # Note: View ansible modules
# Note: doc document, l list

latest means installation, not necessarily the latest


Project Name: Deploying nginx cluster and mysql cluster in batches using ansible
Project Environment: centos8.2, ansible2.9.15, nginx1.19.5, mysql5.7.31
Project Description:
	Use ansible to deploy 6 nginx servers, 1 NFS file server, and 3 MySQL servers in batches. Nginx is installed by compiling the source code, MySQL is installed using binary installation, and NFS is installed using the yum installation method. Scripts for compiling and installing nginx and MySQL are prepared in advance and executed on nginx and MySQL servers using ansible, achieving batch automated deployment using playbooks.
Project Steps:
	1. Deploy 11 Linux virtual machines with CentOS 8.2 installed and configured with 1 core and 2GB of memory.
	2. Install and deploy ansible on one of the Linux systems using yum.
	3. Prepare a script for one-click installation of nginx, along with the nginx.conf configuration file, for later use in playbooks.
	4. Prepare a script for one-click installation of MySQL, along with the my.cnf configuration file, for later use in playbooks.
	5. Establish ssh passwordless communication between the ansible server and all nginx, MySQL, and NFS servers.
	6. Finally, write ansible playbook files to deploy nginx, MySQL, and NFS servers.
	7. Test the success of the entire installation and deployment.
Project Insights:
	1. Gained some understanding of the use of ansible in large-scale clusters and experienced the convenience of batch deployment.
	2. Developed a certain understanding of clusters.
	3. Improved scripting skills.
	4. Enhanced troubleshooting ability through troubleshooting various issues.
When writing a project
1. Present the data


What is it? What is it used for?

nginx is a web server

web refers to websites


domain name system --> ip

Why do we need DNS?

To easily remember a website name

IP addresses are difficult to remember

Forward lookup: domain name --> ip

Reverse lookup: ip --> domain name

What happens when you enter in the browser?

  1. Browser cache

  2. Hosts file

  3. Local DNS server

  4. Forwarding server

  5. Root domain server

  6. Iterative process

  7. Recursive return

  8. Direct access

CDN Content Delivery Network: Acceleration (nearest resolution)

Note: There is a delay in caching#

Note: CDN is heavily used in video services#

Record types

A record --> address record

www -->

What are the steps (tasks to be done) to launch your own website?

  1. Purchase a cloud server and deploy nginx, mysql, Python, and other environments

  2. Purchase a domain name and bind the domain name to the cloud server --> A record --> Record the server in China (required for domestic servers)

  3. Develop the website --> Write the website

  4. Test the website

  5. Upload it to the nginx web root directory on the cloud server --> Go live

[root@cPen_C lianxi]# yum provides nslookup
# Note: Check which package provides the nslookup command


Network File System

What is it used for?

Sharing files --> Multiple servers use the same content

Note: NFS is the cheapest liberation solution, but it is affected by network, low server hardware configuration, disk speed, CPU, memory, and network bandwidth are relatively poor#

Note: More expensive solutions: professional storage#

Note: Better solutions are SAN fiber devices#

SAN -->

NAS --> Network Attached Storage

SAN generally refers to Storage Area Network. Storage Area Network (SAN) uses Fibre Channel (FC) technology to connect storage arrays and server hosts through FC switches to establish a dedicated network for data storage.

NAS (Network Attached Storage) is a device connected to the network with data storage capabilities, so it is also called "network storage".




nginx one-click deployment

Website launch




nginx one-click installation script


mkdir -p /nginx2
cd /nginx2
#download nginx
curl -O

#create user
useradd lihu

tar xf nginx-1.17.9.tar.gz 

#enter the unzipped directory
cd nginx-1.17.9

#resolve dependencies
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make 

./configure --prefix=/usr/local/nginx9 --user=lihu --group=lihu --with-threads --with-file-aio --with-http_ssl_module --with-http_stub_status_module --with-stream 

#compile and install
make -j 2 ; make install

#start on boot
echo "/usr/local/nginx9/sbin/nginx" >>/etc/rc.local 
chmod +x /etc/rc.d/rc.local 

#modify PATH variable
echo "PATH=/usr/local/nginx9/sbin:$PATH" >>/etc/profile

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.