运维常用操作

运维常用操作

Author:woodman

v1.0

1 配置权限,编辑 /etc/sudo 文件

#visudo
    Cmnd_Alias WEBMASTER = /srv/nginx/sbin/nginx, /srv/php/sbin/php-fpm, !/srv/mysql/bin/*
    www localhost = NETWORKING, SERVICES, DELEGATING, PROCESSES, WEBMASTER
    Cmnd_Alias Database = /usr/bin/mysqldump, /srv/mysql/bin/mysql, /u01/oracle/10.x.x/bin/sqlplus
    mysql localhost = NETWORKING, SERVICES, DELEGATING, PROCESSES, WEBMASTER, Database
 
#实现ADMINS组具备root权限,但是无法修改root和组成员的密码
    User_Alias ADMINS = gaogao,woodman,liukengkeng
    root    ALL=(ALL)       ALL
    ADMINS  ALL=(ALL)     NOPASSWD:  ALL , ! /usr/bin/passwd root
    liukengkeng ALL=(ALL)       ! /usr/bin/passwd woodman , ! /usr/bin/passwd gaogao
    woodman ALL=(ALL)       ! /usr/bin/passwd liukengkeng , ! /usr/bin/passwd gaogao
    gaogao ALL=(ALL)      ! /usr/bin/passwd woodman , ! /usr/bin/passwd liukengkeng

2  配置服务,编辑/etc/ssh/sshd_config 

#超时
    ClientAliveInterval 300
    ClientAliveCountMax 0
#禁止root登录
    PermitRootLogin no

#禁止密码登录

PasswordAuthentication no

#禁止端口转发
    AllowTcpForwarding no
默认配置
禁用   .rhosts 文件:#IgnoreRhosts yes
禁用基于主机的认证:#HostbasedAuthentication no
禁用空密码:#PermitEmptyPasswords no
记录日志:#LogLevel INFO
-------------------------
#service sshd restart
#systemctl restart sshd.service
#生成密钥,不设置密码则连续回车,默认rsa加密。存放在~/.ssh/
#ssh-keygen 
#将公钥发送到目标主机,并重名命为~/.ssh/authorized_keys
#ssh-copy-id user@IP

3 /etc/motd  和 /etc/issue 

/etc/issue文件的使用方法与/etc/motd文件相差不大,它们的主要区别在于:当一个网络用户或通过串口登录系统上时,
/etc/issue的文件内容显示在login提示符之前,而/etc/motd内容显示在用户成功登录系统之后。
(1)清空登录提示
echo "" > /etc/issue.net
echo "" > /etc/issue
(2)编辑警告信息,据说国外因为提示含有 welcome 结果败诉了。
#vim /etc/motd
==============Wrrning==============
Without the owner's prior written consent,        
no decompiling or reverse-engineering shall be allowed
 
*Notice: 
This is a private communication system.
Unauthorized access or use may lead to prosecution.
==================================
 
以下是解释:
 
\d    本地端时间的日期
\l    显示第几个终端机的接口;
\m    显示硬件的等级(i386/i486/i586/i686....)
\n    显示主机的网络名称
\o    显示 domain name
\r    操作系统的版本 (类似 uname-r) 
\t    显示本地端时间的时间
\s    操作系统的名称
 
 
4 定制HISTORY
vim  /etc/profile.d/history.sh
#HISTSIZE=500
HISTFILESIZE=2000
HISTTIMEFORMAT="%F %T "
#HISTCONTROL=ignoredups  //合并重复
#HISTCONTROL=erasedups   //删除重复
#HISTCONTROL=ignorespac #command //不记住命令
HISTIGNORE="ls:cd /etc:pwd:history"  //忽略命令

5 /etc/security/limits.conf

limits.conf 配置 limits.conf 文件实际是 Linux PAM(插入式认证模块)中 pam_limits.so 的配置文件,而且只针对于单个会话。
nobody soft nofile 102400
nobody hard nofile 102400
 
为什么会设置为nobody用户呢?因为root用户启动系统后web 服务器会使用nobody用户创建子进程,
socket连接实际上是nobody用户在处理;root 仅仅是守护父进程。
mysql soft nofile 10240
mysql hard nofile 10240
 
针对 mysql 做限制
 
关闭写磁盘I/O功能
对于某些文件没必要记录文件的访问时间,由其是在高并发的IO密集操作的环境下,通过两个参数可以实现noatime,nodiratime减少不必要的系统IO资源。
编辑/etc/fstab 添加 noatime,nodiratime 参数
 
/dev/sdb1    /www          ext4    noatime,nodiratime        0 0
 

6 PAM 插件认证加固配置

/etc/pam.d/su
/etc/pam.d/sshd
 

7 锁定关键配置,一般在部署完应用后设置。

#关闭一下配置文件的写权限(包括root)
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab /etc/sudoers
#改变命令名称已仿黑客篡改。
mv /usr/bin/chattr /usr/bin/woodman

8 加密启动选项仿单用户登录

grub-md5-crypt 
    #Password: 123456
    #Retype password: 123456
    $1$cVb95/$6t3Rg2hBpE8tr5F9pKr4s.
vim /etc/grub.conf 
    hiddenmenu下增加,即加在 splashimage 和title 之间
password --md5  $1$cVb95/$6t3Rg2hBpE8tr5F9pKr4s.
 

9 必备软件

(1)安装epel源
#rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-lastest.noarch.rpm 
#rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
#(如果报错则)epel.repo中注释所有的"#mirrorlist"使用"baseurl"并且"enabled=1"。
#sed -r -i 's@#(baseurl)@\1@g' epel.repo
# sed -i 's@mirrorlist@#&@g' epel.repo
#yum clean all 
#yum repolist
(2)
# yum -y install wget tree sysstat vim expect ntpdate mtr tracerout extundelete lsof dmidecode
#sysstat 包含多个工具,有:sar,iostat,mpstat,sadf,/usr/lib64/sa/sadc。
#expect 包含mkpasswd工具,用于生成随机密码。
#生成密码长度12,大写3个,特殊2个,默认2个数字,剩下的全部是小写字母
#mkpasswd -l 12 -C 3 -s 2 -d 2
#mtr ,做路由图表分析, -n 不解析主机,-c 发送多少个数据包
#extundelete 和 lsof 可分开使用,也可以配合用。
#在误伤或者需要的时候恢复已删除数据。
#dmidecode -t typecode 
#获取有关硬件方面的信息
#其输出的信息包括 BIOS、系统、主板、处理器、内存、缓存等等。

10 常用的周期服务

#crontab -e
*/20 * * * * /usr/sbin/ntpdate cn.pool.ntp.org #同步时钟
0 0 * * *  find /var/spool/postfix/maildrop/ -type f |xargs rm -f #清楚系统内部邮件
 
posted @ 2016-12-24 00:31  山城木头人  阅读(261)  评论(0)    收藏  举报