常用操作

常用操作

标签: 常用  

常用操作

删除最近2天日志

find ./ -mtime +2 -name "*.log" -exec rm -rf {} \;

重启应用

su admin
cd /opt/tomcat
ps -ef|grep `pwd`| grep -v 'grep' | awk '{print $2}' |xargs kill -9
rm -rf ./work/* ./temp/*
./bin/startup.sh && tail -f ./logs/catalina.out

安装nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx -y sudo systemctl enable nginx.service

查看排名

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head  查看cpu排名
du -sk *|sort -n|cut -f2|xargs -d '\n' du -sh   查看磁盘排名

批量替换

sed -i "s/10.32.144.192/10.32.166.38/g" `grep 10.32.144.192 -rl /opt/xkmictest/` 

磁盘修复

fsck -y /dev/sdb

日志处理

find /opt/goaccess-logs/nbapache4.34/ -type f -name "access_log-2017_06*"  | xargs -i cat {} >> /opt/nb201706apache.txt

cat nb201706apache.txt|awk '{print $1}'|grep -v '10.'|grep -v '192.'|sort -n|uniq -c|sort -n |wc -l

awk -v total=0 '{total+=$10}END{print total/1024/1024/1024} ' nb201708apache.txt 

计算磁盘最多分区

df -h|awk '{print $5}'|grep -v 'Use'|awk -F '%' '{print $1}'|awk 'BEGIN {max = 0} {if ($1+0 > max+0) max=$1} END {print "Max=", max}' 

fdisk -l|grep 'GB'|grep '/dev/emcpowera'|awk '{print $3}' || grep 'GB'|grep '/dev/xvd'|awk '{print $3}'

安装jdk

yum install java-1.8.0-openjdk* -y
apt-get install openjdk-8-jdk

远程挂载和同步

sshfs -o nonempty logcheck@10.101.1.59:/opt/tomcat-chj-9090/logs/ /opt/goaccess-logs/10.101.1.59-nbchj1/
#反推
rsync -e "ssh -p22" -avpgolr /root/.jenkins/ root@10.32.144.191:/root/.jenkins/
#正拉
rsync -avz --delete -e ssh 10.32.144.191:/root/.jenkins/  /root/.jenkins/

一些系统初始优化和磁盘分区挂载

echo "* soft nofile 65535" >>/etc/security/limits.conf
echo "* hard nofile 131072" >>/etc/security/limits.conf
echo "* soft nproc 65535"  >>/etc/security/limits.conf
echo "* hard nproc 131072"  >>/etc/security/limits.conf
ulimit -n 65535
vi /etc/sysctl.conf
sysctl -p

fdisk -l
pvcreate  /dev/sdb
vgcreate  datavg /dev/sdb
lvcreate -l +100%FREE -n datalv datavg
mkfs.ext4 /dev/datavg/datalv
mkdir /data
mount /dev/datavg/datalv /data/
df -h
echo "/dev/mapper/datavg-datalv /data                    ext4    defaults        0 0" >>/etc/fstab

service iptables stop
/sbin/service   firewalld stop
/sbin/chkconfig firewalld off
/usr/bin/sed -i "/SELINUX/s/enforcing/disabled/"  /etc/selinux/config
/usr/sbin/setenforce  0

ssh 互信

/usr/bin/ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.3.31.205

ssh root@10.3.31.205 ifconfig

方法2:

/usr/bin/ssh-keygen -d

scp -P 8022 id_dsa.pub 223.100.98.83:/root/.ssh/authorized_keys

ssh -p 37 root@218.24.71.26

ssh -p 8022 root@223.100.98.84 ifconfig

filebeat

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.3-x86_64.rpm
rpm -ivh filebeat-6.4.3-x86_64.rpm

root@app53:/opt$cat /etc/filebeat/filebeat.yml 
filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/*.log
    - /var/log/messages
  tags: ["system-log"]

- type: log
  enabled: true
  paths:
    - /opt/tomcat*/logs/catalina.out
  multiline.pattern: '^\['
  multiline.negate: true
  multiline.match: after
  tail_files: true
  document_type: tomcat-log
  tags: ["tomcat-log"]

output.logstash:
  hosts: ["10.4.31.162:5044"]

chkconfig filebeat on

同步时间和改时区

https://www.aliyun.com/jiaocheng/118626.html

时间同步:ntpdate 0.centos.pool.ntp.org

ntpdate 0.cn.pool.ntp.org

更换yum源

网易yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache

配置ELEP源:
yum -y install epel-release

数据库操作:

加权限
grant all privileges on *.* to 'root'@'%' identified by '123' with grant option;
快速清理表
truncate table ja_alarm_alarminstance;
清理binlog
show binary logs;
purge binary logs to 'mysql-bin.000271';
创建数据库 
CREATE DATABASE IF NOT EXISTS RUNOOB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
导入脚本 mysql -u -p < ddd.sql
bi数据库在182 3306 记得备份
    /data/weadmin/mysql-mxj/bin/mysql -h127.0.0.1 -P3308 -uroot -proot

/data/weadmin/mysql-mxj/bin/mysqldump -h127.0.0.1 -P3308 -uroot -proot itoss > itoss1010.sql
mysql itoss < itoss1010.sql

防火墙

服务器被攻击,发包占满带宽处理 时间不够,进程暂时找不到,把ip段封了

查看网络流量攻击 iptraf iftop -i eth1 -n -P

封ip段 iptables -A INPUT -s 103.231.0.0/16 -j DROP

「真诚赞赏,手留余香」

Uwei

请我喝杯咖啡?

使用微信扫描二维码完成支付