当前位置:   article > 正文

RHCE---服务+ansible

ens224 ethernet connecting (getting ip configuration) wired connection 2

一、命令提示符颜色

  1. 也可以写入配置文件/etc/profile
  2. [root@master ~]# vim .bashrc
  3. 绿色:
  4. PS1='\[\033[01;32m\]\u@\H:\[\033[01;34m\]\w\$\[\033[00m\] '
  5. 粉红色:
  6. PS1='\[\e[1;35m\]\u@\h:\[\e[0m\]\[\e[1;33m\]\w\[\e[1;35m\]\[\e[0m\]\[\e[1;34m\]\$ \[\e[0m\]'
  7. [root@master ~]# source .bashrc

详解:

  1. [root@master ~]# echo $PS1
  2. [\u@\h \W]\$
  3. 那么里面的 [\u@\h \W]$分别代表什么呢?
  4. PS1(是数字1而不是字母l),每个版本bash的PS1变量内的特殊符号可能有些小的差异,
  5. 你可以先man bash 一下。
  6. 下面是RedHat7环境下默认的特殊符号所代表的意义:
  7. \d :代表日期,格式为weekday month date,例如:"Mon Aug 1"
  8. \H :完整的主机名称。例如:我的机器名称为:RedHat7.linux,则这个名称就是RedHat7.linux
  9. \h :仅取主机的第一个名字,如上例,则为RedHat7,而.linux则被省略
  10. \t :显示时间为24小时格式,如:HH:MM:SS
  11. \T :显示时间为12小时格式
  12. \A :显示时间为24小时格式:HH:MM
  13. \u :当前用户的账号名称
  14. \v :BASH的版本信息
  15. \w :完整的工作目录名称。家目录会以 ~代替
  16. \W :利用basename取得工作目录名称,所以只会列出最后一个目录
  17. \# :下达的第几个命令
  18. \$ :提示字符,如果是root时,提示符为:# ,普通用户则为:$
  19. 默认的PS1内容为: PS1='[\u@\h \W]\$ '
  20. 所以默认的提示符就是: [root@linux ~]#
  21. 当我们了解上述参数之后,在实际操作过程中,我们如果想显示主机全名以及完整的工作目录,我们就需要修改PS1的相应参数,并写入/etc/profile文件中 例如:修改前,我们默认的PS1对于主机名、目录都只是显示一部分,
  22. [root@RedHat7 ~]# hostname
  23. RedHat7.linux
  24. [root@RedHat7 ~]#
  25. [root@RedHat7 ~]# cd /etc/sysconfig/network-scripts/
  26. [root@RedHat7 network-scripts]#
  27. 现在我们想让主机名和工作路径全部显示出来,根据上面参数,我们需要用到大写的H和小写的w,我们用echo命令将修改后的PS1追加到 /etc/profile文件中(不建议这样操作,最好还是vim 进到文件去编辑好些),并更新该文件
  28. [root@RedHat7 ~]# echo "PS1='[\u@\H \w]\$' " >> /etc/profile
  29. [root@RedHat7 ~]# source /etc/profile
  30. 如果是在虚拟机里面或者是Xshell中,我们可能还要重启或断开连接再次连接才能看到结果。
  31. [root@RedHat7.linux ~]$ cd /etc/sysconfig/network-scripts/
  32. [root@RedHat7.linux /etc/sysconfig/network-scripts]$
  33. 此时,我们可以看到主机全名和工作路径的全部
  34. 颜色值设置
  35. PS1中设置字符颜色的格式为:\[\e[F;Bm\],\[\e[0m\] 其中
  36. “F“为字体颜色,编号为30-37,
  37. “B”为背景颜色,编号为40-47。用 \[\e[0m\]结束颜色设置,颜色表如下:
  38. F    B
  39. 30    40    黑色
  40. 31    41    红色
  41. 32    42    绿色
  42. 33    43    黄色
  43. 34    44    蓝色
  44. 35    45    紫红色
  45. 36    46    青蓝色
  46. 37    47    白色
  47. 根据颜色表,套用入字符颜色设置格式中,就可以对linux终端命令行颜色进行个性化设置。
  48. 比如要设置命令行的格式为绿字黑底,显示当前用户的账号名称、
  49. 主机的第一个名字、完整的当前工作目录名称、24小时格式时间,就可以使用如下的命令:
  50. export PS1='\[\e[30;1m\][\u@\h \w]\$ \[\e[0m\] -----黑色提示符
  51. export PS1='\[\e[31;1m\][\u@\h \w]\$ \[\e[0m\] -----红色提示符
  52. export PS1='\[\e[32;1m\][\u@\h \w]\$ \[\e[0m\] -----绿色提示符
  53. export PS1='\[\e[33;1m\][\u@\h \w]\$ \[\e[0m\] -----黄色提示符
  54. export PS1='\[\e[34;1m\][\u@\h \w]\$ \[\e[0m\] -----蓝色提示符(天蓝)
  55. export PS1='\[\e[35;1m\][\u@\h \w]\$ \[\e[0m\] -----粉色提示符
  56. export PS1='\[\e[36;1m\][\u@\h \w]\$ \[\e[0m\] -----蓝色提示符(海蓝)
  57. export PS1='\[\e[37;1m\][\u@\h \w]\$ \[\e[0m\] -----白色提示符

环境准备:

  1. 1.至少俩台linux主机,一台是控制节点,一台是受控节点
  2. 2.控制节点和受控节点都需要安装Python36
  3. 3.控制节点需要安装ansible
  4. 4.控制节点需要获得受控节点的普通用户或root用户的权限,控制节点需要ssh客户端,受控节点需要ssh服务端
  5. 5.控制节点和受控节点之间网络联通,配置静态ip

二、环境安装:

主机名IP地址角色
master172.25.250.132控制节点
node01172.25.250.128受控节点
node02172.25.250.129受控节点

1、替换yum源,方便安装软件:----阿里

  1. sed -e 's|^mirrorlist=|#mirrorlist=|g' \
  2. -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
  3. -i.bak \
  4. /etc/yum.repos.d/Rocky-*.repo
  5. dnf makecache

2、安装常用工具:

yum install -y bash-completion tree lrzsz  vim  net-tools.x86_64  unzip   lsof  wget

3、修改主机名

  1. master: hostnamectl set-hostname master
  2. node01:hostnamectl set-hostname node01
  3. node02:hostnamectl set-hostname node02

4、配置ip地址:

master:俩张网卡NAT和桥接模式

node01 node02:桥接模式

  1. master主机上的配置:
  2. 1.查看状态:
  3. [root@master ~]# nmcli device
  4. DEVICE TYPE STATE CONNECTION
  5. ens160 ethernet connected ens160
  6. ens224 ethernet connecting (getting IP configuration) Wired connection 1
  7. lo loopback unmanaged --
  8. [root@master ~]# nmcli connection
  9. NAME UUID TYPE DEVICE
  10. Wired connection 1 408f15fc-eaa9-3a51-ae18-d9673dcbabab ethernet ens224
  11. ens160 b4725590-2691-43b0-b2a8-7eae81ee470a ethernet ens160
  12. 2、添加ip,网关,dns,改为手动,开机自启
  13. [root@master ~]# cd /etc/sysconfig/network-scripts/
  14. [root@master network-scripts]# ll
  15. total 4
  16. -rw-r--r--. 1 root root 247 Dec 13 09:34 ifcfg-ens160
  17. [root@master network-scripts]# cat ifcfg-ens160
  18. TYPE=Ethernet
  19. PROXY_METHOD=none
  20. BROWSER_ONLY=no
  21. BOOTPROTO=dhcp
  22. DEFROUTE=yes
  23. IPV4_FAILURE_FATAL=no
  24. IPV6INIT=yes
  25. IPV6_AUTOCONF=yes
  26. IPV6_DEFROUTE=yes
  27. IPV6_FAILURE_FATAL=no
  28. NAME=ens160
  29. UUID=b4725590-2691-43b0-b2a8-7eae81ee470a
  30. DEVICE=ens160
  31. ONBOOT=yes ---改为yes
  32. 3、修改master主机桥接网卡的ip地址:
  33. [root@master ~]# nmcli device
  34. DEVICE TYPE STATE CONNECTION
  35. ens160 ethernet connected ens160
  36. ens224 ethernet connecting (getting IP configuration) Wired connection 1
  37. lo loopback unmanaged
  38. [root@master network-scripts]# nmcli device connect ens224 ---自动创建connection,如果有俩个网段就可以实现
  39. 但是我在家在学校只有一个192.168.x.x的地址,包括后面俩台node也配不上
  40. [root@master network-scripts]# nmcli device connect ens224
  41. Error: Connection activation failed: (5) IP configuration could not be reserved (no available address, timeout, etc.).

5、网卡改为仅主机模式:

  1. 仅主机:172.25.250.x 255.255.255.0
  2. master:192.168.11.154---NAT模式,都可以连接
  3. master:172.25.250.132
  4. node01172.25.250.128
  5. node02:172.25.250.129

6、配置hosts文件:

  1. 172.25.250.132 master
  2. 172.25.250.128 node01
  3. 172.25.250.129 node02

7、xshell配置会话:

  1. 172.25.250.132 master
  2. 172.25.250.128 node01
  3. 172.25.250.129 node02

8、时间同步:

  1. 这里我使用的是仅主机模式,所以受控节点的主机没有互联网,但是三台主机的时间一样的,我就不做配置
  2. 1、安装时间同步软件包:
  3. [root@master ~]# yum install chrony
  4. 2、修改配置文件:
  5. [root@master ~]# vim /etc/chrony.conf
  6. pool 2.rocky.pool.ntp.org iburst
  7. pool ntp1.aliyun.com iburst
  8. pool ntp2.aliyun.com iburst
  9. 3、设置为开机自启:
  10. [root@master ~]# systemctl enable --now chronyd
  11. 4、写计划任务同步:
  12. [root@master ~]# vim /etc/crontab
  13. 0 10 * * * root chronyc sources &>/dev/null

9、装Python36:

  1. 1、每台机器都装:接下来的操作都在master上
  2. yum install python36 -y
  3. 2、不用root权限,权限太高了;在master主机上创建student 密码redhat;在node节点上用的redhat用户,密码redhat
  4. [root@node01 ~]# vim /etc/sudoers
  5. root ALL=(ALL) ALL
  6. redhat ALL=(ALL) NOPASSWD: ALL
  7. 强制保存退出
  8. 如果用的visudo打开就不用,正常退出就行
  9. 3、测试:
  10. [root@master ~]# visudo
  11. [root@master ~]#
  12. [root@master ~]#
  13. [root@master ~]# su - student
  14. Last login: Tue Dec 13 12:17:40 CST 2022 on pts/0
  15. [student@master ~]$ sudo ls /root
  16. anaconda-ks.cfg

10、安装ansible:

  1. 1、阿里云下载扩展源:epel
  2. [student@master ~]$ sudo yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
  3. 也可以自己写源:
  4. [epel]
  5. name=epel
  6. baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
  7. gpgcheck=0
  8. 2、安装ansible:
  9. [student@master ~]$ yum install ansible -y
  10. 3、查看ansible版本信息:
  11. [student@master ~]$ ansible --version
  12. ansible [core 2.13.3]
  13. config file = /etc/ansible/ansible.cfg
  14. configured module search path = ['/home/student/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  15. ansible python module location = /usr/lib/python3.9/site-packages/ansible
  16. ansible collection location = /home/student/.ansible/collections:/usr/share/ansible/collections
  17. executable location = /usr/bin/ansible
  18. python version = 3.9.13 (main, Nov 16 2022, 15:31:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  19. jinja version = 3.1.2
  20. libyaml = True

11、配置免密登录:

  1. 1、在master主机上创建密钥对:
  2. [student@master ~]$ ssh-copy-id redhat@node02
  3. /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/student/.ssh/id_rsa.pub"
  4. The authenticity of host 'node02 (172.25.250.129)' can't be established.
  5. ECDSA key fingerprint is SHA256:723ytDI+oeyH5SeBHONt70U2NspX11SZ5lwzBASGLy4.
  6. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
  7. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  8. /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
  9. redhat@node02's password:输入密码
  10. Number of key(s) added: 1
  11. Now try logging into the machine, with: "ssh 'redhat@node02'"
  12. and check to make sure that only the key(s) you wanted were added.
  13. 2、测试:
  14. 在master连接node节点:
  15. [student@master ~]$ ssh redhat@node01
  16. Last login: Tue Dec 13 12:12:43 2022
  17. [redhat@node01 ~]$

12、环境搭好了,做好快照

所有的密码都是redhat

三、简单操作:

ansible清单和配置文件

1、定义清单文件:

  1. 1、创建一个文件夹存放::
  2. [student@master ~]$ mkdir ansibleTest
  3. [student@master ~]$ cd ansibleTest/
  4. [student@master ansibleTest]$
  5. 2、编写文件,注意优先级
  6. [student@master ~]$ sudo vim /etc/ansible/hosts
  7. 这是在默认配置文件中的主机清单文件:
  8. [student@master ~]$ tail -2 /etc/ansible/hosts
  9. node01
  10. node02
  11. 这是在自定义的主机清单文件,-i指定清单文件文件名:
  12. [student@master ansibleTest]$ ansible all --list-hosts -i ./inventory
  13. hosts (3):
  14. node01
  15. node02
  16. master
  17. 这是查看主机组里面的主机文件:
  18. [student@master ansibleTest]$ ansible webserver --list-hosts -i ./inventory
  19. hosts (2):
  20. node01
  21. node02

2、执行清单文件:

  1. [student@master ~]$ ansible all --list-hosts
  2. hosts (2):
  3. node01
  4. node02

3、修改配置文件

  1. 1、自定义ansible.cfg,这几条信息都需要写
  2. [student@master ansibleTest]$ cat ./ansible.cfg
  3. [defaults]
  4. inventory= ./inventory
  5. remote_user = redhat
  6. ask_pass = false
  7. [privilege_escalation]
  8. become = True
  9. become_method = sudo
  10. become_user = root
  11. become_ask_pass = False

4、简单测试:

  1. 1.masterping不通。因为没有免密做student免密登录redhat:
  2. [student@master ansibleTest]$ ansible all -m ping
  3. The authenticity of host 'master (172.25.250.132)' can't be established.
  4. ECDSA key fingerprint is SHA256:NeqtJaCF7cvzBynyHDzGp4j1w6qIRrF2du45YRldvB8.
  5. Are you sure you want to continue connecting (yes/no/[fingerprint])? node01 | SUCCESS => {
  6. "ansible_facts": {
  7. "discovered_interpreter_python": "/usr/libexec/platform-python"
  8. },
  9. "changed": false,
  10. "ping": "pong"
  11. }
  12. node02 | SUCCESS => {
  13. "ansible_facts": {
  14. "discovered_interpreter_python": "/usr/libexec/platform-python"
  15. },
  16. "changed": false,
  17. "ping": "pong"
  18. }
  19. 这里master上面的redhat需要密码,但是在清单文件中是ask_pass = false,所以ping不通master
  20. root ALL=(ALL) ALL
  21. student ALL=(ALL) NOPASSWD: ALL
  22. redhat ALL=(ALL) NOPASSWD:ALL
  23. 添加redhat进去
  24. 2、把公钥私钥用student用户传给redhat
  25. [student@master ansibleTest]$ ssh-copy-id redhat@master
  26. 测试:
  27. [student@master ansibleTest]$ ansible all -m ping
  28. node02 | SUCCESS => {
  29. "ansible_facts": {
  30. "discovered_interpreter_python": "/usr/libexec/platform-python"
  31. },
  32. "changed": false,
  33. "ping": "pong"
  34. }
  35. node01 | SUCCESS => {
  36. "ansible_facts": {
  37. "discovered_interpreter_python": "/usr/libexec/platform-python"
  38. },
  39. "changed": false,
  40. "ping": "pong"
  41. }
  42. master | SUCCESS => {
  43. "ansible_facts": {
  44. "discovered_interpreter_python": "/usr/libexec/platform-python"
  45. },
  46. "changed": false,
  47. "ping": "pong"
  48. }
  49. 学会看日志

5、几个清单文件的优先级:

[student@master ansibleTest]$ ll /etc/ansible/ansible.cfg  ~/ansible.cfg   ./ansible.cfg

运行临时命令

1、创建文件:

  1. 1、file模块:
  2. [student@master ansibleTest]$ ansible-doc -l ---查看所有模块
  3. [student@master ansibleTest]$ ansible-doc file ---查看file模块的用法
  4. [student@master ansibleTest]$ ansible all -m ping -v ---ping模块
  5. Using /home/student/ansibleTest/ansible.cfg as config file ---使用的配制文件
  6. node01 | SUCCESS => {
  7. "ansible_facts": {
  8. "discovered_interpreter_python": "/usr/libexec/platform-python"
  9. },
  10. "changed": false,
  11. "ping": "pong"
  12. }
  13. node02 | SUCCESS => {
  14. "ansible_facts": {
  15. "discovered_interpreter_python": "/usr/libexec/platform-python"
  16. },
  17. "changed": false,
  18. "ping": "pong"
  19. }
  20. master | SUCCESS => {
  21. "ansible_facts": {
  22. "discovered_interpreter_python": "/usr/libexec/platform-python"
  23. },
  24. "changed": false,
  25. "ping": "pong"
  26. }

作业:

  1. 使用yum和service模块安装和启动httpd服务,但是我node没有网,所以下载不了
  2. [student@master ansibleTest]$ ansible all -m yum -a 'name=httpd state=present'
  3. [student@master ansibleTest]$ ansible all -m service -a 'name=httpd state=started'
  4. 这里我把受控节点也添加了俩张网卡,一个仅主机一个NAT
  5. [student@master ansibleTest]$ ansible all -m yum -a 'name=httpd state=present'
  6. node01 | SUCCESS => {
  7. "ansible_facts": {
  8. "discovered_interpreter_python": "/usr/libexec/platform-python"
  9. },
  10. "changed": false,
  11. "msg": "Nothing to do",
  12. "rc": 0,
  13. "results": []
  14. }
  15. node02 | SUCCESS => {
  16. "ansible_facts": {
  17. "discovered_interpreter_python": "/usr/libexec/platform-python"
  18. },
  19. "changed": false,
  20. "msg": "Nothing to do",
  21. "rc": 0,
  22. "results": []
  23. }
  24. master | SUCCESS => {
  25. "ansible_facts": {
  26. "discovered_interpreter_python": "/usr/libexec/platform-python"
  27. },
  28. "changed": false,
  29. "msg": "Nothing to do",
  30. "rc": 0,
  31. "results": []
  32. }
  33. 测试:
  34. [student@master ansibleTest]$ ansible all -m shell -a 'systemctl is-active httpd'
  35. node02 | CHANGED | rc=0 >>
  36. active
  37. node01 | CHANGED | rc=0 >>
  38. active
  39. master | CHANGED | rc=0 >>
  40. active

playbook

1、编写一个确保chrond服务开机自启:

  1. 1、安装chrony服务:---注意服务名称呀!!!!
  2. [student@master ansibleTest]$ ansible all -m yum -a 'name=chrony state=present'
  3. node01 | SUCCESS => {
  4. "ansible_facts": {
  5. "discovered_interpreter_python": "/usr/libexec/platform-python"
  6. },
  7. "changed": false,
  8. "msg": "Nothing to do",
  9. "rc": 0,
  10. "results": []
  11. }
  12. master | SUCCESS => {
  13. "ansible_facts": {
  14. "discovered_interpreter_python": "/usr/libexec/platform-python"
  15. },
  16. "changed": false,
  17. "msg": "Nothing to do",
  18. "rc": 0,
  19. "results": []
  20. }
  21. node02 | CHANGED => {
  22. "ansible_facts": {
  23. "discovered_interpreter_python": "/usr/libexec/platform-python"
  24. },
  25. "changed": true,
  26. "msg": "",
  27. "rc": 0,
  28. "results": [
  29. "Installed: timedatex-0.5-3.el8.x86_64",
  30. "Installed: chrony-4.2-1.el8.rocky.1.0.x86_64"
  31. ]
  32. }
  33. 2、编写playbook:
  34. ---
  35. - name: enable chronyd
  36. hosts: all
  37. tasks:
  38. - name: enable chrony service
  39. service:
  40. name: chronyd
  41. enabled: yes
  42. 3、运行playbook:
  43. [student@master ansibleTest]$ ansible-playbook chrony_service.yaml
  44. PLAY [enable chronyd] ************************************************************************************************************************
  45. TASK [Gathering Facts] ***********************************************************************************************************************
  46. ok: [node01]
  47. ok: [node02]
  48. ok: [master]
  49. TASK [enable chrony service] *****************************************************************************************************************
  50. ok: [node01]
  51. ok: [node02]
  52. ok: [master]
  53. PLAY RECAP ***********************************************************************************************************************************
  54. master : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  55. node01 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  56. node02 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  57. 执行成功结果!!!

2、语法检测:

  1. [student@master ansibleTest]$ ansible-playbook --syntax-check chrony_service.yaml
  2. playbook: chrony_service.yaml

实验:

案例一:安装http 启动防火墙,写入测试页index.html

  1. 1、编写playbook:
  2. ---
  3. - name: configer web server
  4. hosts: webs
  5. tasks:
  6. - name: install httpd
  7. yum:
  8. name: httpd
  9. state: present
  10. - name: start firwalld
  11. service:
  12. name: firewalld
  13. state: started
  14. - name: firewalld allow httpd
  15. firewalld:
  16. service: http
  17. state: enabled
  18. - name: copy index.html
  19. copy:
  20. content: "this is web test"
  21. dest: /var/www/html/idnex.html
  22. - name: test web page
  23. uri:
  24. url: http://localhost
  25. return_content: yes
  26. status_code: 200
  27. 2、语法检测:
  28. [student@master ansibleTest]$ ansible-playbook --syntax-check configer_server.yaml
  29. playbook: configer_server.yaml
  30. 3、运行playbook:
  31. [student@master ansibleTest]$ ansible-playbook configer_server.yaml
  32. PLAY [configer web server] *******************************************************************************************************************
  33. TASK [Gathering Facts] ***********************************************************************************************************************
  34. ok: [node02]
  35. ok: [node01]
  36. TASK [install httpd] *************************************************************************************************************************
  37. ok: [node01]
  38. ok: [node02]
  39. TASK [start firwalld] ************************************************************************************************************************
  40. ok: [node02]
  41. ok: [node01]
  42. TASK [firewalld allow httpd] *****************************************************************************************************************
  43. ok: [node02]
  44. ok: [node01]
  45. TASK [copy index.html] ***********************************************************************************************************************
  46. changed: [node01]
  47. changed: [node02]
  48. TASK [test web page] *************************************************************************************************************************
  49. ok: [node02]
  50. ok: [node01]
  51. PLAY RECAP ***********************************************************************************************************************************
  52. node01 : ok=6 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  53. node02 : ok=6 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

案列二:在上一实验基础上写多个play

  1. 1、编写playbook:
  2. [student@master ansibleTest]$ cat configer_server.yaml
  3. ---
  4. - name: configer web server
  5. hosts: webs
  6. tasks:
  7. - name: install httpd
  8. yum:
  9. name: httpd
  10. state: present
  11. - name: start firwalld
  12. service:
  13. name: firewalld
  14. state: started
  15. - name: firewalld allow httpd
  16. firewalld:
  17. service: http
  18. state: enabled
  19. - name: copy index.html
  20. copy:
  21. content: "this is web test"
  22. dest: /var/www/html/index.html
  23. - name: test web page
  24. uri:
  25. url: http://localhost
  26. return_content: yes
  27. status_code: 200
  28. - name: test web pages
  29. hosts: master
  30. tasks:
  31. - name: test node01 web
  32. uri:
  33. url: http://node01
  34. status_code: 200
  35. - name: test node02 web
  36. uri:
  37. url: http://node02
  38. status_code: 200
  39. 2、测试:
  40. [student@master ansibleTest]$ ansible-playbook configer_server.yaml
  41. PLAY [configer web server] *******************************************************************************************************************
  42. TASK [Gathering Facts] ***********************************************************************************************************************
  43. ok: [node02]
  44. ok: [node01]
  45. TASK [install httpd] *************************************************************************************************************************
  46. ok: [node01]
  47. ok: [node02]
  48. TASK [start firwalld] ************************************************************************************************************************
  49. ok: [node02]
  50. ok: [node01]
  51. TASK [firewalld allow httpd] *****************************************************************************************************************
  52. ok: [node02]
  53. ok: [node01]
  54. TASK [copy index.html] ***********************************************************************************************************************
  55. changed: [node01]
  56. changed: [node02]
  57. TASK [test web page] *************************************************************************************************************************
  58. ok: [node02]
  59. ok: [node01]
  60. PLAY RECAP ***********************************************************************************************************************************
  61. node01 : ok=6 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  62. node02 : ok=6 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

案例三:webserver

  1. 1、编写playbook:
  2. ---
  3. - name: first play
  4. hosts: webs
  5. tasks:
  6. - name: install packages
  7. yum:
  8. name:
  9. - httpd
  10. - php
  11. - firewalld
  12. - mariadb-server
  13. - php-mysqlnd
  14. state: latest
  15. - name: start firewalld
  16. service:
  17. name: firewalld
  18. state: started
  19. enabled: yes
  20. - name: configer firewalld allow http
  21. firewalld:
  22. service: http
  23. permanent: yes
  24. state: enabled
  25. immediate: yes
  26. - name: copy index.php
  27. copy:
  28. src: index.php
  29. dest: /var/www/html/index.php
  30. - name: start httpd
  31. service:
  32. name: httpd
  33. state: restarted
  34. enabled: yes
  35. - name: second play
  36. hosts: master
  37. become: no
  38. tasks:
  39. - name: test web1 page
  40. uri:
  41. url: http://node01
  42. return_content: yes
  43. status_code: 200
  44. - name: test web2 page
  45. uri:
  46. url: http://node02
  47. return_content: yes
  48. status_code: 200
  49. 2、编写php文件:
  50. [student@master ansibleTest]$ cat index.php
  51. <?php
  52. phpinfo();
  53. 3、测试:
  54. [student@master ansibleTest]$ ansible-playbook plays.yaml
  55. PLAY [first play] ****************************************************************************************************************************
  56. TASK [Gathering Facts] ***********************************************************************************************************************
  57. ok: [node02]
  58. ok: [node01]
  59. TASK [install packages] **********************************************************************************************************************
  60. ok: [node01]
  61. ok: [node02]
  62. TASK [start firewalld] ***********************************************************************************************************************
  63. ok: [node02]
  64. ok: [node01]
  65. TASK [configer firewalld allow http] *********************************************************************************************************
  66. ok: [node01]
  67. ok: [node02]
  68. TASK [copy index.php] ************************************************************************************************************************
  69. ok: [node01]
  70. ok: [node02]
  71. TASK [start httpd] ***************************************************************************************************************************
  72. ok: [node01]
  73. ok: [node02]
  74. PLAY [second play] ***************************************************************************************************************************
  75. TASK [Gathering Facts] ***********************************************************************************************************************
  76. ok: [master]
  77. TASK [test web1 page] ************************************************************************************************************************
  78. ok: [master]
  79. TASK [test web2 page] ************************************************************************************************************************
  80. ok: [master]
  81. PLAY RECAP ***********************************************************************************************************************************
  82. master : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  83. node01 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  84. node02 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

作业:在受控节点上添加一个普通用户xiaohong,配置控制节点的student可以免密登录xiaohong用户,并且xiaohong可以sudo。

  1. 1、编写yaml:
  2. [student@master ansibleTest]$ cat user.yaml
  3. ---
  4. - name: generate public/private key pair
  5. hosts: master
  6. become: no
  7. remote_user: student
  8. tasks:
  9. - openssh_keypair:
  10. path: /home/student/.ssh/id_rsa
  11. - name: create user
  12. hosts: node01
  13. tasks:
  14. - name: create user xiaohong
  15. user:
  16. name: xiaohong
  17. state: present
  18. - name: setting passwd
  19. shell: echo redhat | passwd --stdin xiaohong
  20. - name: setting sudoers
  21. lineinfile:
  22. line: "xiaohong ALL=(ALL) NOPASSWD: ALL"
  23. path: /etc/sudoers
  24. - name: set authorized key
  25. hosts: node01
  26. remote_user: xiaohong
  27. become: no
  28. tasks:
  29. - name: set authorized key
  30. authorized_key:
  31. state: present
  32. user: xiaohong
  33. key: "{{ lookup( 'file', '/home/student/.ssh/id_rsa.pub' ) }}"
  34. 2、修改ansible.cfg文件
  35. [student@master ansibleTest]$ cat ansible.cfg
  36. [defaults]
  37. inventory= ./inventory
  38. remote_user = redhat
  39. ask_pass = yes
  40. [privilege_escalation]
  41. become = True
  42. become_method = sudo
  43. become_user = root
  44. become_ask_pass = False
  45. 3、语法检测:
  46. [student@master ansibleTest]$ ansible-playbook user.yaml
  47. 4、执行:需要输入密码!!!
  48. [student@master ansibleTest]$ ansible-playbook user.yaml
  49. SSH password:
  50. PLAY [generate public/private key pair] ******************************************************************************************************
  51. TASK [Gathering Facts] ***********************************************************************************************************************
  52. ok: [master]
  53. TASK [openssh_keypair] ***********************************************************************************************************************
  54. changed: [master]
  55. PLAY [create user] ***************************************************************************************************************************
  56. TASK [Gathering Facts] ***********************************************************************************************************************
  57. ok: [node01]
  58. TASK [create user xiaohong] ******************************************************************************************************************
  59. changed: [node01]
  60. TASK [setting passwd] ************************************************************************************************************************
  61. changed: [node01]
  62. TASK [setting sudoers] ***********************************************************************************************************************
  63. changed: [node01]
  64. PLAY [set authorized key] ********************************************************************************************************************
  65. TASK [Gathering Facts] ***********************************************************************************************************************
  66. ok: [node01]
  67. TASK [set authorized key] ********************************************************************************************************************
  68. changed: [node01]
  69. PLAY RECAP ***********************************************************************************************************************************
  70. master : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  71. node01 : ok=6 changed=4 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

作业二:给受控主机部署yum仓库

仓库1:

name:base

description:baseos

base url:http://mirrors.163.com/centos-vault/8.5.2111/BaseOS/x86_64/os/

需要验证软件包gpg签名

gpgcheck在/etc/pki/rpm-gpg/rpm-gpg-key-*

启用此软件仓库

仓库2:

name:app

description:APPstream

base url:http://mirrors.163.com/centos-vault/8.5.2111/AppStream/x86_64/os/

需要验证软件包gpg签名

gpgcheck在/etc/pki/rpm-gpg/rpm-gpg-key-*

注意:检查自己的linux版本,选择对应版本的仓库

部署成功后在受控节点上安装vsftpd软件包

  1. 环境前准备:
  2. 查看配置文件:
  3. [student@master ansibleTest]$ cat ansible.cfg
  4. [defaults]
  5. inventory= ./inventory
  6. remote_user = redhat
  7. ask_pass = false
  8. [privilege_escalation]
  9. become = True
  10. become_method = sudo
  11. become_user = root
  12. become_ask_pass = False
  13. [student@master ansibleTest]$ ansible --version
  14. ansible [core 2.13.3]
  15. config file = /home/student/ansibleTest/ansible.cfg
  16. configured module search path = ['/home/student/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  17. ansible python module location = /usr/lib/python3.9/site-packages/ansible
  18. ansible collection location = /home/student/.ansible/collections:/usr/share/ansible/collections
  19. executable location = /usr/bin/ansible
  20. python version = 3.9.13 (main, Nov 16 2022, 15:31:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  21. jinja version = 3.1.2
  22. libyaml = True
  23. 查看inventory:
  24. [student@master ansibleTest]$ cat inventory
  25. [webs]
  26. node01
  27. node02
  28. [web1]
  29. node01
  30. [web2]
  31. node02
  32. [all]
  33. node01
  34. node02
  35. master
  36. 做好免密登录,重传
  37. [student@master ansibleTest]$ ssh-copy-id redhat@node01
  38. [student@master ansibleTest]$ ssh-copy-id redhat@node02
  39. 1、编写playbook:
  40. [student@master ansibleTest]$ cat yum.yaml
  41. ---
  42. - name: create repository
  43. hosts: webs
  44. tasks:
  45. - name: add repository baseos
  46. yum_repository:
  47. name: base
  48. description: baseos
  49. baseurl: http://mirrors.163.com/rocky/8.6/BaseOS/x86_64/os/
  50. gpgcheck: yes
  51. gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG_KEY-rockyofficial
  52. enabled: yes
  53. - name: add repository app
  54. yum_repository:
  55. name: app
  56. description: appstream
  57. baseurl: http://mirrors.163.com/rocky/8.6/AppStream/x86_64/os/
  58. gpgcheck: yes
  59. gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG_KEY-rockyofficial
  60. enabled: yes
  61. 2、语法检测:
  62. [student@master ansibleTest]$ ansible-playbook yum.yaml
  63. 3、测试:
  64. [student@master ansibleTest]$ ansible-playbook yum.yaml
  65. PLAY [create repository] *********************************************************************************************************************
  66. TASK [Gathering Facts] ***********************************************************************************************************************
  67. ok: [node02]
  68. ok: [node01]
  69. TASK [add repository baseos] *****************************************************************************************************************
  70. changed: [node02]
  71. changed: [node01]
  72. TASK [add repository app] ********************************************************************************************************************
  73. changed: [node01]
  74. changed: [node02]
  75. PLAY RECAP ***********************************************************************************************************************************
  76. node01 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  77. node02 : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

作业三:给web主机组写一个playbook,该playbook有俩个play,第一个play可以保证在web主机组上安装httpd和php,确保web主机组的/var/www/html/目录下有一个index.php,内容如下:

  1. <?php
  2. phpinfo();

该playbook里面的第二个play用于测试该web主机组的web服务能否被成功访问index.php内容

管理事实

案例一:向受管主机的/home/file文件里面写入内容如下:

  1. hostname=当前主机的名字
  2. memory=当前主机的内存大小
  3. BIOS version = 当前主机的bios的版本
  4. distribution = 当前linux主机的发行版本信息
  5. size of disk device is 当前主机的磁盘大小
  1. [student@master ansibleTest]$ cat sys.yaml
  2. ---
  3. - name: first play
  4. hosts: master
  5. tasks:
  6. - name: print msg
  7. debug:
  8. msg: |
  9. hostname: {{ ansible_facts.hostname }},
  10. memory: {{ ansible_facts.memory_mb.real.total }}
  11. bios version: {{ ansible_facts.bios_version }}
  12. distribution: {{ansible_facts.distribution }}
  13. device size: {{ ansible_facts.device.sda.size}}
  14. - name: copy file
  15. copy:
  16. content: |
  17. hostname: {{ ansible_facts.hostname }},
  18. memory: {{ ansible_facts.memory_mb.real.total }}
  19. bios version: {{ ansible_facts.bios_version }}
  20. distribution: {{ansible_facts.distribution }}
  21. device size: {{ ansible_facts.device.sda.size}}
  22. dest: /home/file

案例二:将createuser.fact文件传输到受管主机工作为自定义事实

案例三:使用debug模块,显示当前受控主机的dns服务器的ip地址

  1. [student@master ansibleTest]$ ansible-playbook dns.yaml
  2. PLAY [firt play] *****************************************************************************************************************************
  3. TASK [Gathering Facts] ***********************************************************************************************************************
  4. ok: [node01]
  5. TASK [debug] *********************************************************************************************************************************
  6. ok: [node01] => {
  7. "ansible_facts.dns.nameservers": [
  8. "192.168.11.2",
  9. "172.25.250.1"
  10. ]
  11. }
  12. PLAY RECAP ***********************************************************************************************************************************
  13. node01 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  14. [student@master ansibleTest]$ cat dns.yaml
  15. ---
  16. - name: firt play
  17. hosts: node01
  18. tasks:
  19. - debug:
  20. var: ansible_facts.dns.nameservers

实施任务控制

案列一:重启服务

  1. 1、编写playbook:
  2. [student@master ansibleTest]$ cat restart_service.yaml
  3. ---
  4. - name: restart service
  5. hosts: all
  6. tasks:
  7. - name: install httpd mariadb-server
  8. yum:
  9. name:
  10. - httpd
  11. - mariadb-server
  12. state: present
  13. register: result
  14. - debug:
  15. var: result
  16. - name: start service
  17. service:
  18. name: "{{ item }}"
  19. state: restarted
  20. loop:
  21. - httpd
  22. - mariadb
  23. when: result.rc == 0
  24. 2、执行:俩次执行不一样,因为幂等性
  25. [student@master ansibleTest]$ ansible-playbook restart_service.yaml
  26. PLAY [restart service] ***********************************************************************************************************************
  27. TASK [Gathering Facts] ***********************************************************************************************************************
  28. ok: [node02]
  29. ok: [node01]
  30. ok: [master]
  31. TASK [install httpd mariadb-server] **********************************************************************************************************
  32. ok: [node01]
  33. ok: [master]
  34. ok: [node02]
  35. TASK [debug] *********************************************************************************************************************************
  36. ok: [node01] => {
  37. "result": {
  38. "changed": false,
  39. "failed": false,
  40. "msg": "Nothing to do",
  41. "rc": 0,
  42. "results": []
  43. }
  44. }
  45. ok: [node02] => {
  46. "result": {
  47. "changed": false,
  48. "failed": false,
  49. "msg": "Nothing to do",
  50. "rc": 0,
  51. "results": []
  52. }
  53. }
  54. ok: [master] => {
  55. "result": {
  56. "changed": false,
  57. "failed": false,
  58. "msg": "Nothing to do",
  59. "rc": 0,
  60. "results": []
  61. }
  62. }
  63. TASK [start service] *************************************************************************************************************************
  64. changed: [node01] => (item=httpd)
  65. changed: [node02] => (item=httpd)
  66. changed: [master] => (item=httpd)
  67. changed: [node01] => (item=mariadb)
  68. changed: [node02] => (item=mariadb)
  69. changed: [master] => (item=mariadb)
  70. PLAY RECAP ***********************************************************************************************************************************
  71. master : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  72. node01 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  73. node02 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

四、个人博客搭建

一、主要内容

wordpress依赖于PHP和MySQL,所以在搭建wordpress前需要先把PHP和MySQL的环境搭建好,本文中使用的web服务为apache。

1、安装LAMP服务器系统(Linux、Apache、MySQL、PHP )

2、安装WordPress

二、具体步骤

安装apache

使用yum安装apache

root@rocky:~# yum install httpd -y

启动apache

  1. root@rocky:~# systemctl is-active httpd
  2. active
  3. root@rocky:~# systemctl start httpd

设置开机自启动

  1. systemctl enable httpd
  2. 或者:重启加开机自启动
  3. root@rocky:~# systemctl enable --now httpd

安装PHP

root@rocky:~# yum install php php-devel -y

接下来是一些拓展

yum install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc -y

还有一个不能通过上述方式直接安装的php-mysql

  1. root@rocky:~# yum search php-mysql
  2. Last metadata expiration check: 0:16:40 ago on Sat 17 Dec 2022 07:54:40 PM CST.
  3. ===================================================================== Name Matched: php-mysql ======================================================================
  4. php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
  5. root@rocky:~# yum install php-mysqlnd.x86_64
  6. Last metadata expiration check: 0:16:55 ago on Sat 17 Dec 2022 07:54:40 PM CST.
  7. Package php-mysqlnd-7.2.24-1.module+el8.4.0+413+c9202dda.x86_64 is already installed.
  8. Dependencies resolved.
  9. Nothing to do.
  10. Complete!

PHP,启动!

root@rocky:~# systemctl start php-fpm

开机启动

root@rocky:~# systemctl enable php-fpm

安装MySQL

很多教程选择安装mysql的客户端来进行以下操作,官网也是这么玩的,但是我懒,就选择了直接摁命令行

root@rocky:~# yum install mysql mysql-server

启动MySQL

root@rocky:~# systemctl start mysqld.service

修改新建好的账户密码

root@rocky:~# mysqladmin -u root password 123456

登入你的MySQL

root@rocky:~# mysql -u root -p123456

输入你刚刚修改的密码,然后新建一个库

  1. mysql> create database wordpress ;
  2. Query OK, 1 row affected (0.00 sec)

新建一个用户(MySQL8.0需要先创建用户,如果不是8.0+可以跳过这步),如果报错把"IDENTIFIED BY '这里是你的密码'"这块去掉

  1. mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> CREATE USER 'wordpress'@'%' IDENTIFIED BY '123456';
  4. Query OK, 0 rows affected (0.01 sec)

授予访问权限,刷新

  1. mysql> grant all privileges on wordpress .* to 'root'@'%';
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> grant all privileges on wordpress to 'wordpress'@'%';
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.00 sec)

准备工作完成开始安装wordpress

安装wordpress

下载wordpress的包,并解压。如果你愿意冒着一点打不开的风险重新安装的话可以试试下面的最新版,毕竟在装了两次最新版都死亡白屏但是换成了旧版本之前,我也是个一定要装最新版的强迫症

  1. root@rocky:~# wget http://wordpress.org/latest.tar.gz
  2. tar -xzf latest.tar.gz

附上我用起来没毛病的包

  1. root@rocky:~# wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.zip
  2. root@rocky:~#unzip wordpress-5.0.3-zh_CN.zip

将wordpress文件夹拷贝至apache服务器根文件目录下(正常情况下为:/var/www/html )

root@rocky:~#cp -r wordpress /var/www/html/

跳转然后创建并修改wordpress的配置文件

  1. root@rocky:~# cd /var/www/html/wordpress/
  2. root@rocky:/var/www/html/wordpress# cp wp-config-sample.php wp-config.php
  3. root@rocky:/var/www/html/wordpress# vim wp-config.php

修改数据库名字,用户名,密码

测试:

关闭防火墙selinux

  1. root@rocky:/var/www/html/wordpress# systemctl is-active firewalld.service
  2. active
  3. root@rocky:/var/www/html/wordpress# systemctl stop firewalld.service
  4. root@rocky:/var/www/html/wordpress# setenforce 0
  5. root@rocky:/var/www/html/wordpress# getenforce
  6. Permissive

访问

http://192.168.11.142/wordpress/wp-admin/install.php

进行wordpress初始化,一顿操作猛如虎,但是结果进不了数据库

简化步骤直接操作:

  1. 1、安装httpd:
  2. [root@rocky ~]#yum update
  3. [root@rocky ~]# yum install httpd -y
  4. 2、启动服务;
  5. [root@rocky ~]# systemctl start httpd
  6. 3、关闭防火墙,selinux
  7. [root@rocky ~]# systemctl stop firewalld.service
  8. [root@rocky ~]# setenforce 0
  9. 4、安装PHP
  10. [root@rocky ~]# yum install php -y
  11. 5、安装组件:
  12. [root@rocky ~]#yum install php-* -y
  13. 6、写phpinfo
  14. [root@rocky html]# cat info.php
  15. <?php
  16. phpinfo();
  17. ?>
  18. 7、重启服务:
  19. [root@rocky html]# systemctl restart httpd.service
  20. [root@rocky html]# systemctl restart php-fpm.service
  21. 8、安装mysql:
  22. [root@rocky html]# yum install mysql-server -y
  23. 9、重启并设置为开机自启动:
  24. [root@rocky html]# systemctl enable --now mysqld
  25. 10、设置数据库密码:
  26. mysqladmin -uroot -p123456
  27. 11、创建数据库:
  28. mysql> create database wordpress;
  29. Query OK, 1 row affected (0.00 sec)
  30. 12、下载WordPress
  31. root@rocky:~# wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.zip
  32. root@rocky:~#unzip wordpress-5.0.3-zh_CN.zip
  33. 13、拷贝一份并命名为 wp-config.php
  34. [root@rocky wordpress]# cp wp-config-sample.php wp-config.php
  35. 14、修改三个地方:
  36. 第一个是数据库名称,安装mysql时最后面创建的数据库,这里是wordpress
  37. 第二个是数据库的名称,这里没创建用户,用默认的root即可
  38. 第三个是数据库的密码,即安装第3步数据库时修改的密码,没修改的话默认填写’’,空着,不要删除两个单引号,(实际上我没试过没密码的,习惯性给数据库都添加了密码,这里你可以试试看没密码的,如果不行就按照安装数据库部分第三步修改一下密码,然后设置进来就行)
  39. 修改完成后按esc,然后输入:wq退出保存文件即可
  40. 15、测试:http://192.168.11.142/wordpress/wp-admin/install.php
  41. 数据库密码为空

蒸汽小火车:

下载链接:http://rpmfind.net/linux/rpm2html/search.php?query=sl&submit=Search+...&system=&arch=+x86_64

  1. 1、下载:
  2. [root@rocky ~]# wget http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/s/sl-5.02-1.el8.x86_64.r pm
  3. 2、安装:
  4. [root@rocky ~]# rpm -i sl-5.02-1.el8.x86_64.rpm
  5. warning: sl-5.02-1.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
  6. 3、运行:
  7. [root@rocky ~]# sl

五、RHCE---服务篇

环境准备

1、将网卡设置为开机自启动:

  1. [root@master ~]# nmcli connection modify ens160 connection.autoconnect yes
  2. [root@master ~]# nmcli connection up ens160
  3. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

2、学习环境:8.x

  1. [root@master ~]# cat /etc/os-release
  2. NAME="Rocky Linux"
  3. VERSION="8.6 (Green Obsidian)"
  4. ID="rocky"
  5. ID_LIKE="rhel centos fedora"
  6. VERSION_ID="8.6"
  7. PLATFORM_ID="platform:el8"
  8. PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
  9. ANSI_COLOR="0;32"
  10. CPE_NAME="cpe:/o:rocky:rocky:8:GA"
  11. HOME_URL="https://rockylinux.org/"
  12. BUG_REPORT_URL="https://bugs.rockylinux.org/"
  13. ROCKY_SUPPORT_PRODUCT="Rocky Linux"
  14. ROCKY_SUPPORT_PRODUCT_VERSION="8"
  15. REDHAT_SUPPORT_PRODUCT="Rocky Linux"
  16. REDHAT_SUPPORT_PRODUCT_VERSION="8"

3、系统时间--方便后期查看日志文件更新时间:

[root@master ~]# timedatectl set-timezone   Asia/Shanghai

4、配置好yum/dnf源 rpm

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

5、安装常用的软件包:

yum install -y bash-completion tree lrzsz  vim  net-tools.x86_64  unzip net-tools  lsof  wget

6、rpm包软件管理:

  1. rpm包进行管理
  2. rpm -ivh 安装软件
  3. -evh 卸载软件
  4. -qa rpm -qa | grep httpd 查看信息
  5. -ql
  6. -qf

7、yum/dnf 7的版本用yum更多,在8版本之后用的dnf之多,可以在后期自己尝试用dnf

  1. #vim /etc/fstab
  2. /dev/sr0 /mnt iso9660 defaults 0 0
  3. #mount -a 查看挂载
  4. #vim /etc/yum.repos.d/base.repo
  5. [BaseOS]
  6. name=RHEL8.5-BaseOS
  7. baseurl=file:///mnt/BaseOS
  8. gpgcheck=0
  9. [AppStream]
  10. name=RHEL8.5-AppStream
  11. baseurl=file:///mnt/AppStream
  12. gpgcheck=0

案例

案例一: 搭建web服务器,提供redhat测试界面

linux主机作为服务器

1、部署web服务程序 apache http server(httpd)

  1. [root@localhost ~]# rpm -qa | grep httpd
  2. httpd-filesystem-2.4.37-41.module+el8.5.0+11772+c8e0c271.noarch
  3. httpd-tools-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
  4. httpd-2.4.37-41.module+el8.5.0+11772+c8e0c271.x86_64
  5. redhat-logos-httpd-84.5-1.el8.noarch
  6. [root@localhost ~]# yum install httpd -y

2、当前主机启动该服务程序

  1. #systemctl start|stop|restart|status|load|reload|enable|disable|is-active|is-enabled httpd
  2. [root@localhost ~]# systemctl start httpd
  3. [root@localhost ~]# systemctl is-active httpd

3、提供客户端主机可以访问的资源文件

默认的资源文件

问什么默认访问的是欢迎界面:通过主配置/var/www/html加载网站资源文件(index.html),当文件不存在,匹配子配置文件/etc/httpd/conf.d/welcome.conf

Alias /.noindex.html /usr/share/httpd/noindex/index.html

4、关闭防火墙,selinux

  1. [root@localhost ~]# systemctl stop firewalld ---建议临时关闭
  2. [root@localhost ~]# systemctl disable firewalld

关闭selinux:

  1. 临时生效
  2. [root@localhost ~]# setenforce 0 ---主机运行状态下临时关闭
  3. [root@localhost ~]# getenforce --查看selinux状态
  4. Permissive
  5. 永久修改linux状态
  6. [root@localhost ~]# vim /etc/selinux/config
  7. # This file controls the state of SELinux on the system.
  8. # SELINUX= can take one of these three values:
  9. # enforcing - SELinux security policy is enforced. 强制状态(开启)
  10. # permissive - SELinux prints warnings instead of enforcing. 警告(关闭)
  11. # disabled - No SELinux policy is loaded. 禁用(不加载selinux)
  12. SELINUX=permissive

5、rpm -ql httpd | more

/etc/httpd/conf 主配置目录(默认提供的参数信息)

/etc/httpd/conf/httpd.conf

/etc/httpd/conf.d 子配置目录(辅助)(自定义的配置文件)

/etc/httpd/conf.d/*.conf

一个完整配置文件先加载主配置文件,在加载子配置文件

/etc/httpd/conf.modules.d 模块配置文件的路径

  1. 全局生效
  2. ServerRoot /etc/httpd 配置文件中加载文件的主路径
  3. Listen 80 服务程序默认监听端口
  4. User apache 服务程序运行后的所属用户和所属组
  5. Group apache
  6. Serveradmin root@localhost
  7. #ServerName www.example.com:80 定义服务主机访问名称
  8. ServerName 0.0.0.0:80
  9. DocumentRoot "/var/www/html" 定义网站默认的主路径
  10. IncludeOptional conf.d/*.conf 开始加载所有子配置文件
  11. 局部生效
  12. <Directory /> 目录起始标签 /
  13. AllowOverride none
  14. Require all denied 请求所有拒绝
  15. </Directory>
  16. <Directory "/var/www"> 目录起始标签 /var/www
  17. AllowOverride None
  18. # Allow open access:
  19. Require all granted 请求所有允许
  20. </Directory>
  21. <IfModule dir_module> 模块标记 对目录模块定义
  22. DirectoryIndex index.html 网站主目录索引文件文件名为index.html
  23. </IfModule>

案例二:搭建网站创建自定义网页文件

linux主机作为服务器

1、部署web服务程序 apache http server(httpd)

2、当前主机启动该服务程序

3、提供客户端主机可以访问的资源文件

  1. #cd /var/www/html
  2. #echo helloworld > index.html
  3. 通过主配置/var/www/html加载网站资源文件(index.html)当文件存在,直接加载该文件内容进行相应。

4、关闭防火墙,selinux

window/linux 客户端主机

浏览器:url 网址 http://ip/1/index.html /var/www/html/1/index.html

权限控制

web服务程序资源文件的权限控制可以在配置文件和文件层级。

  1. <Directory "/www"> 目录起始标签 /www
  2. AllowOverride None
  3. #Allow open access:
  4. Require all granted 请求所有允许
  5. </Directory>
  6. [root@localhost ~]# chmod o-r /www/index.html
  7. [root@localhost ~]# ll /www/index.html
  8. -rw-r-----. 1 root root 13 Mar 20 09:58 /www/index.html
  9. [root@localhost ~]# chmod o+r /www/index.html
  10. https://httpd.apache.org/docs/2.4/howto/auth.html
  11. require user tom
  12. Require ip address
  13. Require not ip address
  14. Require host domain_name
  15. <Directory /openlab>
  16. AllowOverride none
  17. <RequireAll>
  18. Require all granted
  19. Require not ip 192.168.153.128
  20. </RequireAll>
  21. </Directory>
  22. 多网站访问
  23. http://ip|域名|:80
  24. https://

案例三:多ip匹配多网站

1、当前主机配置多个ip

  1. [root@localhost ~]# nmcli connection modify ens160 ipv4.method manual ipv4.addresses 192.168.153.128/24 ipv4.gateway 192.168.153.2 ipv4.dns 114.114.114.114 +ipv4.a
  2. ddresses 192.168.153.129 +ipv4.addresses 192.168.153.130
  3. [root@localhost ~]# nmcli connection up ens160
  4. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
  5. [root@localhost ~]# ip a

2、通过配置基于多个虚拟主机标签配置多个网站站点

  1. 虚拟主机示例文件
  2. # rpm -ql httpd | grep vhosts.conf
  3. # vim /usr/share/doc/httpd/httpd-vhosts.conf
  4. 1.自定义子配置文件,配置多主机网站信息
  5. vim /etc/httpd/conf.d/vhosts.conf
  6. <VirtualHost 192.168.153.128:80>
  7. DocumentRoot "/openlab/128"
  8. ServerName 192.168.153.128
  9. ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
  10. CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
  11. </VirtualHost>
  12. <VirtualHost 192.168.153.129:80>
  13. DocumentRoot "/openlab/129"
  14. ServerName 192.168.153.129
  15. </VirtualHost>
  16. <VirtualHost 192.168.153.130:80>
  17. DocumentRoot "/openlab/130"
  18. ServerName 192.168.153.130
  19. </VirtualHost>
  20. #资源路径的访问权限
  21. <Directory /openlab>
  22. AllowOverride none
  23. Require all granted
  24. </Directory>
  25. 2.根据配置创建对应资源文件
  26. #mkdir /openlab/{128,129,130} -pv
  27. #echo this is 128 > /openlab/128/index.html
  28. #echo this is 129 > /openlab/129/index.html
  29. #echo this is 130 > /openlab/130/index.html
  30. #systemctl restart httpd

案例四: 基于多端口访问多网站

  1. ##130-80
  2. <VirtualHost 192.168.153.130:80>
  3. DocumentRoot "/openlab/130"
  4. ServerName 192.168.153.130
  5. </VirtualHost>
  6. ##130--10000
  7. Listen 10000 #监听自定义端口
  8. <VirtualHost 192.168.153.130:10000>
  9. DocumentRoot "/openlab/10000"
  10. ServerName 192.168.153.130
  11. </VirtualHost>
  12. <Directory /openlab>
  13. AllowOverride none
  14. Require all granted
  15. </Directory>
  16. [root@localhost ~]# mkdir /openlab/10000
  17. [root@localhost ~]# echo this is 10000 > /openlab/10000/index.html
  18. [root@localhost ~]# systemctl restart httpd
  19. 测试:

案例五:基于域名访问多网站

  1. <VirtualHost 192.168.153.128:80>
  2. DocumentRoot "/openlab/haha"
  3. ServerName www.haha.com
  4. ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
  5. CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
  6. </VirtualHost>
  7. <VirtualHost 192.168.153.128:80>
  8. DocumentRoot "/openlab/xixi"
  9. ServerName www.xixi.com
  10. ErrorLog "/var/log/httpd/dummy-128.example.com-error_log"
  11. CustomLog "/var/log/httpd/dummy-128.example.com-access_log" common
  12. </VirtualHost>
  13. <Directory /openlab>
  14. AllowOverride none
  15. Require all granted
  16. </Directory>
  17. [root@localhost ~]# mkdir /openlab/{haha,xixi}
  18. [root@localhost ~]# echo this is xixi > /openlab/xixi/index.html
  19. [root@localhost ~]# echo this is haha > /openlab/haha/index.html
  20. [root@localhost ~]# systemctl restart httpd

客户端测试

  1. 1.通过域名访问需要将域名解析为ip
  2. 通过浏览器缓存匹配
  3. 客户端主机的hosts文件匹配
  4. window:C:\Windows\System32\drivers\etc
  5. 192.168.153.128 www.haha.com
  6. 192.168.153.128 www.xixi.com
  7. linux : /etc/hosts
  8. 路由缓存记录匹配
  9. 本地dns服务

排错方式

  1. (1) 启动不成功(配置文件写的有问题)systemctl restart httpd
  2. [root@localhost ~]#systemctl status httpd
  3. [root@localhost ~]# journalctl -xe
  4. [root@localhost ~]# httpd -t
  5. (2)访问的内容不是我们定义的内容
  6. 逻辑问题:分析主机配置标签是否能匹配或是否冲突
  7. 资源文件是否创建
  8. 匹配对应文件是否有权限
  9. 防火墙,selinux

案例六:虚拟目录

alias 虚拟目录名称 真实目录路径

​ 为了便于对网站资源进行灵活管理,还可以把这些文件存放在本地计算机的其它文件夹中或者其它计算机的共享文件夹中,然后再把这个文件夹映射到网站主目录中的一个目录上,这个文件夹被称为“虚拟目录”。

每个虚拟目录都有一个别名,这样用户就可以通过这个虚拟目录的别名来访问与之对应的真实文件夹中的资源了。虚拟目录的好处是在不需要改变别名的情况下,可以随时改变其对应的文件夹。

  1. <VirtualHost 192.168.153.128:80>
  2. DocumentRoot "/openlab/128"
  3. # /网站根目录=/openlab/128
  4. Alias /file /openlab/128/1/f/file/newfile/
  5. ServerName 192.168.153.128
  6. # /openlab/128/3w
  7. Alias /3w /www
  8. </VirtualHost>
  9. <Directory /openlab>
  10. AllowOverride none
  11. Require all granted
  12. </Directory>
  13. <Directory "/www">
  14. AllowOverride None
  15. # Allow open access:
  16. Require all granted
  17. </Directory>
  18. [root@localhost ~]# mkdir -pv /openlab/128/1/f/file/newfile/
  19. mkdir: created directory '/openlab/128/1'
  20. mkdir: created directory '/openlab/128/1/f'
  21. mkdir: created directory '/openlab/128/1/f/file'
  22. mkdir: created directory '/openlab/128/1/f/file/newfile/'
  23. [root@localhost ~]# echo this is zijiemian > /openlab/128/1/f/file/newfile/index.html
  24. [root@localhost ~]# mkdir /www
  25. mkdir: cannot create directory ‘/www’: File exists
  26. [root@localhost ~]# cd /www
  27. [root@localhost www]# ll
  28. total 4
  29. -rw-r--r--. 1 root root 13 Mar 20 09:58 index.html
  30. [root@localhost www]# echo this is 128 test page > index.html

案例七:用户访问控制+虚拟目录

  1. <VirtualHost 192.168.153.128:80>
  2. DocumentRoot "/openlab/128"
  3. # /网站根目录=/openlab/128
  4. Alias /file /openlab/128/1/f/file/newfile/
  5. ServerName 192.168.153.128
  6. Alias /3w /www
  7. </VirtualHost>
  8. <Directory /openlab>
  9. AllowOverride none
  10. Require all granted
  11. </Directory>
  12. <Directory /www>
  13. AuthType Basic
  14. AuthName "Please login:"
  15. AuthuserFile /etc/httpd/userfile
  16. Require user tom zhangsan
  17. </Directory>
  18. [root@localhost www]# htpasswd -c /etc/httpd/userfile tom
  19. New password:
  20. Re-type new password:
  21. Adding password for user tom
  22. [root@localhost www]# htpasswd /etc/httpd/userfile zhangsan
  23. New password:
  24. Re-type new password:
  25. Adding password for user zhangsan
  26. curl http://192.168.153.128/3w/ -u tom

案例八:搭建加密网站

1.加载mod_ssl认证模块

[root@localhost www]# yum install mod_ssl -y

2.生成自签名证书

  1. (第二种) [root@localhost ~]#cd /etc/pki/tls/certs
  2. [root@localhost certs]# openssl req -newkey rsa:4096 -nodes -sha256 -keyout ../private/openlab.key -x509 -days 365 -out openlab.crt
  3. ----------------------------------------------x509 key csr crt---------------------------
  4. [root@www certs]# openssl genrsa -aes128 2048 > openlab.key
  5. (第三种) #openssl req -utf8 -new -key openlab.key -x509 -days 365 -out openlab.crt
  6. -------------------------------------------------------------------------------------

3.虚拟主机标签中添加加密验证信息

  1. <VirtualHost 192.168.153.128:443>
  2. DocumentRoot "/ssl"
  3. ServerName 192.168.153.128
  4. SSLEngine on
  5. SSLCertificateFile /etc/pki/tls/certs/openlab.crt
  6. SSLCertificateKeyFile /etc/pki/tls/private/openlab.key
  7. </VirtualHost>
  8. <Directory /ssl>
  9. ​ AllowOverride none
  10. ​ Require all granted
  11. </Directory>

4.重启服务测试

**案例九:扩展配置 **

1.通过http/https 实现文件共享
目录标签中 options +indexes
indexes 默认加载directoryindex 目录标签后,当目录directoryindex找不到对应网页文件(删除主路径下的index.html,以及欢迎界面)会加载mod_autoindex 会将网站主路径下的文件格式为目录列表提供客户端主机访问。

2.配置用户主界面---静态

  1. 1.更改用户主界面配置
  2. vim /etc/httpd/conf.d/userdir.conf
  3. <IfModule mod_userdir.c>
  4. UserDir public_html
  5. <Directory "/home/tom/public_html">
  6. AuthType Basic
  7. AuthName "please login"
  8. AuthuserFile /etc/httpd/userfile
  9. Require user tom
  10. 注意: 访问用户主界面通过什么协议访问
  11. 指定网站访问方式(ip)通过哪种协议可以匹配
  12. 2.创建资源信息
  13. #useradd tom
  14. #mkdir /home/tom/public_html
  15. #echo this is tom > /home/tom/public_html/index.html
  16. #chmod o+rx /home/tom
  17. #htpasswd -c /etc/httpd/userfile tom
  18. 3.重启
  19. 4.firewalld setenfore

搭建动态网站
LAMP
1.linux平台部署web服务
2.配置web服务
(1).安装web服务
(2).根据配置定义加载网页资源文件的路径

  1. [root@localhost uc_server]# cat /etc/httpd/conf.d/vhosts.conf
  2. <Directory /www>
  3. AllowOverride none
  4. Require all granted
  5. <Virtualhost 192.168.153.128:80>
  6. DocumentRoot /www
  7. ServerName 192.168.153.128

(3).根据配置创建资源文件

  1. #mkdir /www
  2. #cd /www
  3. #unzip Discuz_X3.4_SC_UTF8_20191201.zip

(4).重启服务

3.部署mariadb

  1. [root@localhost install]# yum install mairadb-server -y
  2. [root@localhost www]# systemctl start mariadb
  3. [root@localhost www]# mysql_secure_installation 初始化数据库
  4. enter
  5. y
  6. redhat
  7. redhat
  8. 一直y
  9. [root@localhost www]# mysql -uroot -predhat // -u用户名 -p密码
  10. MariaDB [(none)]> create database luntan;
  11. MariaDB [(none)]>quit
  12. [root@localhost www]# systemctl restart mariadb

4.安装PHP应用程序

  1. yum install php* -y
  2. [root@localhost upload]# pwd
  3. /www/upload
  4. [root@localhost upload]# chmod o+w data config uc_* -R

NFS

1.NFS 网络文件系统(文件共享协议)
通过nfs服务器可以共享文件,客户端主机通过挂载方式访问共享文件。
2.挂载的特点:(文件访问)
通过客户端主机挂载点目录连接服务端共享的nfs文件系统,类似与所有文件都在本地,但实际上所有文
件都在服务端主机中,通过服务端主机可以控制客户某些主机可以访问该文件。
3.挂载方式:
1)临时挂载
2)开机自动挂载
3)自动挂载
一个挂载点可以同时连接多个文件系统(不推荐)注意:RHEL7.X 多个nfs文件系统不支持同时挂载到
一个挂载点目录,但RHEL8.x 多个nfs文件系统不支持同时挂载到一个挂载点目录,但通过挂载点访问的是最后一次连接的文件系统。
同一个文件系统可以挂载到多个挂载点目录。
4.nfs 文件共享的原理

5.nfs服务搭建
服务端
1)安装软件包rpcbind nfs-server
2)自定设置,编辑配置文件

vim /etc/exports
共享目录 允许访问的主机(参数,...)

  1. ro rw
  2. root_squash
  3. no_root_squash
  4. all_squash
  5. anonuid=
  6. anongid=
  7. no_all_squash
  8. sync
  9. async
  10. atime
  11. noatime
  1. 创建资源文件
    创建共享主目录,以及主目录对于用户访问权限设置
    4)systemctl start nfs-server
    exportfs -ra
    5)防火墙 ,selinux
    客户端:linux
    1).showmount -e 服务端ip 查询服务主机共享文件系统
    2).挂载文件系统
    6.服务是否启动
    systemctl is-active httpd
  1. systemctl status httpd
  2. ps -aux | grep httpd
  3. ss -tunlp | grep 2048
  4. netstat -tunlp | grep httpd
  5. lsof -i:80
  6. rpcinfo -p

7.nfs优缺点

**案例:架设一台NFS服务器,并按照以下要求配置 **

1、开放/nfs/shared目录,供所有用户查询资料
2、开放/nfs/upload目录,为192.168.100.0/24网段主机可以上传目录,
并将所有用户及所属的组映射为nfs-upload,其UID和GID均为210

3、将/home/tom目录仅共享给192.168.100.136这台主机,并只有用户tom可以完全访问该目录
autofs
能够动态管理文件系统,在系统需要该文件系统资源时,将文件系统动态挂载可以动态取消挂载。

  1. 1.安装自动挂载服务程序
  2. yum install autofs -y
  3. 2.自定义触发条件,满足该条件后,将文件系统自动挂载
  4. vim /etc/auto.master 主参数文件中定义挂载条件
  5. #挂载点主目录 子参数文件(连接autofs文件系统)
  6. /nfs /etc/auto.nfs
  7. vim /etc/auto.nfs
  8. #触发条件(挂载点目录) 文件系统名称
  9. test 192.168.153.128:/test
  10. 3.加载参数
  11. systemctl restart autofs
  12. 查看挂载点主目录是否自动创建
  13. 手动: cd /nfs cd test
  14. 自动触发:
  15. mount /dev/sr0 /pub/sr0

**搭建web服务通过域名访问网站资源文件,网站资源文件通过nfs服务器共享个web服务端主机,提供用
户解析和查询 **

  1. 1.web服务器
  2. yum install httpd
  3. [root@localhost ~]# cat /etc/httpd/conf.d/vhosts.conf
  4. <Directory /www/129>
  5. AllowOverride none
  6. Require all granted
  7. <Virtualhost *:80>
  8. DocumentRoot /www/129
  9. ServerName 192.168.153.129
  10. 2、安装自动挂载服务程序
  11. yum install autofs -y
  12. vim /etc/auto.master
  13. /www /etc/auto.web
  14. vim /etc/auto.web
  15. 129 192.168.153.128:/test
  16. systemctl restart autofs
  17. yum install php*
  18. yum install mariadb-server -y
  19. systemctl restart mariadb
  20. mysql_secure_installation
  21. mysql -uroot -predhat
  22. create database wordpress;
  23. exit
  24. systemctl start mairadb
  25. systemctl restart httpd
  26. 3.nfs服务器 wordpress
  27. #rpm -qa | grep nfs
  28. #rpm -qa | grep rpcbind
  29. #vim /etc/exports
  30. #mkdir /test
  31. #cd /test
  32. 通过xftp将wordpress包传到共享主目录/test#unzip wordpress-5.9.2.zip
  33. #unzip wordpress-5.9.2.zip
  34. [root@localhost test]# ll
  35. total 19800
  36. drwxr-xr-x. 5 root root 4096 Mar 10 19:39 wordpress
  37. -rw-r--r--. 1 root root 20270503 Mar 27 04:30 wordpress-5.9.2.zip
  38. [root@localhost test]# systemctl restart nfs-server
  39. [root@localhost test]# systemctl stop firewalld
  40. [root@localhost test]# setenforce 0
  41. [root@localhost wordpress]# cp wp-config-sample.php wp-config.php

linux邮件客户端的配置

  1. 第三方邮件客户端程序验证能够通过linux主机将信件发送到外网邮件服务器。
  2. yum install mailx -y
  3. vim /etc/mail.rc
  4. set from=lxx1065372838@163.com # 邮箱账号
  5. set smtp=smtp.163.com #邮件服务器的主机名
  6. set smtp-auth-user=lxx1065372838@163.com # 邮箱账号
  7. set smtp-auth-password=QUREDFYKLNBRAIAA #授权码
  8. set smtp-auth=login
  9. (1)#echo "邮件内容" | mail -s '邮件主题' 收件用户的邮箱账号
  10. (2)#echo 邮件内容 > /a.txt
  11. mail -s '主题' -a /a.txt 收件用户的邮箱账号 < /a.txt

nmcli

  1. ### 配置网卡冗余(主备)
  2. #nmcli connection add type team ifname team0 con-name team0 config '{"runner": {"name": "activebackup"}}
  3. #nmcli connection add type team-slave ifname ens224 con-name team0-port1 master team0
  4. #nmcli connection add type team-slave ifname ens256 con-name team0-port2 master team0
  5. #nmcli connection show
  6. #nmcli con up team0-port1
  7. #nmcli con up team0-port2
  8. #teadctl team0 stat
  9. #nmcli connection modify team0 ipv4.addresses 192.168.153.111/24 +ipv4.addresses 192.168.153.111/24ipv4.gateway 192.168.153.2 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
  10. ## 桥接网卡
  11. #nmcli connection add type bridge-slave ifname ens160 con-name br1-port1 master br1
  12. #nmcli connection show
  13. #nmcli connection up br1-port1

环境准备:

1、下载环境:

2、解压:100G左右

3、打开:

  • 方法一:双击RH294.vmx
  • 方法二:vmware打开RH294.vmx

4、远程连接:

  • 给win的虚拟网卡:VMware Network Adapter VMnet1增加一个ip:
    • ip:172.25.254.1/255.255.255.0,不需要网关
  • 远程连接:
    • IP:172.25.254.250 kiosk/redhat
    • root用户远程登录密码:Asimov
    • student:student

5、设置课程:考试和工作都不用

  1. [kiosk@foundation0 ~]$ rht-setcourse rh294
  2. /content/rhel8.0/x86_64/vms /home/kiosk
  3. /home/kiosk
  4. Course set to rh294

6、启动课程环境:

  1. [kiosk@foundation0 ~]$ rht-vmctl status all
  2. bastion DEFINED
  3. workstation DEFINED
  4. servera DEFINED
  5. serverb DEFINED
  6. serverc DEFINED
  7. serverd DEFINED
  8. [kiosk@foundation0 ~]$ rht-vmctl start classroom
  9. [kiosk@foundation0 ~]$ rht-vmctl start all
  10. Starting bastion.
  11. Starting workstation.
  12. Starting servera.
  13. Starting serverb.
  14. Starting serverc.
  15. Starting serverd.
  16. 重置虚拟机:
  17. [kiosk@foundation0 ~]$ rht-vmctl reset all
  18. Are you sure you want to reset bastion workstation servera serverb serverc serverd? (y/n) y
  19. 查看状态:
  20. [kiosk@foundation0 ~]$ rht-vmctl status all
  21. bastion RUNNING
  22. workstation RUNNING
  23. servera RUNNING
  24. serverb RUNNING
  25. serverc RUNNING
  26. serverd RUNNING
  27. [kiosk@foundation0 ~]$ rht-vmctl status classroom
  28. classroom RUNNING
  29. 学会查看帮助:
  30. [kiosk@foundation0 ~]$ rht-vmctl --help
  31. This utility manages the Red Hat Training supplied VMs on the local
  32. hypervisor.
  33. Usage: rht-vmctl [-y|--yes] VMCMD VMNAME [DATETIME]
  34. rht-vmctl [-i|--inquire] VMCMD VMNAME [DATETIME]
  35. rht-vmctl -h|--help
  36. where VMCMD is one of:
  37. view - launches console viewer of VMNAME
  38. start - obtain and start up VMNAME
  39. stop - stop a running VMNAME
  40. restart - if running, stop then start VMNAME
  41. poweroff - if running, force stop VMNAME
  42. reset - poweroff, return to saved or original state, start VMNAME
  43. save - stop, save image, start VMNAME (to DATETIME)
  44. restore - poweroff, restore to save (to DATETIME), start VMNAME
  45. listsaves - list the saves of VMNAME
  46. status - display libvirt status of VMNAME
  47. get - if not here, obtain VMNAME from server
  48. remove - remove VMNAME from system
  49. fullreset - poweroff, reobtain from server, start VMNAME (bad save/image)
  50. -i|--inquire - confirm each VMNAME first
  51. -y|--yes - confirm nothing, just do it
  52. VMNAME of "all" processes all VMs available in the course

注意:重新开机之后,只需要执行rht-vmctl start all

  1. 练习环境:
  2. [kiosk@foundation0 ~]$ ssh student@workstation
  3. Warning: Permanently added 'workstation,172.25.250.9' (ECDSA) to the list of known hosts.
  4. Activate the web console with: systemctl enable --now cockpit.socket
  5. [student@workstation ~]$

ansible后面的命令:自己去了解一下

  1. student@master:~$ ansible-
  2. ansible-community ansible-connection ansible-doc ansible-inventory ansible-pull
  3. ansible-config ansible-console ansible-galaxy ansible-playbook ansible-vault
  4. student@master:~/ansibleDemo$ ansible-inventory --list
  5. {
  6. "_meta": {
  7. "hostvars": {}
  8. },
  9. "all": {
  10. "children": [
  11. "ungrouped"
  12. ]
  13. }
  14. }

双网卡绑定team

堡垒机或跳板机

双网卡绑定:

  • 轮询:轮流响应用户请求。缺点:如果某一块网卡出现故障,可能会导致访问异常。
  • 主备:正常情况下,只有一个网卡工作。缺点:浪费了一块网卡资源。优点:高可用。
  • 负载均衡:流量分担。

扩展内容:

双网卡绑定:team

前提:需要俩块相同的类型的网卡

查看:

  1. [root@master ~]# nmcli connection show
  2. NAME UUID TYPE DEVICE
  3. ens33 4f0220d5-7ac9-456a-ba4a-852f14911ac7 ethernet ens33

修改连接名:

[root@master ~]# nmcli connection modify ens33 con-name ens33

查看team配置:

[root@master yum.repos.d]# cd /usr/share/doc/teamd-1.29/example_configs/

配置:

1、创建team0设备和team0会话

[root@master example_configs]# nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'

2、配置team0地址信息

[root@master example_configs]# nmcli connection modify team0 ipv4.method manual ipv4.addresses 192.168.11.100/24 ipv4.gatwag 192.168.11.2 ipv4.dns 114.114.114.114 autoconnect yes

3、添加设备到team0

  1. [root@master example_configs]# nmcli connection add type team-slave con-name team0-1 ifname ens33 master team0
  2. [root@master example_configs]# nmcli connection add type team-slave con-name team0-2 ifname ens34 master team0

4、激活设备

  1. 在虚拟机中去做,xshell会中断
  2. [root@master example_configs]# nmcli connection up team0-1
  3. [root@master example_configs]# nmcli connection up team0-2
  4. [root@master example_configs]# nmcli connection up team0

5、查看

[root@master example_configs]# teamdctl team0 state

NFS服务器

案例一:共享/data目录给192.168.11.0/24整个网段可读可写

1、安装软件

[root@master ~]# yum install nfs-utils.x86_64  rpcbind.x86_64  -y

2、编写配置文件

  1. [root@master ~]# cat /etc/exports
  2. /data 192.168.11.0/24(rw,sync,no_root_squash)

3、创建目录

[root@master ~]# mkdir /data

4、测试

  1. [root@master ~]# showmount -e
  2. Export list for master.itcast.com:
  3. /data 192.168.11.0/24

挂载:

  • 手动挂载:mount
  • 开机自动挂载:/etc/fstab
  • 按需挂载:autofs,使用时挂载,灵活

案例:配置autofs挂载光盘到/mnt/dvd

1、安装软件

[root@master ~]# yum install autofs.x86_64 -y

2、写配置文件

  1. [root@master ~]# vim /etc/auto.master
  2. 上层目录 配置文件
  3. /mnt /etc/auto.cdrom
  4. [root@master ~]# cat /etc/auto.cdrom
  5. dvd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

3、重启服务

[root@master ~]# systemctl enable --now autofs.service

4、测试

  1. [root@master ~]# ls /mnt/
  2. [root@master ~]# ll /mnt/dvd
  3. total 1670
  4. -rw-rw-r--. 1 root root 14 Jul 26 2022 CentOS_BuildTag
  5. drwxr-xr-x. 3 root root 2048 Jul 26 2022 EFI
  6. -rw-rw-r--. 1 root root 227 Aug 30 2017 EULA
  7. -rw-rw-r--. 1 root root 18009 Dec 10 2015 GPL
  8. drwxr-xr-x. 3 root root 2048 Jul 26 2022 images
  9. drwxr-xr-x. 2 root root 2048 Jul 26 2022 isolinux
  10. drwxr-xr-x. 2 root root 2048 Jul 26 2022 LiveOS
  11. drwxr-xr-x. 2 root root 1671168 Jul 26 2022 Packages
  12. drwxr-xr-x. 2 root root 4096 Jul 26 2022 repodata
  13. -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
  14. -rw-rw-r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
  15. -r--r--r--. 1 root root 2883 Jul 27 2022 TRANS.TBL
  16. [root@master ~]# df -h
  17. Filesystem Size Used Avail Use% Mounted on
  18. devtmpfs 475M 0 475M 0% /dev
  19. tmpfs 487M 0 487M 0% /dev/shm
  20. tmpfs 487M 7.8M 479M 2% /run
  21. tmpfs 487M 0 487M 0% /sys/fs/cgroup
  22. /dev/mapper/centos-root 17G 1.9G 16G 11% /
  23. /dev/sda1 1014M 139M 876M 14% /boot
  24. tmpfs 98M 0 98M 0% /run/user/0
  25. /dev/sr0 9.6G 9.6G 0 100% /mnt/dvd

DNS服务器

unbound

1、安装unbound

[root@master ~]# yum install unbound -y

2、编辑配置文件,对全局参数进行配置

  1. [root@master ~]# vim /etc/unbound/unbound.conf
  2. access-control: 192.168.11.0/24 allow
  3. username: ""
  4. domain-insecure: "openlab.edu"
  5. include: /etc/unbound/local.d/*.conf

3、进入配置解析域

  1. [root@master ~]# cd /etc/unbound/local.d/
  2. [root@master local.d]# ls
  3. block-example.com.conf
  4. [root@master local.d]# more block-example.com.conf
  5. # entries in this file override toe global DNS
  6. #
  7. # Example blocking email going out to example.com
  8. #
  9. # local-data: "example.com. 3600 IN MX 5 127.0.0.1"
  10. # local-data: "example.com. 3600 IN A 127.0.0.1"
  11. # This can also be done dynamically using: unbound-control local-data [...]
  12. # For more complicated redirection, use conf.d/ with stub-add: or forward-add:

4、配置正向解析记录和反向解析目录

  1. [root@master local.d]# cat domain.conf
  2. local-zone:"openlab.edu." static
  3. local-data:"openlab.edu. 86400 IN SOA dns1.openlab.edu. root.openlab.edu 2023031501 1D 1H 1W 1H"
  4. local-data:"dns1.openlab.edu. IN A 192.168.11.121"
  5. local-data:"www.openlab.edu. IN A 192.168.11.111"
  6. local-data:"web.openlab.edu.IN CNAME www.openlab.edu."
  7. local-data:"mail.openlab.edu. IN A 192.168.11.222"
  8. local-data:"openlab.edu. IN MX 5 mail.openlab.edu."
  9. # 反向解析
  10. local-data-ptr:"192.168.11.121 dns1.openlab.edu"
  11. local-data-ptr:"192.168.11.111 www.openlab.edu"
  12. local-data-ptr:"192.168.11.111 web.openlab.edu"
  13. local-data-ptr:"192.168.11.222 mail.openlab.edu"

5、配置转发

  1. [root@master local.d]# vim /etc/unbound/unbound.conf
  2. forward-zone:
  3. name: "."
  4. forward-addr:223.5.5.5

6、语法检测

[root@master local.d]# unbound-checkconf

7、重启服务

[root@master ~]# systemctl restart unbound

8、测试

  1. 客户端:
  2. [root@master local.d]# yum install bind-utils.x86_64 -y
  3. [root@master ~]# cat /etc/resolv.conf
  4. # Generated by NetworkManager
  5. search localdomain itcast.com
  6. nameserver 192.168.11.121
  7. [root@master ~]#nslookup
  8. > 192.168.11.121

bind---常用

1、安装软件

[root@master ~]# yum install bind -y

2、关闭防火墙或者放行DNS服务

  1. [root@master ~]# firewall-cmd --permanent --add-service=dns
  2. success
  3. [root@master ~]# firewall-cmd --reload
  4. success

3、修改配置文件

  1. [root@master ~]# vim /etc/named.conf
  2. options {
  3. listen-on port 53 { 192.168.11.148; }; #修改这一行IP,注意分号
  4. //listen-on-v6 port 53 { ::1; }; # IPV6的,可以注释掉
  5. directory "/var/named";
  6. dump-file "/var/named/data/cache_dump.db";
  7. statistics-file "/var/named/data/named_stats.txt";
  8. memstatistics-file "/var/named/data/named_mem_stats.txt";
  9. recursing-file "/var/named/data/named.recursing";
  10. secroots-file "/var/named/data/named.secroots";
  11. allow-query { 192.168.11.0/24; }; # 修改为本网段,或者用any

4、区域文件

  1. [root@master ~]# vim /etc/named.rfc1912.zones # 路径在配置文件中有
  2. 正向解析:
  3. zone "openlab.edu" IN {
  4. type master;
  5. file "openlab.edu.zone";
  6. };
  7. [root@master ~]# cd /var/named/
  8. [root@master named]# ll
  9. total 16
  10. drwxrwx---. 2 named named 6 Jan 26 00:48 data
  11. drwxrwx---. 2 named named 6 Jan 26 00:48 dynamic
  12. -rw-r-----. 1 root named 2253 Apr 5 2018 named.ca
  13. -rw-r-----. 1 root named 152 Dec 15 2009 named.empty
  14. -rw-r-----. 1 root named 152 Jun 21 2007 named.localhost
  15. -rw-r-----. 1 root named 168 Dec 15 2009 named.loopback
  16. drwxrwx---. 2 named named 6 Jan 26 00:48 slaves
  17. [root@master named]# cp -a named.localhost openlab.edu.zone #注意带权限修改
  18. [root@master named]# vim openlab.edu.zone
  19. [root@master named]# cat openlab.edu.zone
  20. $TTL 1D
  21. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  22. 2023031601 ; serial
  23. 1D ; refresh
  24. 1H ; retry
  25. 1W ; expire
  26. 3H ) ; minimum
  27. NS dns1.openlab.edu.
  28. MX 5 mail.openlab.edu.
  29. dns1 A 192.168.11.148
  30. mail A 192.168.11.222
  31. www A 192.168.11.111
  32. web CNAME www

5、语法检测

  1. # 7版本的语法:
  2. [root@master named]# named-checkzone "openlab.edu" /var/named/openlab.edu.zone
  3. zone openlab.edu/IN: loaded serial 2023031601
  4. OK

6、重启服务

  1. [root@master named]# systemctl enable --now named.service
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.

7、客户端测试

  1. 安装bind-utils
  2. [root@node01 ~]# yum install bind-utils.x86_64 -y
  3. [root@node01 ~]# more /etc/resolv.conf
  4. # Generated by NetworkManager
  5. search localdomain itcast.com
  6. nameserver 192.168.11.148
  7. [root@node01 ~]# nslookup
  8. > dns1.openlab.edu
  9. Server: 192.168.11.148
  10. Address: 192.168.11.148#53
  11. Name: dns1.openlab.edu
  12. Address: 192.168.11.148
  13. > www.openlab.edu
  14. Server: 192.168.11.148
  15. Address: 192.168.11.148#53
  16. Name: www.openlab.edu
  17. Address: 192.168.11.111
  18. > set type=cname
  19. > web.openlab.edu
  20. Server: 192.168.11.148
  21. Address: 192.168.11.148#53
  22. web.openlab.edu canonical name = www.openlab.edu.

正向解析成功接下来配置反向解析

1、修改主配置文件

  1. [root@master ~]# vim /etc/named.rfc1912.zones # 路径在配置文件中有
  2. zone "11.168.192.in-addr.arpa" IN {
  3. type master;
  4. file "192.168.11.zone";
  5. };

2、修改模板文件

  1. [root@master named]# vim /etc/named.rfc1912.zones
  2. [root@master named]# cp -a named.loopback 192.168.11.zone
  3. [root@master named]# vim 192.168.11.zone
  4. [root@master named]# cat 192.168.11.zone
  5. $TTL 1D
  6. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  7. 2023031601 ; serial
  8. 1D ; refresh
  9. 1H ; retry
  10. 1W ; expire
  11. 3H ) ; minimum
  12. NS dns1.openlab.edu.
  13. dns1.openlab.edu. A 192.168.11.148
  14. 148 PTR dns1.openlab.edu.
  15. 111 PTR www.openlab.edu.
  16. 111 PTR web.openlab.edu.
  17. 222 PTR mail.openlab.edu.

3、语法检测+重启服务

  1. [root@master named]# named-checkzone "openlab.edu" 192.168.11.zone
  2. zone openlab.edu/IN: loaded serial 2023031601
  3. OK
  4. [root@master named]# systemctl restart named

4、测试

  1. [root@node01 ~]# host -t PTR 192.168.11.148
  2. 148.11.168.192.in-addr.arpa domain name pointer dns1.openlab.edu.
  3. [root@node01 ~]# nslookup
  4. > 192.168.11.111
  5. 111.11.168.192.in-addr.arpa name = www.openlab.edu.
  6. 111.11.168.192.in-addr.arpa name = web.openlab.edu.

主从DNS服务器

区域完全传送(主从DNS)

需要俩台DNS服务器:master slave

M:192.168.11.148

S:192.168.11.138

主服务器配置

1、主配置文件

添加允许传送的从服务器,allow-transfer { address_match_elment;...};

  1. [root@master named]# vim /etc/named.conf
  2. options {
  3. listen-on port 53 { 192.168.11.148; };
  4. //listen-on-v6 port 53 { ::1; };
  5. directory "/var/named";
  6. dump-file "/var/named/data/cache_dump.db";
  7. statistics-file "/var/named/data/named_stats.txt";
  8. memstatistics-file "/var/named/data/named_mem_stats.txt";
  9. recursing-file "/var/named/data/named.recursing";
  10. secroots-file "/var/named/data/named.secroots";
  11. allow-query { 192.168.11.0/24; };
  12. allow-transfer { 192.168.11.138;}; # 添加从服务器地址

2、数据文件

  1. [root@master named]# cat openlab.edu.zone
  2. $TTL 1D
  3. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  4. 2023031602 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS dns1.openlab.edu.
  10. NS dns2.openlab.edu.
  11. MX 5 mail.openlab.edu.
  12. dns1 A 192.168.11.148
  13. dns2 A 192.168.11.138
  14. mail A 192.168.11.222
  15. www A 192.168.11.111
  16. web CNAME www
  17. [root@master named]# cat 192.168.11.zone
  18. $TTL 1D
  19. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  20. 2023031602 ; serial
  21. 1D ; refresh
  22. 1H ; retry
  23. 1W ; expire
  24. 3H ) ; minimum
  25. NS dns1.openlab.edu.
  26. NS dns2.oppenlab.edu.
  27. dns1.openlab.edu. A 192.168.11.148
  28. dns2.openlab.edu. A 192.168.11.138
  29. 148 PTR dns1.openlab.edu.
  30. 138 PTR dns2.openlab.edu.
  31. 111 PTR www.openlab.edu.
  32. 111 PTR web.openlab.edu.
  33. 222 PTR mail.openlab.edu.

3、语法检测

  1. [root@master named]# named-checkzone "openlab.edu" 192.168.11.zone
  2. zone openlab.edu/IN: loaded serial 2023031602
  3. OK
  4. [root@master named]# named-checkzone "openlab.edu" openlab.edu.zone
  5. zone openlab.edu/IN: loaded serial 2023031602
  6. OK

4、重启服务

[root@master named]# systemctl restart named

从服务器配置

1、安装软件

[root@node02 ~]# yum install bind -y

2、主配置文件

  1. [root@node02 ~]# vim /etc/named.conf
  2. options {
  3. listen-on port 53 { 192.168.11.138; }; # 指向自己的IP
  4. //listen-on-v6 port 53 { ::1; };
  5. directory "/var/named";
  6. dump-file "/var/named/data/cache_dump.db";
  7. statistics-file "/var/named/data/named_stats.txt";
  8. memstatistics-file "/var/named/data/named_mem_stats.txt";
  9. secroots-file "/var/named/data/named.secroots";
  10. recursing-file "/var/named/data/named.recursing";
  11. allow-query {192.168.11.0/24; }; # 指向网段即可

3、数据文件

  1. [root@node02 ~]# vim /etc/named.rfc1912.zones
  2. zone "openlab.edu" IN {
  3. type slave;
  4. file "slaves/opnlab.edu.zone";
  5. masters {192.168.11.148;};
  6. };
  7. zone "11.168.192.in-addr.arpa" IN {
  8. type slave;
  9. file "slaves/192.168.11.zone";
  10. masters {192.168.11.148;};
  11. };

4、语法检测

[root@node02 ~]# named-checkconf

5、测试

  1. [root@node02 ~]# firewall-cmd --permanent --add-service=dns
  2. success
  3. [root@node02 ~]# firewall-cmd --reload
  4. success
  5. [root@node02 ~]# systemctl enable --now named.service
  6. Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.
  7. [root@node02 ~]# ll /var/named/slaves/
  8. total 8
  9. -rw-r--r--. 1 named named 508 Mar 16 14:25 192.168.11.zone
  10. -rw-r--r--. 1 named named 475 Mar 16 14:25 opnlab.edu.zone
  11. # 可以在本机上测试
  12. [root@node02 ~]# nslookup
  13. > server 192.168.11.138
  14. Default server: 192.168.11.138
  15. Address: 192.168.11.138#53
  16. > www.openlab.edu
  17. Server: 192.168.11.138
  18. Address: 192.168.11.138#53
  19. Name: www.openlab.edu
  20. Address: 192.168.11.111
  21. > 192.168.11.111
  22. 111.11.168.192.in-addr.arpa name = www.openlab.edu.
  23. 111.11.168.192.in-addr.arpa name = web.openlab.edu.
区域增量传送(主从DNS)
  1. [root@master named]# cat openlab.edu.zone
  2. $TTL 1D
  3. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  4. 2023031603 ; serial
  5. 1D ; refresh
  6. 1H ; retry
  7. 1W ; expire
  8. 3H ) ; minimum
  9. NS dns1.openlab.edu.
  10. NS dns2.openlab.edu.
  11. MX 5 mail.openlab.edu.
  12. dns1 A 192.168.11.148
  13. dns2 A 192.168.11.138
  14. mail A 192.168.11.222
  15. www A 192.168.11.111
  16. web CNAME www
  17. ftp A 192.168.11.112
  18. [root@master named]# cat 192.168.11.zone
  19. $TTL 1D
  20. @ IN SOA dns1.openlab.edu. admin.openlab.edu. (
  21. 2023031603 ; serial
  22. 1D ; refresh
  23. 1H ; retry
  24. 1W ; expire
  25. 3H ) ; minimum
  26. NS dns1.openlab.edu.
  27. NS dns2.oppenlab.edu.
  28. dns1.openlab.edu. A 192.168.11.148
  29. dns2.openlab.edu. A 192.168.11.148
  30. 148 PTR dns1.openlab.edu.
  31. 138 PTR dns2.openlab.edu.
  32. 111 PTR www.openlab.edu.
  33. 111 PTR web.openlab.edu.
  34. 222 PTR mail.openlab.edu.
  35. 112 PTR ftp.openlab.edu.

重启服务

[root@master named]# systemctl restart named.service

测试

  1. [root@node02 named]# nslookup ftp.openlab.edu 192.168.11.138
  2. Server: 192.168.11.138
  3. Address: 192.168.11.138#53
  4. Name: ftp.openlab.edu
  5. Address: 192.168.11.112
  6. [root@node02 named]# nslookup 192.168.11.148 192.168.11.138
  7. 148.11.168.192.in-addr.arpa name = dns1.openlab.edu.

web服务器

1、安装软件

[root@node01 ~]# yum install httpd -y

2、设置为开机自启动

[root@node01 ~]# systemctl enable --now httpd

3、查看状态

[root@node01 ~]# systemctl status httpd

4、查看进程

  1. [root@node01 ~]# ps -ef | grep httpd
  2. root 2447 1 0 15:57 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
  3. root 2521 2146 0 15:58 pts/2 00:00:00 grep --color=auto httpd

5、查看端口

  1. [root@node01 ~]# netstat -lntup | grep 80
  2. tcp6 0 0 :::80 :::* LISTEN 2447/httpd
  3. [root@node01 ~]# ss -lntup | grep 80
  4. tcp LISTEN 0 128 *:80 *:* users:(("httpd",pid=2573,fd=4),("httpd",pid=2572,fd=4),("httpd",pid=2571,fd=4),("httpd",pid=2447,fd=4))

6、关闭防火墙或者放行服务

  1. [root@node01 ~]# firewall-cmd --permanent --add-service=http
  2. success
  3. [root@node01 ~]# firewall-cmd --reload
  4. success

7、默认测试

8、默认测试路径

  1. [root@node01 ~]# echo "欢迎来我的web页面" > /var/www/html/index.html
  2. [root@node01 ~]# curl 192.168.11.104
  3. 欢迎来我的web页面

虚拟目录别名

1、创建虚拟目录存放位置及虚拟目录默认首页文件

  1. [root@node01 ~]# mkdir /openlab/xxgc -p
  2. [root@node01 ~]# cat /var/www/html/index.html
  3. 欢迎访问信息工程系主页!

2、创建、编辑虚拟目录子配置文件

  1. [root@node01 ~]# cat /etc/httpd/conf.d/vdir.conf
  2. Alias /xxgcx "/openlab/xxgc"
  3. <Directory "/openlab/xxgc">
  4. AllowOverride None
  5. Options Indexes FollowSymLinks
  6. Require all granted
  7. </Directory>

3、语法检测+重启服务

  1. [root@node01 ~]# httpd -t
  2. Syntax OK
  3. [root@node01 ~]# setenforce 0
  4. [root@node01 ~]# systemctl restart httpd.service

4、测试页面

虚拟主机

三类:

  • 基于IP:一台服务器申请多个IP
  • 基于端口:同一个IP,不同的端口
  • 基于域名:使用同样的IP,同样的端口,不同的域名

如何配?

安装一个在线帮助文档,查看帮助配置

  1. [root@node01 ~]# yum install httpd-manual -y
  2. [root@node01 ~]# systemctl restart httpd.service

基于IP

1、创建目录,准备测试页面

  1. [root@node01 ~]# mkdir -p /openlab/{news,blog,bbs}
  2. [root@node01 ~]# echo "新闻测试页!" > /openlab/news/index.html
  3. [root@node01 ~]# echo "blog测试页!" > /openlab/blog/index.html
  4. [root@node01 ~]# echo "bbs测试页!" > /openlab/bbs/index.html

2、给网卡添加IP,绑定对应的测试页面

  1. news:192.168.11.104
  2. blog:192.168.11.110
  3. bbs:192.168.11.120
  4. [root@node01 ~]# nmcli connection modify ens160 +ipv4.addresses 192.168.11.110/24
  5. [root@node01 ~]# nmcli connection modify ens160 +ipv4.addresses 192.168.11.120/24
  6. [root@node01 ~]#
  7. [root@node01 ~]# nmcli connection up ens160
  8. Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
  9. [root@node01 ~]# ip a
  10. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  11. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  12. inet 127.0.0.1/8 scope host lo
  13. valid_lft forever preferred_lft forever
  14. inet6 ::1/128 scope host
  15. valid_lft forever preferred_lft forever
  16. 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
  17. link/ether 00:0c:29:6b:0b:72 brd ff:ff:ff:ff:ff:ff
  18. inet 192.168.11.110/24 brd 192.168.11.255 scope global noprefixroute ens160
  19. valid_lft forever preferred_lft forever
  20. inet 192.168.11.120/24 brd 192.168.11.255 scope global secondary noprefixroute ens160
  21. valid_lft forever preferred_lft forever
  22. inet 192.168.11.104/24 brd 192.168.11.255 scope global secondary dynamic noprefixroute ens160
  23. valid_lft 1796sec preferred_lft 1796sec
  24. inet6 fe80::20c:29ff:fe6b:b72/64 scope link noprefixroute
  25. valid_lft forever preferred_lft forever

3、配置虚拟主机

  1. [root@node01 ~]# cd /etc/httpd/conf.d/
  2. [root@node01 conf.d]#
  3. [root@node01 conf.d]# ls
  4. autoindex.conf manual.conf README userdir.conf vdir.conf welcome.conf
  5. [root@node01 conf.d]# vim VirtualHost.conf
  6. [root@node01 conf.d]# cat VirtualHost.conf
  7. <Directory "/openlab/">
  8. AllowOverride None
  9. Options Indexes FollowSymLinks
  10. Require all granted
  11. </Directory>
  12. <VirtualHost 192.168.11.104:80>
  13. DocumentRoot "/openlab/news/"
  14. ServerName news.openlab.edu
  15. ErrorLog "/openlab/news/error_log"
  16. CustomLog "/openlab/news/access_log" combined
  17. </VirtualHost>
  18. <VirtualHost 192.168.11.110:80>
  19. DocumentRoot "/openlab/blog/"
  20. ServerName blog.openlab.edu
  21. ErrorLog "/openlab/blog/error_log"
  22. CustomLog "/openlab/blog/access_log" combined
  23. </VirtualHost>
  24. <VirtualHost 192.168.11.120:80>
  25. DocumentRoot "/openlab/bbs/"
  26. ServerName bbs.openlab.edu
  27. ErrorLog "/openlab/bbs/error_log"
  28. CustomLog "/openlab/bbs/access_log" combined
  29. </VirtualHost>

4、语法检测+重启服务

  1. [root@node01 conf.d]# httpd -t
  2. Syntax OK
  3. [root@node01 conf.d]# systemctl restart httpd.service

5、测试

6、恢复环境

  1. [root@node01 conf.d]# nmcli connection modify ens160 -ipv4.addresses 192.168.11.120/24
  2. [root@node01 conf.d]# nmcli connection modify ens160 -ipv4.addresses 192.168.11.110/24
  3. [root@node01 conf.d]# nmcli connection up ens160

基于端口

1、修改配置文件

  1. [root@node01 conf.d]# cat VirtualHost.conf
  2. <VirtualHost 192.168.11.104:80>
  3. DocumentRoot "/openlab/news/"
  4. ServerName news.openlab.edu
  5. ErrorLog "/openlab/news/error_log"
  6. CustomLog "/openlab/news/access_log" combined
  7. </VirtualHost>
  8. <VirtualHost 192.168.11.104:81>
  9. DocumentRoot "/openlab/blog/"
  10. ServerName blog.openlab.edu
  11. ErrorLog "/openlab/blog/error_log"
  12. CustomLog "/openlab/blog/access_log" combined
  13. </VirtualHost>
  14. <VirtualHost 192.168.11.104:82>
  15. DocumentRoot "/openlab/bbs/"
  16. ServerName bbs.openlab.edu
  17. ErrorLog "/openlab/bbs/error_log"
  18. CustomLog "/openlab/bbs/access_log" combined
  19. </VirtualHost>
  20. <Directory "/openlab/">
  21. AllowOverride None
  22. Options Indexes FollowSymLinks
  23. Require all granted
  24. </Directory>
  25. Listen 81
  26. Listen 82

2、重启服务 + 关闭防火墙 +selinux

  1. [root@node01 conf.d]# systemctl restart httpd.service
  2. [root@node01 conf.d]# systemctl stop firewalld.service
  3. [root@node01 conf.d]# setenforce 0
  4. [root@node01 conf.d]# systemctl restart httpd.service
  5. [root@node01 conf.d]# ss -lntup | grep 81
  6. tcp LISTEN 0 128 *:81 *:* users:(("httpd",pid=39951,fd=9),("httpd",pid=39601,fd=9),("httpd",pid=39600,fd=9),("httpd",pid=39599,fd=9),("httpd",pid=39476,fd=9))
  7. [root@node01 conf.d]# ss -lntup | grep 82
  8. tcp LISTEN 0 128 *:82 *:* users:(("httpd",pid=39951,fd=11),("httpd",pid=39601,fd=11),("httpd",pid=39600,fd=11),("httpd",pid=39599,fd=11),("httpd",pid=39476,fd=11))
  9. [root@node01 conf.d]# ss -lntup | grep 80
  10. tcp LISTEN 0 128 *:80 *:* users:(("httpd",pid=39951,fd=4),("httpd",pid=39601,fd=4),("httpd",pid=39600,fd=4),("httpd",pid=39599,fd=4),("httpd",pid=39476,fd=4))

3、测试

基于域名

1、修改配置文件

  1. [root@node01 conf.d]# cat VirtualHost.conf
  2. <VirtualHost 192.168.11.104:80>
  3. DocumentRoot "/openlab/news/"
  4. ServerName news.openlab.edu
  5. ErrorLog "/openlab/news/error_log"
  6. CustomLog "/openlab/news/access_log" combined
  7. </VirtualHost>
  8. <VirtualHost 192.168.11.104:80>
  9. DocumentRoot "/openlab/blog/"
  10. ServerName blog.openlab.edu
  11. ErrorLog "/openlab/blog/error_log"
  12. CustomLog "/openlab/blog/access_log" combined
  13. </VirtualHost>
  14. <VirtualHost 192.168.11.104:80>
  15. DocumentRoot "/openlab/bbs/"
  16. ServerName bbs.openlab.edu
  17. ErrorLog "/openlab/bbs/error_log"
  18. CustomLog "/openlab/bbs/access_log" combined
  19. </VirtualHost>
  20. <Directory "/openlab/">
  21. AllowOverride None
  22. Options Indexes FollowSymLinks
  23. Require all granted
  24. </Directory>

2、重启服务

[root@node01 conf.d]# systemctl restart httpd.service

3、没有DNS情况下修改hosts文件

  1. [root@node01 conf.d]# cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.11.104 news.openlab.edu blog.openlab.edu bbs.openlab.edu

4、测试

  1. [root@node01 conf.d]# curl news.openlab.edu
  2. 新闻测试页!
  3. [root@node01 conf.d]# curl blog.openlab.edu
  4. blog测试页!
  5. [root@node01 conf.d]# curl bbs.openlab.edu
  6. bbs测试页!

个人页面网站

1、修改redhat权限

  1. [root@node01 conf.d]# cd /home/redhat/
  2. [root@node01 redhat]# chmod 711 /home/redhat/

2、创建public_html目录

[root@node01 redhat]# mkdir public_html

3、写index.html默认页面

[root@node01 redhat]# echo "这是redhat个人测试页面" > public_html/index.html

4、关闭防火墙和selinux

  1. [root@node01 redhat]# systemctl is-active firewalld.service
  2. inactive
  3. [root@node01 redhat]# getenforce
  4. Permissive

5、修改配置文件

  1. [root@node01 conf.d]# vim userdir.conf
  2. <IfModule mod_userdir.c>
  3. #UserDir disabled
  4. UserDir public_html
  5. </IfModule>

6、语法检测+重启服务

  1. [root@node01 conf.d]# httpd -t
  2. Syntax OK
  3. [root@node01 conf.d]# systemctl restart httpd.service

加密解密

案例:基于https的静态站点

第一阶段:制作CA根证书

1、制作CA秘钥

操作过程:设置CA秘钥口令(123456)

  1. [root@node01 httpd]# mkdir /etc/httpd/ssl
  2. [root@node01 httpd]# cd /etc/httpd/ssl/
  3. [root@node01 ssl]# openssl genrsa -des3 -out ca.key 2048
  4. Generating RSA private key, 2048 bit long modulus (2 primes)
  5. ............+++++
  6. ............................................................................................................................................................+++++
  7. e is 65537 (0x010001)
  8. Enter pass phrase for ca.key:
  9. Verifying - Enter pass phrase for ca.key:

2、制作CA根证书申请

  1. [root@node01 ssl]# openssl req -new -key ca.key -out ca.csr
  2. Enter pass phrase for ca.key:
  3. You are about to be asked to enter information that will be incorporated
  4. into your certificate request.
  5. What you are about to enter is what is called a Distinguished Name or a DN.
  6. There are quite a few fields but you can leave some blank
  7. For some fields there will be a default value,
  8. If you enter '.', the field will be left blank.
  9. -----
  10. Country Name (2 letter code) [XX]:CN
  11. State or Province Name (full name) []:SX
  12. Locality Name (eg, city) [Default City]:Sx
  13. Organization Name (eg, company) [Default Company Ltd]:openlab
  14. Organizational Unit Name (eg, section) []:openlab
  15. Common Name (eg, your name or your server's hostname) []:tom
  16. Email Address []:
  17. Please enter the following 'extra' attributes
  18. to be sent with your certificate request
  19. A challenge password []:
  20. An optional company name []:

3、生成根签名证书

  1. [root@node01 ssl]# openssl x509 -req -days 3650 -signkey ca.key -in ca.csr -out ca.crt
  2. Signature ok
  3. subject=C = CN, ST = SX, L = Sx, O = openlab, OU = openlab, CN = tom
  4. Getting Private key
  5. Enter pass phrase for ca.key:
  6. [root@node01 ssl]# ls
  7. ca.crt ca.csr ca.key

第二阶段:制作服务器证书

1、制作服务器秘钥

  1. [root@node01 ssl]# openssl genrsa -des3 -out server.key 2048
  2. Generating RSA private key, 2048 bit long modulus (2 primes)
  3. ..........................................................................................+++++
  4. ..................................+++++
  5. e is 65537 (0x010001)
  6. Enter pass phrase for server.key:
  7. Verifying - Enter pass phrase for server.key:

2、制作服务器证书签名申请

  1. [root@node01 ssl]# openssl req -new -key server.key -out server.csr
  2. Enter pass phrase for server.key:
  3. You are about to be asked to enter information that will be incorporated
  4. into your certificate request.
  5. What you are about to enter is what is called a Distinguished Name or a DN.
  6. There are quite a few fields but you can leave some blank
  7. For some fields there will be a default value,
  8. If you enter '.', the field will be left blank.
  9. -----
  10. Country Name (2 letter code) [XX]:CN
  11. State or Province Name (full name) []:SC
  12. Locality Name (eg, city) [Default City]:cd
  13. Organization Name (eg, company) [Default Company Ltd]:it
  14. Organizational Unit Name (eg, section) []:it
  15. Common Name (eg, your name or your server's hostname) []:www.it.edu
  16. Email Address []:
  17. Please enter the following 'extra' attributes
  18. to be sent with your certificate request
  19. A challenge password []:
  20. An optional company name []:

3、签署证书

  1. [root@node01 ssl]# openssl x509 -req -days 3560 -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt
  2. Signature ok
  3. subject=C = CN, ST = SC, L = cd, O = it, OU = it, CN = www.it.edu
  4. Getting CA Private Key
  5. Enter pass phrase for ca.key:
  6. [root@node01 ssl]# ls
  7. ca.crt ca.csr ca.key ca.srl server.crt server.csr server.key

4、配置虚拟主机

  1. [root@node01 ssl]# vim /etc/httpd/conf.d/vhost.conf
  2. <VirtualHost *:443>
  3. DocumentRoot /var/www/web
  4. ServerName www.openlab.edu
  5. SSLEngine on
  6. SSLProtocol all -SSLv2
  7. SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!IDEA
  8. SSLCertificateFile /etc/httpd/ssl/server.crt
  9. SSLCertificateKeyFile /etc/httpd/ssl/server.key
  10. SSLCertificateChainFile /etc/httpd/ssl/ca.crt
  11. </VirtualHost>

5、测试页面

  1. [root@node01 ~]# mkdir /var/www/web
  2. [root@node01 ~]# echo "https测试页面!..."> /var/www/web/index.html

6、重启服务

  1. [root@node01 ssl]# systemctl restart httpd.service
  2. Enter TLS private key passphrase for www.openlab.edu:443 (RSA) : ******

image-20230317091124090

LAMP环境

1、安装软件

[root@node01 ~]# yum install httpd mariadb-server php  php-gd php-mysqlnd.x86_64  -y

2、测试环境

Apache和php协同

  1. [root@node01 ~]# cd /var/www/html/
  2. [root@node01 html]# vim phpinfo.php
  3. [root@node01 html]# cat phpinfo.php
  4. <?php
  5. phpinfo();
  6. ?>
  7. [root@node01 html]# systemctl enable --now httpd php-fpm.service

image-20230317092554688

php与mariadb协同

启动数据库

[root@node01 html]# systemctl enable --now mariadb

初始安全设置

  1. [root@node01 html]# mysql_secure_installation
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MariaDB to secure it, we'll need the current
  5. password for the root user. If you've just installed MariaDB, and
  6. you haven't set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8. Enter current password for root (enter for none):
  9. OK, successfully used password, moving on...
  10. Setting the root password ensures that nobody can log into the MariaDB
  11. root user without the proper authorisation.
  12. Set root password? [Y/n] y
  13. New password:
  14. Re-enter new password:
  15. Password updated successfully!
  16. Reloading privilege tables..
  17. ... Success!
  18. By default, a MariaDB installation has an anonymous user, allowing anyone
  19. to log into MariaDB without having to have a user account created for
  20. them. This is intended only for testing, and to make the installation
  21. go a bit smoother. You should remove them before moving into a
  22. production environment.
  23. Remove anonymous users? [Y/n] y
  24. ... Success!
  25. Normally, root should only be allowed to connect from 'localhost'. This
  26. ensures that someone cannot guess at the root password from the network.
  27. Disallow root login remotely? [Y/n] y
  28. ... Success!
  29. By default, MariaDB comes with a database named 'test' that anyone can
  30. access. This is also intended only for testing, and should be removed
  31. before moving into a production environment.
  32. Remove test database and access to it? [Y/n] y
  33. - Dropping test database...
  34. ... Success!
  35. - Removing privileges on test database...
  36. ... Success!
  37. Reloading the privilege tables will ensure that all changes made so far
  38. will take effect immediately.
  39. Reload privilege tables now? [Y/n] y
  40. ... Success!
  41. Cleaning up...
  42. All done! If you've completed all of the above steps, your MariaDB
  43. installation should now be secure.
  44. Thanks for using MariaDB!

测试php数据库

  1. [root@node01 html]# cat php_mysql.php
  2. <?php
  3. $con = new Mysqli("localhost","root","123456");
  4. if ($con->connect_error)
  5. {
  6. die('Could not connect: ' . $con->connect_error);
  7. }
  8. else{
  9. echo "Success!";
  10. }
  11. // some code
  12. mysql_close($con);
  13. ?>

image-20230317093918211

测试完毕!删除这俩个文件!

3、部署php应用

博客 论坛 门户网站

1> 上传软件

2> 解压到指定目录

3> 修改权限

4> 向导安装

FTP服务器

服务端:

1、安装软件

[root@node01 ~]# yum install vsftpd.x86_64 -y

2、重启服务

[root@node01 ~]# systemctl restart vsftpd.service

3、查看状态

[root@node01 ~]# systemctl status vsftpd.service

4、查看端口

  1. [root@node01 ~]# ss -lntup | grep ftp
  2. tcp LISTEN 0 32 *:21 *:* users:(("vsftpd",pid=2669,fd=3))

5、放行服务

  1. [root@node01 ~]# firewall-cmd --permanent --add-service=ftp
  2. success
  3. [root@node01 ~]# firewall-cmd --reload
  4. success
  5. [root@node01 ~]# firewall-cmd --list-all
  6. public (active)
  7. target: default
  8. icmp-block-inversion: no
  9. interfaces: ens160
  10. sources:
  11. services: cockpit dhcpv6-client ftp ssh
  12. ports:
  13. protocols:
  14. forward: no
  15. masquerade: no
  16. forward-ports:
  17. source-ports:
  18. icmp-blocks:
  19. rich rules:

6、修改主配置文件

  1. [root@node01 ~]# vim /etc/vsftpd/vsftpd.conf
  2. #anonymous_enable=NO
  3. anonymous_enable=yes
  4. [root@node01 ~]# systemctl restart vsftpd.service

客户端

1、安装软件

[root@node02 ~]# yum install ftp.x86_64  lftp -y

2、连接

  1. [root@node02 ~]# ftp 192.168.11.104
  2. Connected to 192.168.11.104 (192.168.11.104).
  3. 220 (vsFTPd 3.0.3)
  4. Name (192.168.11.104:root): anonymous
  5. 331 Please specify the password.
  6. Password:
  7. 230 Login successful.
  8. Remote system type is UNIX.
  9. Using binary mode to transfer files.
  10. ftp>bye
  11. [root@node02 ~]# lftp 192.168.11.104
  12. lftp 192.168.11.104:~> user ftp
  13. Password:
  14. lftp ftp@192.168.11.104:~> ls
  15. drwxr-xr-x 2 0 0 6 Apr 22 2021 pub
  16. lftp ftp@192.168.11.104:/> exit

案例:扩展学校的FTP服务器

1、建立用于维护网站的禁止登录且家目录为/var/www/web1的用户user1 设置用户密码 创建用于测试的文件

  1. [root@node01 ~]# mkdir -p /var/www/web1
  2. [root@node01 ~]# echo "www.openlab.edu" > /var/www/web1/本地用户访问ftp.txt
  3. [root@node01 ~]# chmod -R 757 /var/www/web1/
  4. [root@node01 ~]# useradd user1 -s /bin/bash
  5. [root@node01 ~]# echo 123456 | passwd --stdin user1
  6. Changing password for user user1.
  7. passwd: all authentication tokens updated successfully.
  8. [root@node01 ~]# chown -R user1 /var/www/web1/
  9. [root@node01 ~]# ll -d /var/www/web1/
  10. drwxr-xrwx. 2 user1 root 39 Mar 18 14:23 /var/www/web1/

2、编辑主配置文件 重启服务

  1. [root@node01 ~]# vim /etc/vsftpd/vsftpd.conf
  2. local_enable=YES
  3. anonymous_enable=NO
  4. local_root=/var/www/web1
  5. write_enable=YES
  6. local_umask=022
  7. connect_from_port_20=YES
  8. chroot_local_user=NO
  9. chroot_list_enable=YES
  10. chroot_list_file=/etc/vsftpd/chroot_list
  11. allow_writeable_chroot=YES
  12. [root@node01 ~]# systemctl restart vsftpd.service

3、建立/etc/vsftpd/chroot_list文件,锁定用户

  1. [root@node01 ~]# cat /etc/vsftpd/chroot_list
  2. user1

4、测试

  1. [root@node02 ~]# ftp 192.168.11.104
  2. Connected to 192.168.11.104 (192.168.11.104).
  3. 220 (vsFTPd 3.0.3)
  4. Name (192.168.11.104:root): user1
  5. 331 Please specify the password.
  6. Password:
  7. 230 Login successful.
  8. Remote system type is UNIX.
  9. Using binary mode to transfer files.
  10. ftp>

案例:配置一个虚拟用户访问ftp

本地用户user2

虚拟用户z3 l4

虚拟用户目录:

z3 /ftp/public 下载

l4 /var/www/web2 上传下载

1、创建虚拟用户对应的本地用户及目录

  1. [root@node01 ~]# useradd user2 -s /sbin/nologin
  2. [root@node01 ~]# mkdir -p /ftp/public /var/www/web2
  3. [root@node01 ~]# echo "test file "> /ftp/public/f1.txt
  4. [root@node01 ~]# echo "test file "> /var/www/web2/f1.txt
  5. [root@node01 ~]# chown user2 /var/www/web2/ /ftp/public/
  6. [root@node01 ~]# chmod -R 755 /var/www/web2/ /ftp/public/

2、创建虚拟用户文件

  1. [root@node01 ~]# cat /etc/vsftpd/vuser.list
  2. z3
  3. 123
  4. l4
  5. 456

3、转换虚拟用户文件

  1. [root@node01 ~]# db_load -T -t hash -f /etc/vsftpd/vuser.list /etc/vsftpd/vuser.db
  2. [root@node01 ~]# chmod 600 /etc/vsftpd/vuser.*

4、创建用户用户登录时的PAM文件

  1. [root@node01 ~]# cd /etc/pam.d/
  2. [root@node01 pam.d]# cp -p vsftpd vuser.vu
  3. [root@node01 pam.d]# vim vuser.vu
  4. [root@node01 pam.d]# cat vuser.vu
  5. #%PAM-1.0
  6. auth sufficient pam_userdb.so db=/etc/vsftpd/vuser
  7. account sufficient pam_userdb.so db=/etc/vsftpd/vuser
  8. session optional pam_keyinit.so force revoke
  9. auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
  10. auth required pam_shells.so
  11. auth include password-auth
  12. account include password-auth
  13. session required pam_loginuid.so
  14. session include password-auth

5、修改配置文件

  1. [root@node01 ~]# vim /etc/vsftpd/vsftpd.conf
  2. anonymous_enable=NO //禁止匿名登录
  3. local_enable=YES //允许本地用户模式,由于映射的系统用户为本地用户,因此此项必须开启
  4. guest_enable=YES //开启虚拟用户模式
  5. guest_username=user2 //指定虚拟用户账号映射到本地账号vftp
  6. pam_service_name=vuser.vu //指定pam文件
  7. chroot_local_user=YES //禁锢用户在其家目录
  8. allow_writeable_chroot=YES //允许禁锢的FTP根目录可写
  9. user_config_dir=/etc/vsftpd/vconfig //指定虚拟用户的权限配置目录
  10. userlist_enable=YES
  11. userlist_deny=YES
  12. virtual_user_local_privs=YES

6、虚拟用户配置专用文件

  1. [root@node01 ~]# mkdir -p /etc/vsftpd/vconfig
  2. [root@node01 ~]# cat /etc/vsftpd/vconfig/z3
  3. local_root=/ftp/public/
  4. anno_world_readable_only=YES
  5. write_enable=NO
  6. anno_max_rate=500000
  7. [root@node01 ~]# cat /etc/vsftpd/vconfig/l4
  8. local_root=/var/www/web2/
  9. write_enable=YES
  10. anno_upload_enable=YES
  11. anno_mkdir_wirte_enable=YES
  12. anno_other_write_enable=YES
  13. anno_max_rate=500000
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号