运维工作中经常用到的一些知识总结(二)

接上篇:
http://blog.51cto.com/bobo365/2125121

31、screen:

screen -S xxx
screen -r xxx
screen -D  -r <session-id>

-D -r 先踢掉前一用户,再登陆。

screen -X -S 31978 quit

32、Markdown基本语法

一级标题

二级标题

三级标题

四级标题

五级标题
六级标题

无序列表1

  • 列表1

    • 列表1.1
    • 列表1.2
  • 列表2
  • 列表3

无序列表2

  • 1

    • 1

      • 1
      • 2
      • 3
    • 2
    • 3
  • 2
  • 3

有序列表

  1. 列表1

    1. 列表1.1
    2. 列表1.2
  2. 列表2
  3. 列表3

引用

FBI WARNING 一级引用

> Warning here. 二级引用

>> Warning here too.三级引用

To-Do List

  • [x] 已完成项目1

    • [x] 已完成事项1
    • [x] 已完成事项2
  • [ ] 待办事项1
  • [ ] 待办事项2

表格

Item Value Qty
Comput 1600$ 5
phone 12$ 20

插入图片

插入链接

I am a url of Baidu.

粗体和斜体

This is 粗体
This is 斜体

分割线

第一段



第二段



第三段

代码框代码高亮

    while true:
        do echo "hehe";
    done

    for i in a b c
        do echo "Hehe2";
    done

代码框模式二

while true:<br/>do echo "hehe";<br/>done

33、docker复制文件至容器及进入容器:

docker cp /home/ok/mini.ok.com.cn.key 6f82d5f30f14:/root
wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;
echo "[ -f ~/.bashrc_docker ] && . ~/.bashrc_docker" >> ~/.bashrc; source ~/.bashrc

34、DenyHosts:

wget http://sourceforge.net/projects/denyhosts/files/denyhosts/2.6/DenyHosts-2.6.tar.gz

[[email protected] ~]# tar zxvf DenyHosts-2.6.tar.gz
[[email protected] ~]# cd DenyHosts-2.6
安装部署
[[email protected] DenyHosts-2.6]# yum install python -y
[[email protected] DenyHosts-2.6]# python setup.py install
准备好默认的配置文件
[[email protected] DenyHosts-2.6]# cd /usr/share/denyhosts/
[[email protected] denyhosts]# cp denyhosts.cfg-dist denyhosts.cfg
[[email protected] denyhosts]# cp daemon-control-dist daemon-control
编辑配置文件denyhosts.cfg

chown root daemon-control #添加root权限
chmod 700 daemon-control #修改为可执行文件
ln -s /usr/share/denyhosts/daemon-control /etc/init.d #对daemon-control进行软连接,方便管理

安装到这一步就完成了。
/etc/init.d/daemon-control start #启动denyhosts
chkconfig daemon-control on #将denghosts设成开机启动

35、代理:

export http_proxy=http://192.168.2.133:3188

[[email protected] squid]# grep -vE "#|^$" squid.conf

acl SSL_ports port 443
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3188
coredump_dir /var/spool/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

36、postgresql:

yum install https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-2.noarch.rpm
yum install postgresql93-server
/usr/pgsql-9.3/bin/postgresql93-setup initdb
systemctl enable postgresql-9.3
systemctl start postgresql-9.3

37、linux中临时禁用用户

a.在/etc/passwd文件中找到禁用用户所在行,在该行首添加

/etc/passwd
#user1:x:500:500::/home/user1:/bin/bash

b.在/etc/shadow 文件中找到禁用用户所在行,在第二个字段(密码加密字段)前添加!或者*

/etc/shadow 一般该文为只读属性,不建议修改
user1:*$1$HsYY3Xxn$iDxguvDB8vsSeM3VjxKbq/:14817:0:99999:7:::

c、锁定账号 newuser1

#usermod -L newuser1

d、解除对 newuser1 的锁定

#usermod -U newuser1

38、新机配置:

a、更换yum源:

cp -R /etc/yum.repos.d /etc/yum.repos.d.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum -y install epel-release
yum clean all
yum makecache 

b、文件数限制

ulimit -SHn 655350

more /etc/security/limits.conf

*       soft    nofile  655350
*       hard    nofile  655350
*       soft    nproc   655350
*       hard    nproc   655350

c、系统参数优化

more /etc/sysctl.conf

vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_announce=2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.conf.lo.arp_announce=2
kernel.sem = 250 32000 100 10000
fs.file-max = 655536
vm.overcommit_memory = 1
net.core.somaxconn = 1024
net.ipv4.tcp_fin_timeout = 30
sysctl -p

d、selinux

查看SELinux状态:

A、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态

SELinux status: enabled

B、getenforce ##也可以用这个命令检查

关闭SELinux:
临时关闭(不用重启机器):
setenforce 0 ##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可

e、安装常用软件

yum install -y net-tools vim lrzsz tree screen lsof tcpdump wget ntpdate

f、 更改时区

cp /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

39、VUE:

nuxt build
nuxt start
npm run generate

40、redis导入导出

导出,密码前面要加一个冒号

redis-dump -u :[email protected]:6379 > redis.json

导入

cat redis.json | redis-load -u :[email protected]
yum install ruby rubygems ruby-devel openssl*

gem sources --remove https://rubygems.org/
gem sources -a https://gems.ruby-china.org/
gem sources -u 

gem sources -l
gem update --system
gem install redis-dump

gem install -n /usr/local/bin redis-dump --pre
pod setup

41、内核版本升级:

yum uodate kernel

42、安全加固:

检查项: 系统crontab权限设置
加固建议: 依次执行:

rm -f /etc/cron.deny
rm -f /etc/at.deny
touch /etc/cron.allow
touch /etc/at.allow
chmod 0600 /etc/cron.allow
chmod 0600 /etc/at.allow

检查项: 禁止主机进行路由转发
加固建议: 执行

sysctl -w net.ipv4.ip_forward=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.ip_forward=0,不存在则添加
检查项: 禁止转发ICMP重定向报文
加固建议: 执行

sysctl -w net.ipv4.conf.all.send_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.all.send_redirects=0,不存在则添加
检查项: 禁止转发ICMP重定向报文
加固建议: 执行

sysctl -w net.ipv4.conf.default.send_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.default.send_redirects=0,不存在则添加
检查项: 禁止包含源路由的ip包
加固建议: 执行

sysctl -w net.ipv4.conf.default.accept_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.default.accept_redirects=0,不存在则添加
检查项: 禁止转发安全ICMP重定向报文
加固建议: 执行

sysctl -w net.ipv4.conf.all.secure_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.all.secure_redirects=0,不存在则添加
检查项: 禁止转发安全ICMP重定向报文
加固建议: 执行

sysctl -w net.ipv4.conf.default.secure_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.default.secure_redirects=0,不存在则添加
检查项: 启用反转地址路径过滤
加固建议: 执行

sysctl -w net.ipv4.conf.all.rp_filter=1,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.all.rp_filter=1,不存在则添加
检查项: 启用反转地址路径过滤
加固建议: 执行

sysctl -w net.ipv4.conf.default.rp_filter=1,

再查看/etc/sysctl.conf中是否存在net.ipv4.conf.default.rp_filter=1,不存在则添加
检查项: 禁止ipv6路由广播
加固建议: 执行

sysctl -w net.ipv6.conf.all.accept_ra=0,

再查看/etc/sysctl.conf中是否存在net.ipv6.conf.all.accept_ra=0,不存在则添加
检查项: 禁止ipv6路由广播
加固建议: 执行

sysctl -w net.ipv6.conf.default.accept_ra=0,

再查看/etc/sysctl.conf中是否存在net.ipv6.conf.default.accept_ra=0,不存在则添加
检查项: 禁止ipv6路由重定向
加固建议: 执行

sysctl -w net.ipv6.conf.all.accept_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv6.conf.all.accept_redirects=0,不存在则添加
检查项: 禁止ipv6路由重定向
加固建议: 执行

sysctl -w net.ipv6.conf.default.accept_redirects=0,

再查看/etc/sysctl.conf中是否存在net.ipv6.conf.default.accept_redirects=0,不存在则添加
检查项: 密码授权新密码与老密码不能重复
加固建议: 在/etc/pam.d/password-auth中添加:password sufficient pam_unix.so remember=3 ,remember的值表示此次设置密码与过去3次不同
检查项: 系统授权新密码与老密码不能重复
加固建议: 在/etc/pam.d/system-auth中添加:password sufficient pam_unix.so remember=3 ,remember的值表示此次设置密码与过去3次不同
检查项: rsyslog日志文件权限配置
加固建议: 在/etc/rsyslog.conf中添加:$FileCreateMode 0640
检查项: SSHD强制使用V2安全协议
加固建议: 在/etc/ssh/sshd_config中取消Protocol注释符号#
检查项: SSHD仅记录ssh用户登录活动
加固建议: 在/etc/ssh/sshd_config中取消LogLevel INFO注释符号#
检查项: SSHD仅记录ssh用户登录活动
加固建议: 在/etc/ssh/sshd_config中取消MaxAuthTries注释符号#,设置自定义最大密码尝试失败次数
检查项: 清理主机远程登录历史主机记录
加固建议: 在/etc/ssh/sshd_config中取消IgnoreRhosts yes注释符号#
检查项: 禁止主机认证登录
加固建议: 在/etc/ssh/sshd_config中取消HostbasedAuthentication no注释符号#
检查项: 禁止空密码用户登录
加固建议: 在/etc/ssh/sshd_config中取消PermitEmptyPasswords no注释符号#
检查项: 禁止用户修改环境变量
加固建议: 在/etc/ssh/sshd_config中取消PermitUserEnvironment no注释符号#
检查项: 设置输入密码间隔时间
加固建议: 在/etc/ssh/sshd_config中取消LoginGraceTime前注释符,同时设置输入密码时间间隔秒数
检查项: 设置用户密码最小长度
加固建议: 在/etc/security/pwquality.conf中取消minlen注释符号#,同时设置最小密码长度建议10位以上
检查项: 设置用户密码数字位数
加固建议: 在/etc/security/pwquality.conf中取消dcredit注释符号#,同时设置为负数建议-1最少包含1位数字
检查项: 设置用户密码大写字母位数
加固建议: 在/etc/security/pwquality.conf中取消ucredit注释符号#,同时设置为负数建议-1最少包含1位大写字母
检查项: 设置用户密码小写字母位数
加固建议: 在/etc/security/pwquality.conf中取消lcredit注释符号#,同时设置为负数建议-1最少包含1位小写字母
检查项: 设置用户密码特殊字符位数
加固建议: 在/etc/security/pwquality.conf中取消ocredit注释符号#,同时设置为负数建议-1最少包含1位特殊字符
检查项: 强制密码失效时间
加固建议: 在/etc/login.defs 设置强制密码失效时间,建议值365
检查项: 密码修改最小间隔时间
加固建议: 在/etc/login.defs 设置密码修改最小间隔时间,建议值7
检查项: 设置有密码账户不活动最大时间
加固建议: 使用如下命令设置有密码账户不活动最大时间值:useradd -D -f 90,建议值90
检查项: 检查/boot/grub2/grub.cfg文件ACL属性
加固建议: 执行:

chmod 0600 /boot/grub2/grub.cfg

检查项: 检查/etc/crontab文件ACL属性
加固建议: 执行:

chmod 0600 /etc/crontab

检查项: 检查/etc/cron.hourly文件ACL属性
加固建议: 执行:

chmod 0600 /etc/cron.hourly

检查项: 检查/etc/cron.daily文件ACL属性
加固建议: 执行:

chmod 0600 /etc/cron.daily

检查项: 检查/etc/cron.weekly 文件ACL属性
加固建议: 执行:

chmod 0600 /etc/cron.weekly

检查项: 检查/etc/cron.monthly 文件ACL属性
加固建议: 执行:

chmod 0600 /etc/cron.monthly

检查项: 检查/etc/cron.d 文件ACL属性
加固建议: 执行:

chmod 0600 /etc/cron.d

43、不允许root直接登录的服务器用普通用户免密登录:

跳板机操作:

su - ok
ssh-copy-id -i /home/ok/.ssh/id_rsa.pub -p 20002 [email protected]

44、BIGDATA加固:

systemctl stop firewalld
systemctl disable firewalld
yum list all iptables*
yum install iptablesyum install iptables-services.x86_64 -y
systemctl start iptables
systemctl status iptables
systemctl enable iptables
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -s 192.168.2.133/32 -j ACCEPT
iptables -A INPUT -s 192.168.2.134/32 -j ACCEPT
iptables -A INPUT -s 192.168.2.135/32 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dport 18089,18080,18090,60010,50070,10002,8888,8889,11000,8088,19888 -s 192.168.2.136/32 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dport 18089,18080,18090,60010,50070,10002,8888,8889,11000,8088,19888 -s 0.0.0.0/0 -j DROP
service iptables save
iptables -A INPUT -s 10.0.0.0/8 -j ACCEPT
iptables -A INPUT -p tcp -i eth1 --dport 3306 -s 192.168.2.136/32 -j ACCEPT
iptables -A INPUT -p tcp -i eth1 --dport 3306 -s 0.0.0.0/0 -j DROP

45、xtrabackup:

全量备份:

innobackupex --defaults-file=/etc/percona-server.conf.d/mysqld.cnf --user=root --password=ok --socket=/var/lib/mysql/mysql.sock /data/backup/

全量恢复:

方法1:

systemctl stop mysql
rm -rf /opt/percona-server/mysql/*
innobackupex --defaults-file=/etc/percona-server.conf.d/mysqld.cnf --copy-back --rsync /data/backup/2018-01-04_17-11-19/
chown -R mysql.mysql /opt/percona-server/mysql/
systemctl start mysql

方法2:

innobackupex --apply-log --use-memory=32M /data/backup/2018-01-04_17-11-19/
systemctl stop mysql
cp -a /data/backup/2018-01-04_17-11-19/* /opt/percona-server/mysql/
chown -R mysql.mysql /opt/percona-server/mysql/
systemctl start mysql

增量备份:

首先全量备份:

innobackupex --defaults-file=/etc/percona-server.conf.d/mysqld.cnf --user=root --password=ok --socket=/var/lib/mysql/mysql.sock --no-timestamp /data/backup/base_full
innobackupex --defaults-file=/etc/percona-server.conf.d/mysqld.cnf --user=root --password=ok --socket=/var/lib/mysql/mysql.sock --no-timestamp --incremental-basedir=/data/backup/base_full --incremental /data/backup/one_inc

全量恢复准备:

systemctl stop mysql
innobackupex --apply-log --use-memory=32M /data/backup/base_full/
innobackupex --apply-log --use-memory=32M --redo-only --incremental-dir=/data/backup/one_inc /data/backup/base_full/

正式恢复:

\cp -R /data/backup/base_full/* /opt/percona-server/mysql/
chown -R mysql.mysql /opt/percona-server/mysql/
systemctl start mysql

47、修改用户UID:

usermod -u 91 tomcat
groupmod -g 91 tomcat

原文地址:http://blog.51cto.com/bobo365/2125138

时间: 2024-07-30 09:11:15

运维工作中经常用到的一些知识总结(二)的相关文章

运维工作中经常用到的一些知识总结(一)

在日常运维工作中,会有一些知识使用频率较高,以下为个人在工作中常用的一些操作,没有做详细的分类,排版比较凌乱.有需要的同学们可以参考,希望能有所帮助. 1.查看当前系统所以变量 sysctl -a 2.修改Centos7 网卡为eth install centos 7 按 tab键,增加: net.ifnames=0 biosdevname=0 3.yum删除软件 yum erase $(rpm -qa|grep java) yum erase $(rpm -qa|grep zabbix) 4.

运维工作中经常用到的一些知识总结(四)

接上篇:http://blog.51cto.com/bobo365/2125159 54.rabbitMQ http://blog.csdn.net/lishaojun0115/article/details/53152255 用户管理 用户管理包括增加用户,删除用户,查看用户列表,修改用户密码. (1) 新增一个用户 rabbitmqctl add_user Username Password (2) 删除一个用户 rabbitmqctl delete_user Username (3) 修改

日常运维工作中如何确保你的linux操作系统安全

在现在这个世道中,Linux操作系统的安全是十分重要的.但是,你得知道怎么干.一个简单反恶意程序软件是远远不够的,你需要采取其它措施来协同工作.下面是日常运维工作中常用的几种Linux安全的策略方法. 1. 使用SELinux SELinux是用来对Linux进行安全加固的,有了它,用户和管理员们就可以对访问控制进行更多控制.SELinux为访问控制添加了更细的颗粒度控制.与仅可以指定谁可以读.写或执行一个文件的权限不同的是,SELinux可以让你指定谁可以删除链接.只能追加.移动一个文件之类的

Linux 运维工作中的经典应用ansible(批量管理)

一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) 1.安装ansible(需要bese epel 2种源) wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum

运维工作中的bootstraping之PXE自动安装操作系统

运维工作纵向来看主要分为三个方向: 1.BootStraping:主要做的是操作系统的安装与配置,包括Bare Metal(pxe,cobbler)和Virtual Machine(image files). 2.Configuration:主要使用运维工具如puppet(rubby研发).saltstack(python研发).ansible.chef.cfengine等自动化运维工具做应用程序做批量部署与配置. 3.Command and Conrol:主要使用自动化运维工具发送命令或指令实

关于运维工作中的问题和自学方面的浅谈

我是一个运维工程师,因为主要侧重系统监控方面,所以相对来讲知道的东西面上比较广,但是实际根据业务的需要,或者某类产品的特定要求,又必须深入的了解内部原理. 所以我们经常要快速的掌握大量的知识,信息,已经相关的标准或者协议. 那么我们要有各自的自学方法. 工作前几年的时候,我主要是通过去图书馆,查阅相关资料,或者做知识储备,那时还是从事的web站点管理的工作,通过查阅大量的书籍后,我迷茫了,没有了方向.但是这种泡图书馆的方法,使我确实获得了很多知识. 后来我转到运维这块,当时的维护工作,主要是针对

运维工作中常见错误总结分享

作为一个小运维,要时刻学习.总结.最近收集了一下常见的错误,和大家分享一下.希望对大家有用 一.卸载的时候出现的错误 umount /dev/nb1 device is busy 解决:找到是什么进程使得他busy,用 lsof /dev/nb1 . kill掉那个进程,然后重新umount即可. 二.GD2编译的时候出现的错误 The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL' Libtool library used b

运维工作中的一些标准流程

一.服务器上架标准 因为我们的服务器有专门的人员在IDC进行上架,下面几项我们按照标准来进行提供. 要指定配置的IP,子网掩码,网关: 安装系统的版本(CentOS 7.6 mini),比如分区如下: 目录 大小 boot 200MB swap 8GB / 剩余大小 二.系统初始化标准 系统的初始化标准流程使用一键初始化脚本,主要包含一下几个参数的设定: 1.配置服务器时区 rm -f /etc/localtime cp /usr/share/zoneinfo/Asia/Shanghai /et

IT运维服务中的一些工作思路探索(二)

1.  重承诺.讲计划 (1)重承诺:对于用户的任何承诺,包括:服务的目标与级别要求.提供的资源或方案.应给予的回复等,运维人员都应在约定的时间内.按约定的要求予以提供或实现,严格履行承诺.确因特殊原因导致无法履行时,应提前和用户进行说明和解释,获得对方的谅解:并提出补救措施,以尽量接近当初的承诺. (2)讲计划:工作计划是整个运维工作的龙头,工作计划依据公司要求及对用户的承诺而制定,各项运维服务将围绕计划展开.决策管理系统的运维工作以主动服务为主,所有的主动服务类工作都可以提前策划.中烟信息的