運維工作中經常用到的一些知識總結(二)
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
- 1
- 2
- 3
有序列表
- 列表1
- 列表1.1
- 列表1.2
- 列表2
- 列表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
[root@www ~]# tar zxvf DenyHosts-2.6.tar.gz
[root@www ~]# cd DenyHosts-2.6
安裝部署
[root@www DenyHosts-2.6]# yum install python -y
[root@www DenyHosts-2.6]# python setup.py install
準備好默認的配置文件
[root@www DenyHosts-2.6]# cd /usr/share/denyhosts/
[root@www denyhosts]# cp denyhosts.cfg-dist denyhosts.cfg
[root@www 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
[root@BOARD 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 :password@localhost
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
運維工作中經常用到的一些知識總結(二)