只开启应用服务,并关闭所有不相关的系统服务.提高性能.
- #!/usr/bin/perl -w
- use warnings;
- use strict;
- my %myservices = (
- "atd" => "1",
- "crond" => "1",
- "netfs" => "1",
- "autofs" => "1",
- "sshd" => "1",
- "syslog" => "1",
- "network" => "1",
- "nfslock" => "1",
- );
- #my($sec,$min,$hour,$day,$mon,$year)=localtime;
- #my $year=$year+1900;
- chomp(my $date=`date +%F`);
- my $file="/tmp/.chkconfig.$date.log";
- unlink $file;
- sub Getservices {
- my $cmd="chkconfig --list";
- my @chklist = `$cmd`;
- my @services;
- # print "@chklist\n";
- foreach (@chklist){
- chomp;
- s/^\s+//;
- s/\s+$//;
- next if $_ eq '';
- my @num=split /\s+/,$_;
- next if scalar@num !=8;
- push (@services,(split /\s+/,$_)[0]);
- }
- return @services;
- }
- sub savelog {
- `/bin/echo "@_">>$file`;
- }
- sub Changeservices {
- my $off=0;
- foreach (Getservices()){
- next if $myservices{$_};
- print " $_ at all level to off\n";
- my $cmd="chkconfig --level 0123456 $_ off";
- `$cmd`;
- $off++;
- savelog($cmd);
- }
- foreach (keys %myservices){
- my $cmd="chkconfig --level 35 $_ on";
- `$cmd`;
- print " $_ at 35 level to on\n";
- savelog($cmd);
- }
- printf "OFF_services: %d\nON_services: %d\nALL_services: %d\n",$off,scalar(keys %myservices),scalar Getservices();
- }
- &Changeservices();