19 Sep 2015
yum install -y ./examrhce-0.0.1-1.el7.x86_64.rpm
lab examrhce setup
lab examrhce grade
vi /etc/sysconfig/selinux *********************************** SELINUX=enforcing ***********************************
setenforce 1
getenforce
systemctl mask iptables systemctl mask ip6tables systemctl mask ebtables
systemctl enable firewalld
systemctl start firewalld
#允许ssh服务 firewall-cmd --permanent --add-service=ssh #禁止特定域(ip段)访问ssh firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=172.17.0.0/24 service name=ssh reject'
firewall-cmd --reload
firewall-cmd --list-all
nm-connection-editor
nmcli con reload nmcli con down eth0 nmcli con up eth0
ip a ping ip address (互相ping一下)
ip link
nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'
nmcli con mod team0 ipv4.addresses '192.168.0.101/24'
nmcli con mod team0 ipv4.method manual
nmcli con add type team-slave con-name team0-port1 ifname eth1 master team0 nmcli con add type team-slave con-name team0-port2 ifname eth2 master team0
teamdctl team0 state ping 192.168.0.254
vim /etc/bashrc ******************************** alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz' ********************************
which qstat
systemctl enable postfix
systemctl restart postfix
postconf -e "inet_interfaces = loopback-only" 配置网卡 postconf -e "myorigin = example.com" 配置邮件来源 postconf -e "relayhost = [classroom.example.com]" 配置邮件下一跳地址 postconf -e "mydestination = " 为空表示不接受任何外网邮件 postconf -e "local_transport = error: local delivery disabled" postconf -e "mynetworks = 127.0.0.1/8, [::1]/128" 允许本地ip来访问
systemctl restart postfix
mail -s "server0 null client" student@classroom.example.com null client test 此处为输入内容 . 此处为输入内容 EOT
浏览器输入”classroom.exam.com/cgi-bin/recevied_mail”检查邮件
#如果没有发送成功,可以检查发送队列
mailq
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=172.25.0.0/24 forward-port port=5423 protocol=tcp to-port=80'
firewall-cmd --reload
yum install samba samba-client -y
mkdir /common useradd -s /sbin/nologin rob useradd -s /sbin/nologin brian
smbpasswd -a rob smbpasswd -a brian
chown :brian /common/
chmod 2775 /common/
ll -d /common/
semanage fcontext -a -t samba_share_t '/common(/.*)?'
restorecon -vFR /common/
vim /etc/samba/smb.conf ***************************************** #修改 workgroup = STAFF security = user #增加 [common] path=/common write list = brian browseable = yes hosts allow = 172.25.0. # 172网段 *****************************************
systemctl enable smb nmb
systemctl start smb nmb
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
yum install cifs-utils -y
mkdir /mnt/multiuser
echo 'username=brian' > /root/smb-multiuser.txt # 名称自定义 echo 'password=redhat' >> /root/smb-multiuser.txt # 注意配置文件名称保持一致
vi /etc/fstab ********************************** //server0.example.com/common /mnt/multiuser cifs credentials=/root/smb-multiuser.txt,multiuser,sec=ntlmssp 0 0 **********************************
mount -a # 把fstab里的所有挂载配置挂载 df -h # 检查挂载结果
id rob id brian
su - brian cifscreds add server0 Password: #检查brian用户是否可读写 su - rob cifscreds add server0 Password: #检查rob用户是否是只读
# 安装nfs软件包 yum install -y nfs-utils systemctl enable nfs-server systemctl start nfs-server
# 创建未加密共享目录 mkdir /public chown nfsnobody /public # 创建kerberos加密共享目录 mkdir /protected/project -p chown ldapuser0:ldapuser0 /protected/project
# exports配置 vi /etc/exports ************************************** /protected *.example.com(rw,sec=krb5p) # krb的必须放首位,并且域要和其他的规则一致 /public *.example.com(ro) ************************************** exportfs -r exportfs # nfs全局配置 vi /etc/sysconfig/nfs *********************************** RPCNFSDRAGS="-V 4.2" ***********************************
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --reload
wget -O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/server0.keytab
systemctl enable nfs-secure-server.service
systemctl start nfs-secure-server.serivce
mkdir /mnt/nfsmount mkdir /mnt/nfssecure
vi /etc/fstab ***************************************** #增加 server0.example.com:/public /mnt/nfsmount nfs defaults 0 0 server0.example.com:/protected /mnt/nfssecure nfs defaults,sec=krb5p 0 0 *****************************************
wget -O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/desktop0.keytab
systemctl enable nfs-secure
systemctl start nfs-secure
mount -a df -h
ssh ldapuser0@localhost # password是:kerberos # cd进/mnt/nfssecure/project做个文件检查下是否可读写
yum install -y httpd
systemctl enable httpd
systemctl start httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
vi /etc/httpd/conf.d/vhost-server0.conf ******************************************* <VirtualHost *:80> ServerName server0.example.com DocumentRoot "/var/www/html" CustomLog "logs/server0_vhost_log" combined <Directory "/var/www/html"> <RequireAll> Require all granted Require not host .my133t.org </RequireAll> </Directory> </VirtualHost> *******************************************
wget -O /var/www/html/index.html http://classroom.example.com/materials/station.html
systemctl restart httpd lsof -i:80 -n
yum install -y mod_ssl
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
wget -O /etc/pki/tls/certs/server0.crt http://classroom.example.com/pub/tls/certs/server0.crt wget -O /etc/pki/tls/private/server0.key http://classroom.example.com/pub/tls/private/server0.key wget -O /etc/pki/tls/certs/example-ca.crt http://classroom.example.com/pub/example-ca.crt
vi /etc/httpd/conf.d/ssl.conf ************************************************* #在<VirtualHost _default_:443>块下添加 ServerName server0.example.com DocumentRoot "/var/www/html" #修改如下证书路径 SSLCertificateFile /etc/pki/tls/certs/server0.crt SSLCertificateKeyFile /etc/pki/tls/private/server0.key SSLCACertificateFile /etc/pki/tls/certs/example-ca.crt #添加访问控制 </Directory "/var/www/html"> <RequireAll> Require all granted Require not host .my133t.org </RequireAll> </Directory> ************************************************* systemctl restart httpd
yum install -y httpd systemctl enable httpd systemctl start httpd firewall-cmd --permanent --add-service=http firewall-cmd --reload
vi /etc/httpd/conf.d/vhost-www0.conf ******************************************* <VirtualHost *:80> ServerName www0.example.com DocumentRoot "/var/www/virtual" CustomLog "logs/www0_virtual_log" combined <Directory "/var/www/virtual"> Require all granted </Directory> </VirtualHost> *******************************************
mkdir -p /var/www/virtual wget -O /var/www/virtual/index.html http://classroom.example.com/materials/www.html
semanage fcontext -a -t httpd_sys_content_t '/var/www/virtual(/.*)?'
restorecon -vFR /var/www/virtual
useradd floyd setfacl -m user:floyd:rwx /var/www/virtual
mkdir /var/www/virtual/private wget -O /var/www/virtual/private/index.html http://classroom.example.com/materials/private.html
vi /etc/httpd/conf.d/vhost-www0.conf ********************************************* #在<VirtualHost>中添加如下代码 <Directory "/var/www/html/private"> Require all denied Require local </Directory> *********************************************
systemctl restart httpd
curl http://www0.example.com/private
yum install -y mod-wsgi
mkdir /var/www/webapp
wget -O /var/www/webapp/webinfo.wsgi http://classroom.example.com/materials/webinfo.wsgi
semanage fcontext -a -t httpd_sys_content_t '/var/www/webapp(/.*)?'
restorecon -vFR /var/www/webapp
vi /etc/httpd/conf.d/vhost-webapp0.conf ******************************************** Listen 8908 <VirtualHost *:8908> ServerName webapp0.example.com DocumentRoot "/var/www/webapp" CustomLog "logs/webapp0_vhost_log" combined <Directory "/var/www/webapp"> Require all granted </Directory> WSGIScriptAlias / /var/www/webapp/webinfo.wsgi </VirtualHost> ********************************************
semanage port -a -t http_port_t -p tcp 8908 firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=172.25.0.0/24 port port=8908 protocol=tcp accept' firewall-cmd --reload
systemctl restart httpd
curl http://webapp0.example.com:8908
vi /root/foo.sh ********************************** #!/bin/bash case $1 in redhat) echo "fedora" ;; fedora) echo "redhat" ;; *) echo "/root/foo.sh redhat|fedora" ;; esac **********************************
chmod 755 /root/foo.sh
vi /root/batchusers *********************************************** #!/bin/bash if [ $-eq 1 ];then if [ -f "$1" ];then while read username;do useradd -s /bin/false $username &> /dev/null done < $1 else echo "Input file not found" exit 1 fi else echo "Usage: /root/batchusers userfile" exit 2 fi ***********************************************
chmod 755 /root/batchusers
wget -O /root/userlist http://classroom.example.com/materials/userlist
/root/batchusers /root/userlist
tail -4 /etc/passwd
yum install targetcli -y
systemctl enable target
systemctl start target
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
lsblk fdisk /dev/sdb Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +4G Partition 1 of type Linux and of size 4 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. #把分区创建为物理卷 pvcreate /dev/sdb1 #创建虚拟卷组 vgcreate iSCSI_vg /dev/sdb1 #创建虚拟卷 lvcreate -n iscsi_store -L 3G iSCSI_vg #查看结果 lvs
targetcli > cd /scsi > create iqn.2014-11.com.example:server0 > iqn.2014-11.com.example:server0/tgp1/portals create 172.25.0.11 3260 #绑定一个后端卷 > cd / > backstores/block create name=server0.iscsi_store dev=/dev/iSCSI_vg/iscsi_store > iscsi/iqn.2014-11.com.example:server0/tpg1/luns create /backstores/block/server0.iscsi_store #做访问控制 > iscsi/iqn.2014-11.com.example:server0/tpg1/acls create iqn.2014-11.com.example:desktop0 #关闭密码验证的访问控制 > iscsi/iqn.2014-11.com.example:server0/tpg1/ set attribute authentication=0 #使上面的访问控制生效 > iscsi/iqn.2014-11.com.example:server0/tpg1/ set attribute generate_node_acls=0 #保存并退出 > saveconfig > exit #### 5) 查看设置结果 targetcli > ls
yum install iscsi-initiator-utils -y
vi /etc/iscsi/initiatorname.iscsi ************************************ InitiatorName=iqn.2014-11.com.example:desktop0 ************************************
systemctl enable iscsi
systemctl start iscsi
iscsiadm -m discovery -t st -p 172.25.0.11 iscsiadm -m node -l
lsblk # 会发现多了一个硬盘 fdisk /dev/sdc n p 1 +2100M w #格式化 mkfs.ext4 /dev/sdc1 #### 6) 挂载iscsi硬盘分区 mkdir /mnt/data #获取分区UUID blkid /dev/sdc1 vi /etc/fstab ************************************************** UUID_HERE /mnt/data ext4 defaults,_netdev 0 0 ************************************************** mount -a #检查挂载结果 df -h
yum groupinstall mariadb mariadb-client -y
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation 密码是空 y 输入新密码 再次输入新密码 y y y y
wget -O /root/mariadb.dump http://classroom.example.com/content/courses/rhce/rhel7.0/materials/mariadb/mariadb.dump
mysql -uroot -p > create database legacy; > use legacy; > source /root/mariadb.dump > show tables;show databases;
> grant select on legacy.* to mary@'localhost' identified by 'mary_password'; > grant select,insert,update,delete on legacy.* to legacy@'localhost' identified by 'legacy_password'; > grant select on legacy.* to report@'localhost' identified by 'report_password';
mysql -uroot -p > use legacy; > desc product; > select id from product where name='RT-AC68U'; > select count(product.id) from category,product where category.name='Servers' and category.id=product.id_category;