首页
归档
留言板
时光轴
推荐
Cloud
图床
导航
Search
1
openstact 基础环境安装 (手动版)
298 阅读
2
域名
191 阅读
3
Mariadb 主从复制&读写分离
186 阅读
4
查询化妆品许可证信息
179 阅读
5
模拟登录古诗文网
178 阅读
Python
Linux
随笔
mysql
openstack
登录
Search
标签搜索
Pike
linux
python
爬虫
mysql
openstack
Essay
Ansible
docker
Zabbix
Internet
Redis
1+X
Hyper-V
jenkins
Acha
累计撰写
65
篇文章
累计收到
1
条评论
首页
栏目
Python
Linux
随笔
mysql
openstack
页面
归档
留言板
时光轴
推荐
Cloud
图床
导航
搜索到
6
篇与
linux
的结果
2021-07-04
1+X 初级实验
私有云实训 一、本地 YUM 源管理 使用 VMWare 软件启动提供的 xserver1 虚拟机(配置虚拟机 xserver1 的 IP 为 `192.168.100.11`,主机名为 xserver1) 在虚拟机的/root 目录下,存在一个`CentOS-7-x86_64-DVD-1511.iso` 的镜像文件,使用这个镜像文件配置本地 yum 源, 要求将这个镜像文件挂载在`/opt/centos` 目录,请问如何配置自己的 local.repo 文件,使得可以使用该镜像中的软件包,安装软件。 请将 local.repo 文件的内容和执行 yum repolist 的返回结果(简要)写到下方。 echo "TYPE=Ethernet BOOTPROTO=static DEVICE=eno16777736 ONBOOT=yes IPADDR=192.168.100.11 GATEWAY=192.168.100.1 PREFIX=24" > /etc/sysconfig/network-scripts/ifcfg-eno16777736 [root@xserver1 ~]# hostnamectl set-hostname xserver1 [root@xserver1 ~]# bash [root@xserver1 ~]#cd [root@xserver1 ~]# mkdir /opt/centos [root@xserver1 ~]# mount -o loop CentOS-7-x86_64-DVD-1511.iso /opt/centos/ [root@xserver1 ~]# mkdir /etc/yum.repos.d/bak [root@xserver1 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ echo "[centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1" > /etc/yum.repos.d/local.repo [root@xserver1 ~]# yum clean all [root@xserver1 ~]# yum repolist Loaded plugins: fastestmirror centos | 3.6 kB 00:00:00 (1/2): centos/group_gz | 155 kB 00:00:00 (2/2): centos/primary_db | 2.8 MB 00:00:00 Determining fastest mirrors repo id repo name status centos centos 3,723 repolist: 3,723 二、FTP 安装使用 使用 xserver1 虚拟机,安装 `ftp 服务`,并配置 ftp 的共享目录为/opt。 使用VMWare 软件继续启动提供的 xserver2 虚拟机(配置虚拟机 xserver2 的 IP 为`192.168.100.12`,主机名为xserver2), 并创建该虚拟机的 yum 源文件 `ftp.repo` 使用xserver1 的ftp 源(配置文件中的FTP 地址使用主机名)。 配置完成后,将xserver1节点执行 netstat -ntpl 命令(netstat 命令若不能用,则自行安装 net-tools 工具)的返回结果(简要)和将 xserver2 节点的 ftp.repo 文件内容写到下方。 [root@xserver1 ~]# yum instal vsftpd -y [root@xserver1 ~]# echo anon_root=/opt/ >> /etc/vsftpd/vsftpd.conf [root@xserver1 ~]# systemctl start vsftpd && systemctl enable vsftpd echo "TYPE=Ethernet BOOTPROTO=static DEVICE=eno16777736 ONBOOT=yes IPADDR=192.168.100.12 GATEWAY=192.168.100.1 PREFIX=24" > /etc/sysconfig/network-scripts/ifcfg-eno16777736 [root@localhost ~]# hostnamectl set-hostname xserver2 [root@localhost ~]# bash echo "[centos] name=centos baseurl=ftp://192.168.100.11/centos gpgcheck=0 enabled=1" > /etc/yum.repos.d/ftp.repo [root@xserver2 ~]# setenforce 0 [root@xserver2 ~]# systemctl stop firewalld && systemctl disable firewalld [root@xserver1 ~]# setenforce 0 [root@xserver1 ~]# systemctl stop firewalld && systemctl disable firewalld [root@xserver2 ~]# yum clean all [root@xserver2 ~]# yum repolist Loaded plugins: fastestmirror centos | 3.6 kB 00:00:00 (1/2): centos/group_gz | 155 kB 00:00:00 (2/2): centos/primary_db | 2.8 MB 00:00:00 Determining fastest mirrors repo id repo name status centos centos 3,723 repolist: 3,723 [root@xserver1 ~]# yum install -y net-tools [root@xserver1 ~]# netstat -ntpl tcp6 0 0 :::21 :::* LISTEN 3280/vsftpd 三、NFS 服务管理 使用 xserver1、xserver2 虚拟机,安装 NFS 服务所需要的软件包,将 xserver1 节点中的/mnt/share 目录使用 NFS 服务共享出来(目录不存在请自行创建,要求可访问共享目录的网段为 192.168.100.0/24), 接着在 xserver2 节点上,将 xserver1中共享的文件挂载到/mnt 目录下。 操作完毕后,依次将 xserver1 节点上执行showmount -e ip 命令和 xserver2 节点上执行 df -h 命令的返回结果(简要)写到下方 [root@xserver1 ~]# yum -y install nfs-utils rpcbind [root@xserver2 ~]# yum -y install nfs-utils rpcbind echo "/mnt/share 192.168.100.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501)" > /etc/exports [root@xserver1 ~]# exportfs -r [root@xserver1 ~]# systemctl start rpcbind && systemctl enable rpcbind [root@xserver1 ~]# systemctl start nfs-server && systemctl enable nfs-server [root@xserver1 ~]# showmount -e 192.168.100.11 Export list for 192.168.100.11: /mnt/share 192.168.100.0/24 [root@xserver2 ~]# setenforce 0 [root@xserver2 ~]# systemctl stop firewalld && systemctl disable firewalld [root@xserver1 ~]# setenforce 0 [root@xserver1 ~]# systemctl stop firewalld && systemctl disable firewalld [root@xserver2 ~]# mount -t nfs 192.168.100.11:/mnt/share /mnt [root@xserver2 ~]# df -h 192.168.100.11:/mnt/share 36G 7.6G 29G 22% /mnt 四、主从数据库管理 在 xserver1、xserver2 上安装 mariadb 数据库, 并配置为主从数据库(xserver1 为主节点、xserver2 为从节点),实现两个数据库的主从同步。 配置完毕后,请在 xserver2 上的数据库中执行“show slave status \G”命令查询从节点复制状态,将查询到的结果(简要)写到下方。 # xserver1 & xserver2 都执行 echo "192.168.100.11 mysql1 192.168.100.12 mysql2" >> /etc/hosts [root@xserver1 ~]# yum install -y mariadb mariadb-server [root@xserver1 ~]# systemctl start mariadb && systemctl enable mariadb [root@xserver2 ~]# yum install -y mariadb mariadb-server [root@xserver2 ~]# systemctl start mariadb && systemctl enable mariadb # xserver1 & xserver2 都执行 [root@xserver1 ~]# mysql_secure_installation Disallow root login remotely? [Y/n] n 其他为 yes ;密码设置为 000000 # 为 xserver1/etc/my.cnf 中的[mysqld]增添如下内容 log_bin=mysql-bin binlog_ignore_db=mysql server_id=11 # xserver1 MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "000000"; MariaDB [(none)]> grant replication slave on *.* to 'user'@'mysql2' identified by '000000'; # 为 xserver2 /etc/my.cnf 中的[mysqld]增添如下内容 log_bin=mysql-bin binlog_ignore_db=mysql server_id=12 # xserver2 MariaDB [(none)]> change master to master_host='mysql1',master_user='user',master_password='000000'; MariaDB [(none)]> start slave; MariaDB [(none)]> show slave status\G `Slave_IO_Running: Yes` `Slave_SQL_Running: Yes` ## 验证数据同步 # xserver1 MariaDB [(none)]> create database test; MariaDB [(none)]> use test; MariaDB [test]> create table company(id int not null primary key,name varchar(50),addr varchar(255)); MariaDB [test]> insert into company values(1,"alibaba","china"); MariaDB [test]> select * from company; # xserver2 MariaDB [(none)]> show databases; MariaDB [(none)]> use test; MariaDB [test]> show tables; MariaDB [test]> select * from company; +----+---------+-------+ | id | name | addr | +----+---------+-------+ | 1 | alibaba | china | +----+---------+-------+ 1 row in set (0.01 sec) 五、LNMP 环境部署 使用 xserver1 节点,安装单节点 lnmp 环境。 安装 lnmp 环境需要用到的 YUM 源为 CentOS-7-x86_64-DVD-1511.iso 和 lnmp 目录(均在/root 目录下)。 安装并配置完 lnmp 环境后。依次查询数据库、nginx、php 服务的状态,并使用 netstat -ntpl 命令查看端口开放情况。 最后依次将查询服务状态的返回结果(简要),和查看端口开放情况的返回结果(简要)写到下方。 echo "[lnmp] name=centos baseurl=file:///root/lnmp gpgcheck=0 enabled=1" >> /etc/yum.repos.d/local.repo [root@xserver1 ~]# yum clean all [root@xserver1 ~]# yum repolist [root@xserver1 ~]# yum install -y nginx echo "server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }" > /etc/nginx/conf.d/default.conf [root@xserver1 ~]# mysql -uroot -p000000 MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '000000' with grant option; MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by '000000' with grant option; MariaDB [(none)]> create database wordpress; [root@xserver1 ~]# yum install -y php-fpm php-mysql [root@xserver1 ~]# vi /etc/php-fpm.d/www.conf #修改下两行 user = nginx group = nginx [root@xserver1 ~]# systemctl restart nginx php-fpm [root@xserver1 ~]# yum install net-tools [root@xserver1 ~]# netstat -ntpl 六、部署 WordPress 应用 使用 xserver1 节点,基于 lnmp 环境,部署 WordPress 应用(WordPress 源码包在/root 目录下)。 应用部署完毕后,设置 WordPress 的站点标题为自己的姓名( 例: 名字叫张三, 则设置站点标题为张三的 BLOG), 设置完毕后登录WordPresss 首页。最后将命令 curl ip(ip 为 wordpress 的首页 ip)的返回结果(简要)写到下方。 [root@xserver1 ~]# yum install -y unzip [root@xserver1 ~]# unzip wordpress-4.7.3-zh_CN.zip [root@xserver1 ~]# cp -rfv wordpress/* /usr/share/nginx/html/ echo "<?php define('DB_NAME', 'wordpress'); define('DB_USER', 'root'); define('DB_PASSWORD', '000000'); define('DB_HOST', 'localhost'); define('DB_CHARSET', 'utf8mb4'); define('DB_COLLATE', ''); define('AUTH_KEY', '<*sWiXc.1x HhNW`r>o?o7b,l`PoiY`_Ji/YD>o4Cc}460|Bew2-Ba)X/LZmsbvS'); define('SECURE_AUTH_KEY', '`v$-3/Gk`/&yRoSBoVrc+%*=WGmQc;R0!KxY}HM61V9Pcyz&= Xw986qi4/,W*4j'); define('LOGGED_IN_KEY', '/%Iuho!m&L#d1J=S:*6C~4>7@72$ZcGJcE=bW)jM0wl^|ZO2YIX5OllUMG*Wr1?W'); define('NONCE_KEY', 'K!KOU7%&2K=x^o7p7VG>/ast51N>ry_Rcl^)c}WOong&~cuh>p 8twe{B]Z[7Q)]'); define('AUTH_SALT', '#ho(+-ICZ>@fy>^;U],e!9Y<sbGV$|LLo)F[Lkveh]~s|Q9KQ)g#cCrgw2fGviP,'); define('SECURE_AUTH_SALT', 'l~@~( d2k-Gh?VczpK(_4}8#;BEX0RFncorH#qf1{r<-1$DpM#@bcBKjv)R4Q}_9'); define('LOGGED_IN_SALT', '1q.8W-yy)tNt^$+pSScX>o*UDX!T?>I%{_RP~<*heM|A6j[6OfL4]w 2:SI)cuud'); define('NONCE_SALT', '6kt&5<?n%]:z4[%i6,jL-l@i#!$v8x-[JXERj+*dja{]))<e`aE!qwzy>?kw$IKI'); $table_prefix = 'wp_'; define('WP_DEBUG', false); define('WP_ZH_CN_ICP_NUM', true); if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); require_once(ABSPATH . 'wp-settings.php'); " > /usr/share/nginx/html/wp-config.php [root@xserver1 ~]# systemctl restart mariadb nginx php-fpm [root@xserver1 ~]# netstat -lntp [root@xserver1 ~]# curl 192.168.100.11 七、Linux 存储 LVM 管理 使用 xserver1 虚拟机,使用 VMWare 软件自行添加一块大小为 20G 的硬盘, 使用 fdisk 命令对该硬盘进形分区, 要求分出两个大小为 5G 的分区。使用两个分区,创建名 xcloudvg 的卷组, 然后再创建一个 5G 的分区,将 xcloudvg 扩容至 15G,最后执行 vgdisplay 命令查看卷组信息。 将上述所有操作命令和返回结果(简要)写到下方。 [root@controller ~]# lsblk [root@controller ~]# fdisk /dev/sdb # 创建分区 3个分区 [root@controller ~]# lsblk [root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2 [root@localhost ~]# vgcreate xcloudvg /dev/sdb[1-2] [root@localhost ~]# vgextend xcloudvg /dev/sdb3 八、OpenStack Keystone 管理 使用 VMWare 软件启动提供的 opensatckallinone 镜像,自行检查 openstack 中各服务的状态,若有问题自行排查。 在 keystone 中创建用户 testuser,密码为123456,创建好之后,查看 testuser 的详细信息。 将上述所有操作命令及返回结果(简要)写到下方。 [root@controller ~]# source /etc/keystone/admin-openrc.sh [root@controller ~]# openstack user create --password 123456 --domain xiandian usertest [root@controller ~]# openstack user show usertest +-----------+----------------------------------+ | Field | Value | +-----------+----------------------------------+ | domain_id | 9321f21a94ef4f85993e92a228892418 | | enabled | True | | id | b9b24fd835344500837cb2cbfb79d90d | | name | usertest | +-----------+----------------------------------+ 九、OpenStack Glance 管理 使用 VMWare 软件启动提供的 opensatckallinone 镜像,自行检查 openstack 中各服务的状态,若有问题自行排查。 在 xserver1 节点的/root 目录下存在一个cirros-0.3.4-x86_64-disk.img 镜像; 使用 glance 命令将镜像上传, 并命名为mycirros, 最后将glance image-show id 命令的返回结果(简要)写到下方。 [root@controller ~]# source /etc/keystone/admin-openrc.sh [root@controller ~]# glance image-create --name "mycirros" --disk-format qcow2 --container-format bare --progress < cirros-0.3.2-x86_64-disk.img [=============================>] 100% +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 64d7c1cd2b6f60c92c14662941cb7913 | | container_format | bare | | created_at | 2021-06-30T19:45:27Z | | disk_format | qcow2 | | id | ae634816-62f7-4bcb-8b89-04166478d834 | | min_disk | 0 | | min_ram | 0 | | name | mycirros | | owner | f9ff39ba9daa4e5a8fee1fc50e2d2b34 | | protected | False | | size | 13167616 | | status | active | | tags | [] | | updated_at | 2021-06-30T19:45:27Z | | virtual_size | None | | visibility | private | +------------------+--------------------------------------+ [root@controller ~]# glance image-show mycirros +------------------+--------------------------------------+ | Property | Value | +------------------+--------------------------------------+ | checksum | 64d7c1cd2b6f60c92c14662941cb7913 | | container_format | bare | | created_at | 2021-06-30T19:45:27Z | | disk_format | qcow2 | | id | ae634816-62f7-4bcb-8b89-04166478d834 | | min_disk | 0 | | min_ram | 0 | | name | mycirros | | owner | f9ff39ba9daa4e5a8fee1fc50e2d2b34 | | protected | False | | size | 13167616 | | status | active | | tags | [] | | updated_at | 2021-06-30T19:45:27Z | | virtual_size | None | | visibility | private | +------------------+--------------------------------------+ 十、Docker 安装 使用 xserver1 节点,自行配置 YUM 源,安装 docker 服务(需要用到的包为xserver1 节点/root 目录下的 Docker.tar.gz)。 安装完服务后,将 registry_latest.tar 上传到 xserver1 节点中并配置为私有仓库。 要求启动 registry 容器时,将内部保存文件的目录映射到外部的/opt/registry 目录,将内部的 5000 端口映射到外部5000 端口。 依次将启动 registry 容器的命令及返回结果、执行 docker info 命令的返回结果(简要)写到下方。 mkdir /opt/docker mv Docker.tar.gz /opt/docker tar -zxvf /opt/docker/Docker.tar.gz echo "[kubernetes] name=kubernetes baseurl=file:///opt/docker/Docker gpgcheck=0 enabled=1 " >> /etc/yum.repos.d/local.repo [root@xserver1 ~]# yum clean all [root@xserver1 ~]# yum repolist [root@xserver1 ~]# yum upgrade -y [root@xserver1 ~]# uname -r [root@xserver1 ~]# iptables -t filter -F [root@xserver1 ~]# iptables -t filter -X [root@xserver1 ~]# iptables -t filter -Z [root@xserver1 ~]# /usr/sbin/iptables-save [root@xserver1 ~]# reboot [root@xserver1 ~]# rm -rf /etc/yum.repos.d/C* [root@xserver1 ~]# yum clean all [root@xserver1 ~]# yum repolist cat >> /etc/sysctl.conf << EOF net.ipv4.ip_forward=1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF [root@xserver1 ~]# sysctl -p [root@xserver1 ~]# modprobe br_netfilter [root@xserver1 ~]# yum install -y yum-utils device-mapper-persistent-data [root@xserver1 ~]# yum install docker-ce -y [root@xserver1 ~]# systemctl daemon-reload [root@xserver1 ~]# systemctl restart docker [root@xserver1 ~]# systemctl enable docker [root@xserver1 ~]# docker info [root@xserver1 ~]# docker load -i /opt/docker/images/registry_latest.tar [root@xserver1 opt]# docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry f32a97de94e1 十一、Dockerfile 编写 使用 xserver1 节点,新建目录 centos-jdk,将提供的 jdk-8u141-linux-x64.tar.gz 复制新建的目录,然后编辑 Dockerfile 文件,文件要求如下: 1.使用 centos:latest 基础镜像; 2.指定作为为 xiandian; 3.新建文件夹/usr/local/java 用于存放 jdk 文件; 4.将 JDK 文件复制到镜像内创建的目录并自动解压; 5.创建软连接:ln -s /usr/local/java/jdk1.8.0_141 /usr/local/java/jdk; 6.设置环境变量如下 ENV JAVA_HOME /usr/local/java/jdk ENV JRE_HOME ${JAVA_HOME}/jre ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH ${JAVA_HOME}/bin:$PATH 编写完毕后,构建名为 centos-jdk 的镜像,构建成功后,查看镜像列表。 最后将 Dockerfile 的内容、构建镜像的操作命令、查看镜像列表的命令和返回的(简要)写到下方。 [root@xserver1 ~]# mkdir /home/centos-jdk [root@xserver1 ~]# cp /opt/docker/jdk/jdk-8u141-linux-x64.tar.gz /home/centos-jdk [root@xserver1 centos-jdk]# cat /home/centos-jdk/dockerfile FROM centos:latest MAINTAINER xiandian WORKDIR /usr/local/java ADD jdk-8u141-linux-x64.tar.gz /usr/local/java RUN ln -s /usr/local/java/jdk1.8.0_141 /usr/local/java/jdk ENV JAVA_HOME /usr/local/java/jdk ENV JRE_HOME ${JAVA_HOME}/jre ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib ENV PATH ${JAVA_HOME}/bin:$PATH [root@xserver1 ~]# docker build -t centos-jdk /home/centos-jdk [root@xserver1 ~]# docker run -d -it --rm centos-jdk 十二、swarm集群部署 写出部署swarm集群的主要步骤 1. 主机映射 2. 时间同步 3. 配置Docker API 4. 初始化集群 5. Node节点加入集群
2021年07月04日
85 阅读
0 评论
0 点赞
2021-06-21
nginx 基础学习
nginx 默认配置 user www www; #程序运行用户和组 worker_processes auto; #启动进程,指定 nginx 启动的工作进程数量,建议按照 cpu 数目来指定,一般等于 cpu 核心数目 error_log /home/wwwlogs/nginx_error.log crit; #全局错误日志 pid /usr/local/nginx/logs/nginx.pid; #主进程 PID 保存文件 worker_rlimit_nofile 51200; #文件描述符数量 events { use epoll; #使用 epoll 模型,对于 2.6 以上的内核,建议使用 epoll 模型以提高性能 worker_connections 51200; #工作进程的最大连接数量 } http{ #网站优化参数 server { #具体的某一网站的配置信息 listen 80; #监听端口 root html; #网页根目录(/usr/local/nginx/html) server_name www.atguigu.com; #服务器域名 index index.html; #默认加载页面 access_log logs/access.log; #访问日志保存位置 ......; location (.*)\.php$ { 用正则匹配具体的访问对象; } location { 跳转等规则; } } server { 虚拟主机; } } Nginx 的状态统计 1. 安装 nginx 时将 --with-http_stub_status_module 模块开启 2. 修改 nginx 配置文件(写入要访问的 server 标签中) location /nginx_status{ stub_status on; access_log off; } 3. 客户端访问网址:http://IP/nginx_status `Active connections` 表示当前的活动连接数 `server accepts handled requests` 表示已经处理的连接信息 三个数字依次表示已处理的连接数、成功的 TCP 握手次数、已处理的请求数 目录保护 1. 原理和 apache 的目录保护原理一样(利用上一个实验接着完成) 2. 在状态统计的 location 中添加: auth_basic "Welcome to nginx_status!"; auth_basic_user_file /usr/local/nginx/html/htpasswd.nginx; 3. 使用 http 的命令 htpasswd 进行用户密码文件的创建(生成在上面指定的位置) #htpasswd -c /usr/local/nginx/html/htpasswd.nginx user 4. 重启 nginx 并再次访问统计页面 基于 IP 的身份验证(访问控制) 1. 接着上一个实验完成操作 2. 在状态统计的 location 中添加: allow 192.168.88.1; deny 192.168.88.0/24; #仅允许 192.168.88.1 访问服务器 虚拟主机(基于域名) 1. 提前准备好两个网站的域名, 并且规划好两个网站网页存放目录 2. 在 Nginx 主配置文件中并列编写两个 server 标签,并分别写好各自信息 server { listen 80; server_name blog.atguigu.com; index index.html index.htm index.php; root html/blog; access_log logs/blog-access.log main; } server { listen 80; server_name bbs.atguigu.com; index index.html index.htm index.php; root html/bbs; access_log logs/bbs-access.log main; } 3. 分别访问两个不同的域名验证结果 反向代理 1. 在另外一台机器上安装 apache, 启动并填写测试页面 2. 在 nginx 服务器的配置文件中添加(写在某一个网站的 server 标签内) location / { proxy_pass http://192.168.88.100:80; #此处填写 apache 服务器的 IP 地址 } 3. 重启 nginx,并使用客户端访问测试 负载调度 1. 使用默认的 rr 轮训算法,修改 nginx 配置文件 upstream bbs { #此标签在 server 标签前添加 server 192.168.88.100:80; server 192.168.88.200:80; } server { ........; #修改自带的 location / 的标签,将原内容删除,添加下列两项 location / { proxy_pass http://bbs; #添加反向代理,代理地址填写 upstream 声明的名字 proxy_set_header Host $host; #重写请求头部,保证网站所有页面都可访问成功 } } 2. 开启并设置两台 88.100 & 88.200 的主机 安装 apache 并设置不同的 index.html 页面内容(设置不同页面是为了看实验效果) 3. 重启 nginx,并使用客户端访问测试
2021年06月21日
66 阅读
0 评论
0 点赞
2021-03-18
apache 实验
配置文件位置 配置文件位置: 源码包安装: PREFIX/etc/httpd.conf(主配置文件) PREFIX/etc/extra/*.conf(子配置文件) rpm包安装: /etc/httpd/conf/httpd.conf 网页文件位置: 源码包安装: PREFIX/htdocs/ rpm包安装: /var/www/html/ 日志文件位置: 源码包安装: PREFIX/logs/ rpm包安装: /var/log/httpd/ 配置文件详解 注意:apache配置文件严格区分大小写 针对主机环境的基本配置参数 ServerRoot /usr/local/apache2 #apache主目录 Listen :80 #监听端口 LoadModule php7 #加载的相关模块 User Group #用户和组 ServerAdmin #管理员邮箱 ServerName #服务器名(没有域名解析时,使用临时解析。默认不开启) ErrorLog "logs/error_log #服务器错误日志 CustomLog "logs/access_log" common #访问记录日志 DirectoryIndex index.html index.php #默认网页文件名,优先级顺序 Include etc/extra/httpd-vhosts.conf #子配置文件中内容也会加载生效 主页目录及权限 DocumentRoot "/usr/local/apache2/htdocs" #网页文件存放目录(默认) <Directory "/usr/local/apache2/htdocs"> #定义指定目录的权限 Options Indexes FollowSymLinks None #没有任何额外权限 All #所有权限(除去MultiViews以外) Indexes #浏览权限(当此目录下没有默认网页文件时,显示目录内容) FollowSymLinks #准许软连接到其他目录 MultiViews #准许文件名泛匹配(需要手动开启模块才有效negotiation) AllowOverride None #定义是否允许目录下.htaccess文件中的权限生效 None #.htaccess中权限不生效 All #文件中所有权限都生效 AuthConfig #文件中,只有网页认证的权限生效 Require all granted(denied) #访问控制列表 </Directory> <IfModule dir_module> #此标签用来指定访问到指定目录时自动加载哪个页面文件 DirectoryIndex index.php index.html #可以写多个,但是有优先级之分 </IfModule> 实验 说明:以下实验均为源码安装apache yum 安装需要去 /usr/share/doc/httpd-2.4.6/ 配置文件,拷贝到 http.d 1. 目录别名 当 apache 接受请求时,在默认情况下会将 DocumentRoot目录中的文件送到客户端 如果想将某一不 在 DocumentRoot 目录中的文件共享到网站上 可以通过建立别名的方式将 URL 指向特定的目录 编辑主配置文件 # vim /usr/local/apache2/conf/httpd.conf Include etc/extra/httpd-autoindex.conf #去掉注释,开启调用子配置文件 编辑子配置文件 # vim /usr/local/apache2/conf/extra/httpd-autoindex.conf alias /icons/ "/usr/local/apache2/icons/" 结构:别名 "真实目录" #真实目录的结尾要有/,否则报错 <Directory "/usr/local/apache2/icons"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> 可以根据模板编写一个自己需要的目录别名 重启服务 2.用户认证 有时候,我们需要给一些特殊的访问。设置一个用户认证机制,增加安全 比如我们的个人网站,一般都是有一个管理后台的,虽然管理后台本身就有密码 但为了更加安全,可以再设置一层用户身 份认证 编辑子配置文件 # vim /usr/local/apache2/etc/httpd.conf 在需要进行登录认证的目录标签中加入如下配置: <Directory "/usr/local/apache2/htdocs/admin"> #声明被保护目录 Options Indexes FollowSymLinks AllowOverride All #开启权限认证文件.htaccess Require all granted </Directory> 在指定目录下创建权限文件 切换到需要进行登录认证的目录,创建 .htaccess 文件,并添加下面的内容 # vi .htaccess AuthName "Welcome to atguigu" #提示信息 AuthType basic #加密类型 AuthUserFile /usr/local/apache2/htdocs/admin/apache.passwd #密码文件,文件名自定义。(使用绝对路径) require valid-user #允许密码文件中所有用户访问 建立密码文件,加入允许访问用户(与系统用户无关) # htpasswd -c /usr/local/apache2/htdocs/admin/apache.passwd test1 -c 建立密码文件,只有添加第一个用户时,才能-c # htpasswd -m /usr/local/apache2/htdocs/admin/apache.passwd test2 -m 再添加更多用户时,使用-m 参数 注意: htpasswd 该命令是 httpd 的命令,需要绝对路径 、重启服务 3.虚拟主机 虚拟主机,也叫“网站空间”,就是把一台运行在互联网上的物理服务器划分成多个“虚拟”服务器。 虚拟主机的分类: 基于IP 基于端口 基于域名 实验准备: 域名解析:准备两个域名 www.sohu.com www.sina.com 网站主页目录规划 在/htdocs/目录下分别创建 sohu 和 sina 两个目录,并在新建目录内创建 index.html 文件(分别写不同内容) 实验步骤: 修改主配置文件开启文件关联 # vi /usr/local/apache2/etc/httpd.conf Include etc//extra/httpd-vhosts.conf #此行取消注释 编辑子配置文件,编写虚拟主机标签 # vi /usr/local/apache2/etc/extra/httpd-vhosts.conf 添加下方内容,有几个虚拟主机就写几组(添加之前先把原先存在的示例删除掉) <Directory "/usr/local/apache2/htdocs/sina"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> #目录权限标签根据需要自行添加 <VirtualHost 192.168.88.10:80> #虚拟主机标签 ServerAdmin webmaster@sina.com #管理员邮箱 DocumentRoot "/usr/local/apache2/htdocs/sina" #网站主目录 ServerName www.sina.com #完整域名 ErrorLog "logs/sina-error_log" #错误日志 CustomLog "logs/sina-access_log" common #访问日志 </VirtualHost> 重启服务,验证结果 4.域名跳转 一个站点难免会有多个域名,而多个域名总得有一个主次 比如我的网站可以用两个域名访问:www.sina.com和www.sohu.cn 但大家发现不管我用哪个域名访问,最终都会跳转到 www.sina.com 上 来 这个行为就叫做域名跳转,状态码:301 是永久跳转,302 是临时跳转 网站上一定要设置为 301, 这样对搜索引擎是比较友好的 实验条件: 虚拟主机能正常访问 打开重写配置模块 LoadModule rewrite_module modules/mod_rewrite.so #取消注释 实验步骤: 修改虚拟主机配置文件 # vi */extra/httpd-vhosts.conf <Directory "/usr/local/apache2/htdocs/sohu"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 创建规则匹配文件 # vi */.htaccess 在指定的网站目录下创建文件,并添加以下内容 RewriteEngine on # 开启rewrite功能 RewriteCond %{HTTP_HOST} ^www.sohu.com # 把以www.sina.com 开头的内容赋值给HTTP_HOST变量 RewriteRule ^(.*)$ http://www.sina.com/$1 [R=permanent,L] # ^(.*)$ 指代客户端要访问的资源 # $1 把 .* 所指代的内容赋值到$1变量中 # R=permanent 永久重定向 = 301 # L 指定该规则为最后一条生效的规则,以后的不再生效 重启服务并测试 5.实现https HTTPS(全称:Hypertext Transfer Protocol Secure,超文本传输安全协议),是以安全为目标的 HTTP 通道 简单讲是 HTTP 的安全版,即 HTTP 下加入 SSL 层,用于安全的 HTTP 数据传输。 这个系统被 内置于浏览器中,提供了身份验证与加密通讯方法。 准备工作: 检查 Apache 是否支持 SSL,检查相应模块是否安装,若安装则将模块启用 模块存放目录:/usr/local/apache2/modules 检查模块是否启用:apachectl -M CA 证书申请: a. openssl genrsa -out ca.key 1024 #建立服务器私钥,生成 RSA 密钥 b. openssl req -new -key ca.key -out atguigu.csr #需要依次输入国家,地区,城市,组织,组织单位,Email 等信息。最重要的是有一个 common name,可以写你的名字或者域名。如果为了 https 申请,这个必须和域名吻合,否则会引发浏览 器警报。生成的 csr 文件交给 CA 签名后形成服务端自己的证书 c. openssl x509 -req -days 365 -sha256 -in atguigu.csr -signkey ca.key -out atguigu.crt #使用 CA 服务器签发证书,设置证书的有效期等信息 注意 1:生成完秘钥和证书文件后,将文件存放在 Apache 的安装目录下的 cert 目录下 注意 2:在生产环境中必须要在 https 证书厂商注册(否则浏览器不识别) 配置文件修改: 调用 ssl 模块,并启用 ssl 独立配置文件 # vim /usr/local/apache2/etc/httpd.conf LoadModule ssl_module modules/mod_ssl.so #取消注释 Include etc/extra/httpd-ssl.conf #取消注释 修改 conf/extra/httpd-ssl.conf 配置文件,调用证书等文件 #添加 SSL 协议支持协议,去掉不安全的协议 SSLProtocol all -SSLv2 -SSLv3 #修改加密套件如下 SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM SSLHonorCipherOrder on #证书公钥配置(签字的) SSLCertificateFile cert/atguigu.crt #证书私钥配置 SSLCertificateKeyFile cert/ca.key 修改主配置文件,添加虚拟主机 <VirtualHost _default_:443> # DocumentRoot 目录位置要和 httpd.conf 里面的一致 DocumentRoot "/usr/local/apache2/htdocs" ServerName localhost:443 SSLCertificateFile cert/atguigu.crt SSLCertificateKeyFile cert/ca.key SSLCertificateChainFile cert/atguigu.crt </VirtualHost> 结果验证 # apachectl -t #检查配置文件语法 # apachectl restart #重启 apache,并测试是否可以使用 https 访问 报错提示:AH00526: Syntax error on line 78 of /usr/local/apache2/etc/extra/httpd-ssl.conf: SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?). 解决方案:要么不调用此模块,要么让调用的模块加载上 强制跳转 https: 有些时候为了安全,网站不允许使用 http 访问,仅允许使用 https 访问,目的是为了更加安全 在 http 部分的目录权限标签中添加一下内容 <Directory "/usr/local/apache2/htdocs"> …… RewriteEngine on #开启转发规则 RewriteCond %{SERVER_PORT} !^443$ #检查访问端口只要目标不是443的 RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [R=301,L] #全都使用https重新访问 </Directory> 在做后面实验时为了更加方便理解,我们可以先把 https 关闭掉 需要关闭:跳转&虚拟主机&ssl 配置文件调用 6.日志分割 我们每访问一次网站,那么就会记录若干条日志。如果日志不去管理,时间长了日志文件会越来越大 如何避免产生大的日志文件?其实 apache 有相关的配置 使日志按照我们的需求进行归档,比如每 天一个新日志,或者每小时一个新的日志 首先简单设置日志的路径名称 #vim /usr/local/apache2/etc/httpd.conf 编辑添加内容如下: ErrorLog "logs/error.log" CustomLog "logs/access.log" combined 指定了日志存放在/usr/local/apache2/logs 目录下分别为 error.log 和 access.log,combined 为日 志显示的格式,日志格式可以参考配置文件 httpd.conf 中格式的指定,如下: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common 设置apache 日志分割 同样编辑配置文件 httpd.conf ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/error_%Y%m%d.log 86400" CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/access_%Y%m%d.log 86400" combined 注意 1:以上仅为两条命令(一条错误日志,一条访问日志),路径太长写不开 注意 2:若开启了 https,则需要修改 http-ssl.conf 配置文件中的日志记录条目 xxxxxxxxxx 同样编辑配置文件 ErrorLog 是错误日志,CustomLog 是访问日志。|就是管道符,意思是把产生的日志交给 rotatelog 而这个工具就是 apache 自带的切割日志的工具。-l 的作用是校准时区为 UTC,也就是北京时间 86400,单位是秒,正好是一天,那么日志会每天切割一次 而最后面的 combined 为日志的 格式,在 httpd.conf 中有定义 7.不记录指定日志类型 如果一个网站访问量特别大,那么访问日志就会很多,但有一些访问日志我们其实是可以忽略掉的 比如网站的一些图片,还有 js、css 等静态对象。而这些文件的访问往往是巨量的 而且即使记录这 些日志也没有什么用,那么如何忽略不记录这些日志呢? 配置日志不记录图片的访问 # vim /usr/local/apache2/conf/httpd.conf 相关配置为: SetEnvIf Request_URI ".*\.gif$" image-request SetEnvIf Request_URI ".*\.jpg$" image-request SetEnvIf Request_URI ".*\.png$" image-request SetEnvIf Request_URI ".*\.bmp$" image-request SetEnvIf Request_URI ".*\.swf$" image-request SetEnvIf Request_URI ".*\.js$" image-request SetEnvIf Request_URI ".*\.css$" image-request CustomLog "|/usr/local ... _%Y%m%d.log 86400" combined env=!image-request 说明:在原来的访问日志配置基础上,增加了一些 image-request 的定义 比如把 gif、jpg、bmp、 swf、js、css 等结尾的全标记为 image-request 然后在配置日志后加一个标记 env=!image-request, 表示取反 8.配置静态缓存 所说的静态文件指的是图片、js、css 等文件,用户访问一个站点,其实大多数元素都是图片、js、 css 等 这些静态文件其实是会被客户端的浏览器缓存到本地电脑上的,目的就是为了下次再请求时 不再去服务器上下载 加快了速度,提高了用户体验。但这些静态文件总不能一直缓存,它总 有一些时效性,那么就得设置这个过期时间 Apache 配置静态缓存 # vim /usr/local/apache2/conf/httpd.conf <IfModule mod_expires.c> #此模块默认未启用,请手动启用 ExpiresActive on ExpiresByType image/gif "access plus 1 days" ExpiresByType image/jpeg "access plus 24 hours" ExpiresByType image/png "access plus 24 hours" ExpiresByType text/css "now plus 2 hours" ExpiresByType application/x-javascript "now plus 2 hours" ExpiresByType application/javascript "now plus 2 hours" ExpiresByType application/x-shockwave-flash "now plus 2 hours" ExpiresDefault "now plus 0 min" </IfModule> 或者使用 mod_headers 模块实现:该模块默认启用 <IfModule mod_headers.c> # htm,html,txt 类的文件缓存一个小时 <filesmatch "\.(html|htm|txt)$"> header set cache-control "max-age=3600" </filesmatch> # css, js, swf 类的文件缓存一个星期 <filesmatch "\.(css|js|swf)$"> header set cache-control "max-age=604800" </filesmatch> # jpg,gif,jpeg,png,ico,flv,pdf 等文件缓存一年 <filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$"> header set cache-control "max-age=29030400" </filesmatch> </IfModule> 说明:这里的时间单位可以 days、hours 甚至是 min,两种不同的方法, 上面使用的是 mod_expires, 而下面用的是 mod_headers,要想使用这些模块,必须要事先已经支持。 如何查看是否支持,使用命令: # /usr/local/apache2/bin/apachectl -M 重启服务并验证 验证: # curl -x127.0.0.1:80 'http://www.sohu.com/image/a.jpg' -I HTTP/1.1 200 OK Date: Wed, 26 Oct 2016 03:51:26 GMT Server: Apache/2.2.31 (Unix) PHP/5.5.38 Last-Modified: Tue, 31 May 2016 03:08:36 GMT ETag: "46891b-16b-5341ab0597500" Accept-Ranges: bytes Content-Length: 363 Cache-Control: max-age=86400 # 看这里 Expires: Thu, 27 Oct 2016 03:51:26 GMT Content-Type: image/jpg 9.禁止解析PHP 某个目录下禁止解析 PHP,这个很有作用,我们做网站安全的时候,这个用的很多, 比如某些目录可 以上传文件,为了避免上传的文件有木马,所以我们禁止这个目录下面的访问解析 PHP。 配置禁止解析 php: <Directory /usr/local/apache2/htdocs/data> php_admin_flag engine off <filesmatch "(.*)php"> Order deny,allow Deny from all </filesmatch> </Directory>
2021年03月18日
98 阅读
0 评论
1 点赞
2021-03-16
ansible 学习
ansible inventory ANSIBLE_CONFIG ansible.cfg 项目目录 ./ansible.cfg 当前用户的家目录 /etc/ansible/ansible.cfg [root@manager ~]# cat /etc/ansible/ansible.cfg inventory = /etc/ansible/hosts #主机列表配置文件 library = /usr/share/my_modules/ #库文件存放目录 remote_tmp = ~/.ansible/tmp #临时py文件存放在远程主机目录 local_tmp = ~/.ansible/tmp #本机的临时执行目录 forks = 5 #默认并发数 sudo_user = root #默认sudo用户 ask_sudo_pass = True #每次执行是否询问sudo的ssh密码 ask_pass = True #每次执行是否询问ssh密码 remote_port = 22 #远程主机端口 host_key_checking = False #跳过检查主机指纹 log_path = /var/log/ansible.log #ansible日志 [privilege_escalation] #如果是普通用户则需要配置提权 become=True become_method=sudo become_user=root become_ask_pass=False 生成密钥 生成密钥名字为dsa , 生成的时候会提示生成的密钥的路径以及密码,可以不输入,默认在 ~/.ssh/目录下 ssh-keygen -t dsa 将生成的公钥上传到指定的服务器中 ssh-copy-id -i ~/.ssh/id_dsa.pub user@192.168.0.201 创建工作目录 mkdir project1/ vim hosts [youto] 192.168.0.201 192.168.0.202 Ad-Hoc [ ping ] ansible youto -m ping -i hosts [查看磁盘信息] ansible youto -m shell -a "df -h" -i hosts command 不能支持管道符 playbook [][] 示例 检查yum语法 ansible-palaybook --syntax http.yml nfs.yaml nfs 的 配置文件 exports.j2 /data 192.168.0.201(rw) [共享文件夹] [允许访问主机] (权限) - hosts: 192.168.0.202 tasks: # yum 安装 nfs-utils - name: Install NFS Server yum: name=nfs-utils state=present # 分发 配置文件 - name: Configure NFS Server copy: src=./exports.j2 dest=/etc/exports backup=yes # 创建 组 - name: Create NFS Group group: name=nfss gid=666 # 创建 用户 - name: Create NFS User user: name=nfss uid=666 group=666 shell=/sbin/nologin create_home=no # 创建 共享文件夹 - name: Create NFS Data file: path=/data state=directory owner=nfss group=nfss recurse=yes # 开启 nfs 服务 - name: Service NFS Server service: name=nfs state=started enabled=yes - hosts: 192.168.0.201 tasks: # 创建 挂载目录 - name: Client Create NFS Data file: path=/nfs_tt state=directory # 挂载 - name: Client Mount NFS Server mount: src: 192.168.0.202:/data path: /nfs_tt fstype: nfs opts: defaults state: mounted 清空原来http软件 ansible youto -m yum -a "name=httpd state=absent" -i hosts http.yml tt.j2 (index.html 显示页面) httpd.conf.j2 (httpd 配置文件) - hosts: 192.168.0.202 tasks: yum install httpd # yum 安装 httpd - name: Install Httpd Server yum: name=httpd state=present # 修改 httd.conf 配置文件 - name: Configure Httpd Server copy: src=./httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf backup=yes # 设置 web 页面 - name: Configure Httpd WebSite copy: src=./tt.j2 dest=/var/www/html/tt.html owner=root group=root mode=644 # 开启 httpd 服务 - name: Service Httpd Server service: name=httpd state=started enabled=yes # 开启 firewalld - name: Service Firewalld Server service: name=firewalld state=started # 放行 9988 端口 - name: Configure Firewalld Server firewalld: zone=public port=9988/tcp permanent=yes immediate=yes state=enabled 卸载php71w yum list installed |grep php71w|awk '{print $1}'|xargs|sed -r 's#(.*)#yum remove -y \1#g'|bash lamp.yml wget http://static.kodcloud.com/update/download/kodexplorer4.40.zip - hosts: 192.168.0.201 tasks: # yum 安装 httpd php - name: Install Httpd PHP firewalld yum: name=httpd,php,php-pdo,php-mbstring,php-gd,firewalld state=present # 开启 httpd 服务 - name: Service Httpd Server service: name=httpd state=started # 开启防火墙 - name: Service Firewalld Server service: name=firewalld state=started # 放行 80 端口 - name: Configure Firewalld firewalld: port=80/tcp immediate=yes state=enabled # 获取 tt.php - name: Get Url index.php get_url: url: http://fj.xuliangwei.com/public/index.php dest: /var/www/html/tt.php # 获取并解压 kodexplorer4.40 - name: Copy Kod Cloud Code unarchive: src=./kodexplorer4.40.zip dest=/var/www/html/ mode=0777 - name: Chown Directory file: path=/var/www/html owner=apache group=apache recurse=yes 变量 定义变量 playbook的yaml文件中定义变量赋值 - hosts: all vars: #定义变量 file_name: bgx_yaml_vars tasks: - name: # {{ file_name }}引用上面定义的变量 file: path=/tmp/{{ file_name }} state=touch #playbook执行,在/tmp目录创建bgx_yaml_vars文件 [root@manager ~]# ansible-playbook f1.yml --extra-vars执行参数赋给变量 - hosts: all tasks: - name: Create New File file: path=/tmp/{{ file_name }} state=touch #playbook执行时传入file_name变量的参数,在/tmp目录创建bgx_extra-vars文件 [root@manager ~]# ansible-playbook f2.yml --extra-vars "file_name=bgx_extra-vars" 在文件中定义变量 在/etc/ansible/hosts主机组中定义,然后使用palybook进行调度该变量 [root@manager ~]# cat /etc/ansible/hosts [nfs] 10.0.0.20 [nfs:vars] file_name=bgx_filename 变量优先级 1.extra-vars外置传参的优先级最高 [所有执行的主机都生效] 2.定义在yml文件中的优先级其次 [所有执行的主机都生效] 3.hosts文件中定义的变量优先级最低 [当前主机组定义会生效] 变量注册 register关键字可以存储指定命令的输出结果到一个自定义的变量中 [root@manager ~]# cat f5.yml - hosts: all tasks: - name: shell: netstat -lntp register: System_Status - name: Get System Status debug: msg={{System_Status.stdout_lines}} when ( 判断 ) - hosts: all tasks: #检查httpd服务是否是活动的 - name: Check Httpd Server command: systemctl is-active httpd ignore_errors: yes register: check_httpd #如果check_httpd变量中的rc结果等于0,则执行重启httpd,否则跳过 - name: Httpd Restart service: name=httpd state=restarted when: check_httpd.rc == 0 when with_items ( 循环 ) - hosts: webserver tasks: - name: Create User user: name={{ item.name }} groups={{ item.groups }} state=present with_items: - { name: 'www', groups: 'bin'} - { name: 'test', groups: 'root'} with_items item handlers ( 触发器 ) - hosts: webserver #1.定义变量,在配置文件中调用 vars: http_port: 8881 #2.安装httpd服务 tasks: - name: Install Httpd Server yum: name=httpd state=present #3.使用template模板,引用上面vars定义的变量至配置文件中 - name: Configure Httpd Server template: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf notify: #调用名称为Restart Httpd Server的handlers(可以写多个) - Restart Httpd Server #4.启动Httpd服务 - name: Start Httpd Server service: name=httpd state=started enabled=yes #5.如果配置文件发生变化会调用该handlers下面的对应名称的task handlers: - name: Restart Httpd Server service: name=httpd state=restarted notify handlers include ( 包含) [root@ansible project1]# cat restart_httpd.yml #注意这是一个tasks所有没有play的任何信息 - name: Restart Httpd Server service: name=httpd state=restarted [root@ansible project1]# cat a_project.yml - hosts: webserver tasks: - name: A Project command command: echo "A" - name: Restart httpd include: restart_httpd.yml 导入一个完整的playbook文件 (play task) [root@m01 project1]# cat tasks_total.yml - import_playbook: ./tasks_1.yml - import_playbook: ./tasks_2.yml tags ( 标签) 指定执行某个tags标签 [root@m01 docs1]# ansible-playbook -i hosts nginx_php.yml -t "test_user" 忽略执行某个tags标签 [root@m01 docs1]# ansible-playbook -i hosts nginx_php.yml --skip-tags "test_user" igneore_errors ( 错误处理) 1.强制调用handlers - hosts: webserver force_handlers: yes #强制调用handlers tasks: - name: Touch File file: path=/tmp/bgx_handlers state=touch notify: Restart Httpd Server - name: Installed Packages yum: name=sb state=latest handlers: - name: Restart Httpd Server service: name=httpd state=restarted 2.关闭changed的状态(确定该tasks不会对被控端做任何的修改和变更.) - hosts: webserver tasks: - name: Installed Httpd Server yum: name=httpd state=present - name: Service Httpd Server service: name=httpd state=started - name: Check Httpd Server shell: ps aux|grep httpd register: check_httpd changed_when: false - name: OutPut Variables debug: msg: "{{ check_httpd.stdout_lines }}" 3.使用changed_when检查tasks任务返回的结果 - hosts: webserver tasks: - name: Installed Nginx Server yum: name=nginx state=present - name: Configure Nginx Server copy: src=./nginx.conf.j2 dest=/etc/nginx/nginx.conf notify: Restart Nginx Server - name: Check Nginx Configure Status command: /usr/sbin/nginx -t register: check_nginx changed_when: - ( check_nginx.stdout.find('successful')) - false - name: Service Nginx Server service: name=nginx state=started handlers: - name: Restart Nginx Server service: name=nginx state=restarted jinja语法 {% if EXPR %}...{% elif EXPR %}...{% endif%} 作为条件判断 --------------------------------------判断语句 {% if ansible_fqdn == "web01" %} echo "123" {% elif ansible_fqdn == "web02" %} echo "456" {% else %} echo "789" {% endif %} --------------------------------------循环语句 {% for i in EXPR %}...{% endfor%} 作为循环表达式 {% for i in range(1,10) %} server 172.16.1.{{i}}; {% endfor %} {# COMMENT #} 表示注释 Roles Roles基于一个已知的文件结构 tasks handlers templates ..... Roles小技巧: 创建roles目录结构,手动或使用ansible-galaxy init test roles 编写roles的功能,也就是tasks。 最后playbook引用roles编写好的tasks [root@m01 project2]# mkdir memcached/{tasks,handlers,templates,vars,files} -pv mkdir: 已创建目录 "memcached" mkdir: 已创建目录 "memcached/tasks" mkdir: 已创建目录 "memcached/handlers" mkdir: 已创建目录 "memcached/templates" mkdir: 已创建目录 "memcached/vars" mkdir: 已创建目录 "memcached/files" [root@m01 project2]# mkdir {nginx,php-fpm}/{tasks,handlers,templates} -p galaxy /root/.ansible/roles 1.使用roles创建Rsync服务, 目录结构如下 [root@m01 roles]# tree /etc/ansible/roles/ /etc/ansible/roles/ ├── hosts ├── rsync │ ├── files │ │ ├── rsyncd.conf │ │ └── rsync.passwd │ ├── handlers │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ └── vars ├── site.yml 2.定义roles主机清单 [root@m01 roles]# cat /etc/ansible/roles/hosts [backup] 172.16.1.41 3.指定backup主机组,执行那个roles [root@m01 roles]# cat /etc/ansible/roles/site.yml - hosts: backup remote_user: root roles: - rsync 4.查看rsync角色的tasks任务 [root@m01 roles]# cat /etc/ansible/roles/rsync/tasks/main.yml - name: Install Rsync Server yum: name=rsync state=present - name: Configure Rsync Server copy: src={{ item.src }} dest=/etc/{{ item.dest }} mode={{ item.mode }} with_items: - {src: "rsyncd.conf", dest: "rsyncd.conf", mode: "0644"} - {src: "rsync.passwd", dest: "rsync.passwd", mode: "0600"} notify: Restart Rsync Server - name: Start Rsync Server service: name=rsyncd state=started enabled=yes 5.查看rsync角色的handlers [root@m01 roles]# cat /etc/ansible/roles/rsync/handlers/main.yml - name: Restart Rsync Server service: name=rsyncd state=restarted 6.查看rsync角色的files目录 [root@m01 roles]# ll /etc/ansible/roles/rsync/files/ total 8 -rw-r--r-- 1 root root 322 Nov 16 18:49 rsyncd.conf -rw------- 1 root root 20 Nov 16 18:30 rsync.passwd 8.执行roles,使用-t指定执行测试rsync角色 [root@m01 roles]# ansible-playbook -i hosts -t rsync site.yml PLAY [backup] ******************************************************************************************** TASK [Gathering Facts] ******************************************************************************** ok: [172.16.1.41] TASK [backup : Install Rsync Server] *********************************************************************** ok: [172.16.1.41] TASK [backup : Configure Rsync Server] ********************************************************************* ok: [172.16.1.41] TASK [backup : Start Rsync Server] ************************************************************************* ok: [172.16.1.41] PLAY RECAP ***********************************************************************************=0 failed=0
2021年03月16日
84 阅读
0 评论
0 点赞
2021-03-16
网络服务
网络服务 网络服务管理 操作行为 CentOS 6 CentOS 7 启动指定服务 service [服务名] start systemctl start [服务名] 关闭指定服务 service [服务名] stop systemctl stop [服务名] 重启指导服务 service [服务名] restart systemctl restart [服务名] 查看指定服务状态 service [服务名] status systemctl status [服务名] 查看所有服务状态 service --status -all systemctl list-nuits 设置服务自启动 chkconfig [服务名] on systemctl enable [服务名] 设置服务不自启动 chkconfig [服务名] off systemctl disable [服务名] 查看所有服务自启动状态 chkconfig --list systemctl list-unit-files 网卡配置 [root@achapc ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none # 连接方式( dhcp/static ) DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=eth0 # 网卡名称 UUID=2045ca8b-6656-4597-a113-76091988dc38 DEVICE=eth0 # 设备名称 ONBOOT=yes # 是否开机加载 IPADDR=192.168.0.200 # IP地址 PREFIX=24 # 子网掩码 GATEWAY=192.168.0.2 # 网关 DNS1=210.28.144.8 # DNS IPV6_PRIVACY=no 注意:选项要大写,小写不生效 修改网卡名(Centos7) 1.修改网卡配置名文件 cp ifcfg-ens33 ifcfg-eth0 2.修改网卡配置文件内容 NAME=eth0 DEVICE=eth0 3.修改grub配置文件 GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0" 4.更新配置文件,并加载新的参数 grub2-mkconfig -o /boot/grub2/grub.cfg 5.重启 reboot TCP/IP 五层常见协议 应用层: FTP, HTTP, SMTP, Telnet, DNS 传输层: TCP, UDP 网络层: IP, ICMP,ARP 数据链路层: PPP 物理层:不常用 端口配置文件: /etc/service 端口号 服务名 功能 20/21 ftp 文件共享 22 ssh 安全远程管理 23 telent 不安全远程管理 25 smtp:简单邮件传输协议 发信 465 smtp(ssl) 发信 110 pop3:邮局1协议 收信 143 imap4 收信 993 imap4(ssl) 收信 80 www(http://) 网页访问 443 www(https://) 加密网页访问 3306 mysql 数据库连接端口 53 DNS 域名解析端口 SSH 用户密码验证 格式: ssh 用户名@IP地址 ssh root@192.168.0.200 -p 指定端口 密钥对登录验证 1.生成密钥对 ssh-keygen -t rsa -b 2048 2.将公钥上传至被控端 ssh-copy-id root@192.168.0.200 3.登录 ssh root@192.168.0.200 ssh 配置文件 位置: /ssh/sshd_confi 1.禁止使用密码登录 PasswordAuthentication no 2.禁止使用root远程登录 PermitRootLogin no 3.修改默认端口 Port 2233 4.限制ssh监听IP ListenAddress 192.168.0.201 scp 格式:scp 本地文件 用户@服务器IP:目录 scp /root/acha.txt root@192.168.0.200:/tmp -P 指定端口 sftp 格式:sftp 用户@服务器IP sftp root@192.168.0.200 -oProt=端口 TCP Wrappers TCP_ Wrapper 通过控制两个配置文件实现访问控制 允许 /etc/hosts. allow 阻止 /etc/hosts. deny 配置文件编写规则: service list@host: client list service_ list: 是程序(服务)的列表,可以是多个,多个时,使用,隔开 host: 设置允许或禁止他人从自己的哪个网口进入。这一项不写,就代表全部 client_ list: 是访问者的地址,如果需要控制的用户较多,可以使用空格或,隔开 格式如下: 基于IP地址: 192.168.0.1 192.168.0. 基于主机名:youto .youto.com 基于网络/掩码:192.168.0.0/24 内置ACL:ALL(所有主机) , LOCAL(本地主机) DHCP DHCP介绍 准备实验环境 防护关闭: 1)关闭防火墙 2)关闭 SElinux 3)关闭VMware 虚拟网络编辑器DHCP功能 DHCP 相关信息 软件名: dhcp # DHCP服务软件包 dhcp-common # DHCP命令软件包(默认安装) 服务名: dhcpd # DHCP 服务名 dhcrelay #DHCP 中继服务名 端口号: udp 67 # 作为客服端的目标端口,接受客服端的请求DHCP udp 68 # 作为服务器的源端口,用来向客户端回复数据包 配置文件: dhcpd /etc/dhcp/dhcpd.conf # 此配置文件默认为空,需找模板文件重新生成 dhcpd.conf.sample /usr/share/doc/dhcp-4. . /dhcpd.con.sample # DHCP模板配置文件 dhcrelay /etc/sysconfig/dhcrelay # 中继配置文件 DHCP 配置文件详解 DHCP 基本功能实验 安装 DHCP yum install -y dhcp 生成配置文件 cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 修改配置文件 注释所有subnet,修改最后一个subnet subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.101 192.168.0.110; default-lease-time 600; max-lease-time 7200; } 重启服务 systemctl start dhcpd 监控DHCP日志文件 tail -f /var/log/messages 重启客户机网卡 ifdown eth0;ifup eth0 固定地址分配 获取客户端 mac 地址 arp -a 修改 /etc/dhcp/dhcpd.conf 文件 host fantasia { hardware ethernet 00:0c:29:66:f5:d8; # mac 地址 fixed-address 192.168.0.123; # ip 地址 } 重启DHCP服务 systemctl start dhcpd 重启客户机网卡验证IP ifdown eth0;ifup eth0 超级作用域 设置DHCP服务器单臂路由需要的子网卡 cp -a ifcfg-eth0 ifcfg-eth0:0 #生成网卡,修改网卡名和IP地址 开启路由转发 vim /etc/sysctl.conf net.ipv4.ip_forward=1 #开启路由转发 sysctl -p # 刷新内核参数配置文件 修改 /etc/dhcp/dhcpd.conf 文件 shared-network 0-100 { subnet 192.168.0.0 netmask 255.255.255.0 { option routers 192.168.0.200; range 192.168.0.121 192.168.0.121; } subnet 192.168.100.0 netmask 255.255.255.0 { option routers 192.168.100.200; range 192.168.100.131 192.168.100.141; } } 重启 DHCP 服务 systemctl restart dhcpd 重启客户机网卡,查看验证ip地址 ifdown eth0;ifup eth0 DHCP 中继 DNS DNS 介绍 域名 (Domain Name):简称 域名、网域,是由一串用点分隔的名字组成的 Internet 上某一台计算机 或计算机组的名称, 用于在数据传输时标识计算机的电子方位。具有独一无二,不可重复的特性。 DNS : 域名系统( Domain Name System) , 域名解析就是 域名到 IP 地址的转换过程 正向解析: 域名 --> IP地址 反向解析: IP地址 --> 域名 域名的组成和分类 常见格式:www.youto.club 完整格式:www.youto.club. . 根域,可以省略不写 com 定级域,由ICANN组织指定和管理 分类: 国家地区域名: cn(中国) 、 hk(香港) 、 sg(新加坡) 等 通用顶级域名: com(商业机构) 、 org(非营利组织) 、 edu(教育机构) 等 新通用顶级域名: red(红色、 热情) 、 top(顶级、 高端) 等 youto: 二级域(注册域),可由个人或组织申请注册 www: 三级域(子域) ,服务器网站名代表 主机名: s1.www.youto.club. 中的 s1 就是主机名, 一般用来表示具体某一台主机 com.cn属于“二级域名” ,是 cn 顶级域的子域 4.域名解析过程 客户机首先查看查找本地 hosts 文件,如果有则返回,否则进行下一步 客户机查看本地缓存,是否存在本条目的缓存,如果有则直接返回, 否则进行下一步。 将请求转发给指向的 DNS 服务器。 查看域名是否本地解析, 是则本地解析返回, 否则进行下一步。 本地 DNS 服务器首先在缓存中查找,有则返回,无则进行下一步。 向全球 13 个根域服务器发起 DNS 请求,根域返回 org 域的地址列表。 使用某一个 org 域的 IP 地址,发起 DNS 请求, org 域返回 kernel 域服务器地址列表。 使用某一个 kernel 域 IP 地址,发起 DNS 请求, kernel 域返回 www.kernel.org 主机的 IP 地址,本 地 DNS 服务收到后,返回给客户机,并在本地 DNS 服务器保存一份 5.DNS 软件信息 软件名称:bind 服务名称:named 软件端口: UDP 53 数据通信(域名解析) TCP 53 数据同步(主从同步) 配置文件: 主配置文件: /etc/named.conf(服务器运行参数) 区域配置文件: /etc/named.rfc1912.zones(服务器解析的区域配置,正反向区域定义信息) 数据配置文件: /var/named/xx.xx(主机名和 IP 地址的对应解析关系,及主从同步信息) DNS 服务搭建 先关闭服务器和客户机上的防火墙和 SELinux 软件安装 yum -y install bind 配置主配置文件(/etc/named.conf) 配置区域文件(/etc/named.rfc1912.zones) 注:先对区域文件进行备份, 删除多余的模板,只留下一个正向和一个反向(反向修改时,网络 位的反写格式, 如 192.168.100.2-->100.168.192.) 配置数据文件/var/named/ A. 先复制生成正向解析文件和反向解析文件 B. 编辑正向解析文件(注意域名结尾的 “.” ) C. 编辑反向解析文件(注意域名结尾的 “.” ) 重启 DNS 服务 service named restart 客户端测试 在网卡配置文件中添加 DNS 服务器的地址,然后用 nslookup 测试 DNS 主从服务器 实验目的:减轻主服务器的压力 先关闭服务器和客户机上的防火墙和 SELinux 实验准备: 一台主服务器、一台从服务器、一台测试机 搭建过程: 搭建主服务器步骤(同上,不截图了) : a. 安装 bind 软件 b. 主配置文件的修改 c. 区域配置文件的修改 d. 配置数据文件 正向数据文件 反向数据文件(可选做) e. 启动 named 服务 注意: 主 DNS 的区域配置文件中 allow-updata 参数添加从服务器 IP 地址。 搭建从服务器步骤: a. 安装 bind 软件 b. 修改主配置文件/etc/named.conf c. 配置区域文件(/etc/named.rfc1912.zones) 注意:从配置文件的类型需要修改为 slave,并且需要填写主服务器的地址,如下 type slave; masters { 192.168.0.10; }; #大括号两侧留有空格 文件保存位置修改为 file “slaves/atguigu.localhost” ; d. 重启服务 e. 在测试机上填写从服务器的 IP,并使用 nslookup 测试 DNS 缓存服务器 实验作用:加快解析速度, 提高工作效率 先关闭服务器和客户机上的防火墙和 SELinux 实验软件:dnsmasq 配置文件:/etc/dnsmasq.conf domain=域名 #需要解析的域名 server=ip #主 DNS 服务器 IP cache-size=15000 #声明缓存条数 重启服务: service dnsmasq restart 测试效果: 在测试机上填写 DNS 缓存服务器的 ip 地址 智能 DNS (分离解析) 实验原理: DNS 分离解析即将相同域名解析为不同的 IP 地址。现实网络中一些网站为了让用户有更好 的体验效果解析速度更快,就把来自不同运营商的用户解析到相对应的服务器这样就大大提升了访问速度 实验环境: 一台内网测试机(单网卡) 一台网关+DNS(双网卡) 一台外网测试机(单网卡) 一台 web 服务器(双网卡) 先关闭服务器和客户机上的防火墙和 SELinux 实验步骤: 安装 bind 软件 内核配置文件开启路由转发,修改/etc/sysctl.conf 修改主配置文件/etc/named.conf 生成自己定义的区域文件(反向解析省略掉了) cp – a named.rfc1912.zones lan cp – a named.rfc1912.zones wan 配置数据文件 配置内网的正向解析文件 配置外网的正向解析文件 重启服务 service named restart 效果测试 内网客户端网卡配置 将 dns 和网关都指为网关服务器的内网口地址 外网客户端网卡配置 将 dns 和网关都指为网关服务器的外网口地址 VSFTP VSFTP介绍 概述:VSFTP是一个基于 GPL发布的类 Unix 系统上使用的 FTP 服务器软件 安全性 vsftp 程序的运行者一般是普通用户,降低了相对应进程的权限 任何需要执行较高权限的指令都需要上层程序许可 ftp 所需要使用的绝大多数命令都被整合到了 vsftp 中,基本不需要系统额外提供命令 拥有 chroot 功能,可以改变用户的根目录,限制用户只能在自己的家目录 VSFTP 连接类型 控制连接( 持续连接) --> TCP 21( 命令信道) --> 用户收发FTP命令 数据连接( 按需连接) --> TCP 20( 数据信道) --> 用于上传下载数据 工作模式 Port模式 (主动) Passive 模式 (被动) 传输模式 Binary模式:不对数据进行任何处理,适合进行可执行文件、压缩文件、图片等 ASCII模式: 进行文本传输时,自动适应目标操作系统的结束符, 如回车符等 切换方式: 在ftp>提示符下输入ascii即转换到ACSII方式,输入bin,即转换到Binary方式 软件信息 服务端软件名: vsftpd 客户端软件名: ftp 服务名: vsftpd 端口号: 20、 21、指定范围内随机端口 配置文件: /etc/vsftpd/vsftpd.conf 登录验证方式 匿名用户验证: 用户账号名称: ftp或anonymous 用户账号密码: 无密码 工作目录: /var/ftp 默认权限: 默认可下载不可上传,上传权限由两部分组成(主配置文件和文件系统) 本地用户验证: 用户账号名称:本地用户(/etc/passwd) 用户账号密码: 用户密码(/etc/shadow) 工作目录:登录用户的宿主目录 权限:最大权限(drwx------) 虚拟(virtual)用户验证: 1. 创建虚拟用户用来代替本地用户,减少本地用户曝光率 2. 使用本地用户作为虚拟用户的映射用户,为虚拟用户提供工作目录和权限控制 3. 能够设置严格的权限(为每一个用户生成单独的配置文件) 匿名用户实验 tip:关闭服务器和客户机的防火墙和SELinux 目录:/etc/vsftpd/vsftpd.conf 选项 anonymous_enable=YES 启用匿名访问 anon_umask=022 匿名用户所上传文件的权限掩码 anon_root=/var/ftp 匿名用户的 FTP 根目录 anon_upload_enable=YES 允许上传文件 anon_mkdir_write_enable=YES 允许创建目录 anon_other_write_enable=YES 开放其他写入权(删除、覆盖、重命名) anon_max_rate=0 限制最大传输速率(0 为不限速, 单位: bytes/秒) 实验需求与流程: 注意: 在客户端登录后,默认情况下是可以下载的,但不能上传 实现可以上传 a. anon_upload_enable=YES b. 在/var/ftp/下创建上传目录 c. 修改上传目录的权限或所有者,让匿名用户有写入权限 实现创建目录和文件其他操作 non_mkdir_write_enable=YES 允许创建目录 anon_other_write_enable=YES 开放其他写入权(删除、覆盖、重命名) 用户进入某个文件夹时,弹出相应的说明 a. 在对应目录下创建 .message 文件,并写入相应内容 b. 确认dirmessage_enable=YES是否启用 c. 尝试却换目录查看效果(同一次登录仅提示一次) 实现上传的文件可下载 默认情况下开放上传权限后,上传的文件是无法被下载的,因为文件的其他人位置没有r权限 设置anon_umask=022,可以让上传的文件其他人位置拥有r权限, 然后才能被其他人下载 本地用户实验 目录:/etc/vsftpd/vsftpd.conf 选项 local_enable=YES 是否启用本地系统用户 local_umask=022 本地用户所上传文件的权限掩码 local_root=/var/ftp 设置本地用户的 FTP 根目录 chroot_local_user=YES 是否将用户禁锢在主目录 local_max_rate=0 限制最大传输速率 ftpd_banner=Welcome to blah FTP service 用户登录时显示的欢迎信息 userlist_enable=YES & userlist_deny=YES 禁止user_list 文件中出现的用户名登录 FTP userlist_enable=YES & userlist_deny=NO 仅允许user_list 文件中出现的用户名登录 FTP 禁止 /etc/vsftpd/ftpusers 文件中出现的用户名登录 FTP,权限比 user_list 更高,即时生效 实验需求与流程: 服务端需要创建用户并设置密码(所创建的用户,不需要登录操作系统,仅用来登录VSFTP) useradd -s /sbin/nologin username 将所有用户禁锢在自己的家目录下 注: 默认没有禁锢用户时,客户端登录后可以随意切换目录,查看文件所在位置和文件名 chroot_local_user=YES 开启用户家目录限制, 限制所有用户不能随便切换目录 将部分用户禁锢在自己的家目录下 chroot_list_enable=YES 开启白名单功能,允许白名单中的用户随意切换目录 chroot_list_file=/etc/vsftpd/chroot_list 白名单文件所在位置(需自己创建) 配置文件: /etc/vsftpd/ftpusers 所有写入此文件内的用户名都不允许登录ftp,立刻生效。 修改被动模式数据传输使用端口 pasv_enable=YES pasv_min_port=30000 pasv_max_port=35000 虚拟用户实验 建立 FTP 的虚拟用户的用户数据库文件(在/etc/vsftpd) vim vsftpd.user 该文件名可以随便定义, 文件内容格式: 奇数行用户, 偶数行密码 db_load -T -t hash -f vsftpd.user vsftpd.db 将用户密码的存放文本转化为数据库类型, 并使用 hash 加密 chmod 600 vsftpd.db 修改文件权限为 600,保证其安全性 创建 FTP 虚拟用户的映射用户, 并制定其用户家目录 useradd -d /var/ftproot -s /sbin/nologin virtual 创建 virtual 用户作为 ftp 的虚拟用户的映射用户 建立支持虚拟用户的 PAM 认证文件,添加虚拟用户支持 cp – a /etc/pam.d/vsftpd /etc/pam.d/vsftpd.pam 使用模板生成自己的认证配置文件, 方便一会调用 编辑新生成的文件 vsftpd.pam (清空原来内容, 添加下列两行) auth required pam_userdb.so db=/etc/vsftpd/vsftpd acco unt required pam_userdb.so db=/etc/vsftpd/vsftpd 在 vsftpd.conf 文件中添加支持配置 修改: pam_service_name=vsftpd.pam 添加: guest_enable=YES guest_username=virtual user_config_dir=/etc/vsftpd/dir 为虚拟用户建立独立的配置文件,启动服务并测试 注:做虚拟用户配置文件设置时,将主配置文件中自定义的匿名用户相关设置注释掉。 用户可以上传: anon_upload_enable=YES #允许上传文件 用户可以创建目录或文件: anon_mkdir_write_enable=YES #允许创建目录 用户可以修改文件名: anon_upload_enable=YES #允许上传文件(为了覆盖开启的) anon_other_write_enable=YES #允许重名和删除文件、覆盖 注:给映射用户的家目录 设置 o+r 让虚拟用户有读权限
2021年03月16日
121 阅读
0 评论
0 点赞
1
2