您的位置:首页 > 运维架构 > Linux

一键完成RHCE6.0上午的考试

2016-01-07 17:00 459 查看
#!/sbin/bash

#

#initial envirment

#variable define

IPADDR=192.168.0.12

NETMASK=255.255.255.0

HOSTNAME=station.domain12

DOMAIN='.example.com'

SERVER=instructor$DOMAIN

NAME_SERVER=192.168.0.1

GATEWAY=192.168.0.1

#Checking Selinux status

if [[ $(getenforce) == Disabled ]]

        then

        echo "Selinus is disabled, no aciton is requird!!"

        else

        echo > /etc/sysconfig/selinux

        echo "SELINUX=disabled" >>/etc/sysconfig/selinux

        echo "SELINUXTYPE=targeted" >>/etc/sysconfig/selinux

        echo "Selinux status has been chenged successful!"

fi

#Setup ip address and dns

DEVICE=eth0

IFPATH=/etc/sysconfig/network-scripts

cat $IFPATH/ifcfg-$DEVICE >> /tmp/ifcfg-$DEVICE.bak

echo > $IFPATH/ifcfg-$DEVICE

echo "DEVICE=$DEVICE" >>$IFPATH/ifcfg-$DEVICE

echo "BOOTPROTO=static" >>$IFPATH/ifcfg-$DEVICE

echo "IPADDR=$IPADDR" >>$IFPATH/ifcfg-$DEVICE

echo "NETMASK=$NATMASK" >>$IFPATH/ifcfg-$DEVICE

echo "GATEWAY=$GATEWAY" >>$IFPATH/ifcfg-$DEVICE

echo "DNS1=$NAME_SERVER" >>$IFPATH/ifcfg-$DEVICE

echo "ONBOOT=yes" >>$IFPATH/ifcfg-$DEVICE

chkconfig NetworkManager off

service NetworkManager stop

service network restart

#hostname setup

NETWORK_FILE=/etc/sysconfig/network

echo > $NETWORK_FILE

echo "NETWORKING=yes" >> $NETWORK_FILE

echo "HOSTNANE=$HOSTNAME$DOMAIN" >> $NETWORK_FILE

echo "192.168.0.12 $HOSTNAME$DOMAIN" >> /etc/hosts

hostname $HOSTNAME$DOMAIN

echo "Hostname change succesfull, you may need to religin to aviod it."

#Add u
4000
sers

groupadd admin

useradd -G admin harry

useradd -G admin natasha

useradd -s /sbin/nologin tom

#setpassword for users

echo "harry"|passwd harry --stdin

echo "natasha"|passwd natasha --stdin

echo "User and passwd setup successful."

#Create dir for group admin with sepecial permssion.

mkdir /home/admins

chgrp admin /home/admins

chmod g+ws /home/admins

chmod o-rx /home/admins

#Create cron task for root

echo "23 14 * * * /bin/echo hello" > /root/cron.txt

crontab -e <<EOF

:r /root/cron.txt

:wq

EOF

chkconfig crond on

crontab -l

#

#find file and copy to another folder

mkdir /opt/dir

find / -user harry -exec cp -a {} /opt/dir \;

ls -l /opt/dir

#find key word from file and output to another one.

grep root /etc/passwd >/tmp/testfile

#add more swaps for linux

fdisk -cu /dev/sda <<EOF

n

e

4

+2G

n

l

t

5

82

p

wq

EOF

partx -a /dev/sda

mkswap /dev/sda5

echo "$(blkid /dev/sda5|awk '{print $2}') swap swap defauts 0 0" >> /etc/fstab

swapon -a

#User file swap, please un comment blow

#dd if=/dev/zero of=/tmp/swap.img bs=1M count=2000

#mkswap /tmp/swap.img

#echo "$(blkid /tmp/swap.img|awk '{print $2}') swap swap defauts 0 0" >> /etc/fstab

#swapon -a

swapon -s

free -m

#create with specified id and passwd

useradd -u 1234 alex

echo "alex111" |passwd alex --stdin

#Install ftpserver

REPO=/etc/yum.repos.d/rhel6.repo

echo "[Base]" > $REPO

echo "name=base" >> $REPO

echo "baseurl=http://$SERVER/rhel6" >> $REPO

echo "enabled=1" >> $REPO

echo "gpgcheck=0" >> $REPO

yum makecache

yum install vsftpd -y

chkconfig vsftpd on

service vsftpd start

#setup a simple http server

yum install httpd -y

chkconfig httpd on

cd /var/www/html

wget http://$SERVER/pub/example.html
mv example.html index.html

service httpd restart

#LDAP with autofs

yum groupinstall 'Directory Client' -y

service ntpd stop

ntpdate $SERVER

#cat /root/ntpconf.txt >/etc/ntp.conf

echo "$SERVER iburst">>/etc/ntp.conf

chkconfig ntpd on

service ntpd restart

vi /etc/sysconfig/authconfig <<EOF

:%s/USERLDAPAUTH=no/USERLDAPAUTH=yes/g

:wq

EOF

echo "URI ldap://$SERVER/" >/etc/openldap/ldap.conf

echo "BASE dc=example, dc=com" >>/etc/openldap/ldap.conf

echo "TLS_CACERTDIR /etc/openldap/cacerts" >> /etc/openldap/ldap.conf

cd /etc/openldap/cacerts

wget http://$SERVER/certs/cacert.pem
#cat /root/sssd.txt > /etc/sssd/sssd.conf

#service start sssd

authconfig --enableldap --enableldapauth --enablemkhomedir --ldapserver=instructor.example.com --ldapbasedn="dc=example,dc=com" --update

yum install autofs -y

echo "/lhome /etc/auto.ldap" >> /etc/auto.master

echo "* -fstype=nfs,rw $SERVER:/lhome/&"> /etc/auto.ldap

yum install nfs-utils -y

chkconfig autofs on

service autofs restart
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux RHCE 操作系统