linux系统日志清空

for I in `echo dmesg lastlog messages secure tallylog wtmp btmp maillog spooler yum.log`; do
echo > /var/log/$I;
done
history -c


supermicro IPMI/BMC nginx proxy

需要安装一个openresty或者nginx, 版本大于1.15.10

编译安装参考http://www.kvm.la/1043.html , openresty二进制包版本较低没有更新, 建议编译安装一份.

首先把IPMI的IP丢进一个ip.list的文件里面, 一行一个IP.

cat list.sh
#/bin/bash
i=1000  #vnc start port
b=2000 #wsi start port

stream_vnc_map=/etc/nginx/stream.vnc.map.conf
stream_bmc_map=/etc/nginx/stream.bmc.map.conf
http_vnc_map=/etc/nginx/http.vnc.map.conf
http_bmc_map=/etc/nginx/http.bmc.map.conf

#清空配置
echo > $stream_bmc_map
echo > $stream_vnc_map
echo > $http_vnc_map
echo > $http_bmc_map

#给IP分配统一的端口
for IP in `cat ./ip.list`;
do
i=`expr $i + 1` ;
b=`expr $b + 1` ;
echo $i         $IP';' >> $stream_vnc_map
echo $b 	$IP';' >> $stream_bmc_map
echo $IP 	$i';' >>  $http_vnc_map
echo $IP        $b';' >>  $http_bmc_map
done

nginx -s reload

阅读剩余部分...

Command | kickstart之中rootpw密码生成方法

一、简介

linux kickstart文件里rootpw密码可以使用明文,也可以使用加密过的值,这里主要介绍下三种加密方法:md5、sha256、sha512

使用明文的方法

rootpw "password"

使用加密的方法

rootpw --iscrypted password_hashauthconfig --enableshadow --enablemd5 (--passalgo=sha256 or --passalgo=sha512)

二、加密生成方法,这里统一用password来加密

1、md5加密

使用openssl passwd命令:

# openssl passwd -1 "password"$1$uMOl6YMI$7AAO8YG7l37ipRXCmmame.

使用grub-crypt命令,会提示输出密码:

# grub-crypt --md5Password:Retype password:$1$Y9TR8PpY$qm1VzsjKzbXtYInyAQLG70

使用python,同样也会提示输出密码:

# echo 'import crypt,getpass; print crypt.crypt(getpass.getpass(), "$1$8_CHARACTER_SALT_HERE")' | python -Password:$1$8_CHARAC$GVWpvO3Hu009C37IYF41L0

阅读剩余部分...

centos7升级到centos8

只负责记录, 升级出了问题责任自负.

yum -y install epel-release yum-utils rpmconf  dnf
yum remove 

# 
# package-cleanup --leaves
# package-cleanup --orphans
#

dnf -y remove yum yum-metadata-parser libsysfs  
dnf upgrade -y
dnf upgrade -y http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/{centos-release-8.1-1.1911.0.8.el8.x86_64.rpm,centos-gpg-keys-8.1-1.1911.0.8.el8.noarch.rpm,centos-repos-8.1-1.1911.0.8.el8.x86_64.rpm}

dnf upgrade -y epel-release
dnf clean all
rpm -e `rpm -q kernel`
rpm -e --nodeps sysvinit-tools
dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
dnf -y install kernel-core
dnf -y groupupdate Core "Minimal Install"
cat /etc/redhat-release


centos8的三个包centos-release centos-gpg-keys centos-repos版本会有变动, 操作的时候需要注意选择更新.

也可以不用http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/ ,选用centos vault的库.


frps服务器一键搭建脚本

wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh
chmod 700 ./install-frps.sh
./install-frps.sh install


Linux常用性能测试脚本

dd if=/dev/zero of=test bs=64k count=4k oflag=dsync
curl -Ss http://86.re/bench.sh |bash
curl -fsL https://ilemonra.in/LemonBenchIntl | bash -s fast
curl -fsL https://github.com/LemonBench/LemonBench/raw/master/LemonBench.sh | bash -s fast

https://www.91yuntest.com/

wget -N --no-check-certificate https://raw.githubusercontent.com/91yun/91yuntest/master/test.sh && bash test.sh -i "io,bandwidth,chinabw,download,traceroute,backtraceroute,allping,gotoping,benchtest" -u
wget -qO- --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash
wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py -O  /usr/local/bin/speedtest
chmod a+rx  /usr/local/bin/speedtest
speedtest
wget http://down.eeqiu.net/besttrace4linux.zip
unzip besttrace4linux.zip
chmod +x besttrace
./besttrace -q 1 gd.189.cn


juniper的lo0基础安全连接规则

set firewall family inet filter local_acl term DenyICMP from protocol icmp
set firewall family inet filter local_acl term DenyICMP from icmp-type echo-request
set firewall family inet filter local_acl term DenyICMP from icmp-type echo-reply
set firewall family inet filter local_acl term DenyICMP from icmp-type time-exceeded
set firewall family inet filter local_acl term DenyICMP from icmp-type unreachable
set firewall family inet filter local_acl term DenyICMP then discard
set firewall family inet filter local_acl term terminal_access from source-prefix-list Trusted_IP
set firewall family inet filter local_acl term terminal_access then accept
set firewall family inet filter local_acl term terminal_access_denied from protocol tcp
set firewall family inet filter local_acl term terminal_access_denied from destination-port ssh
set firewall family inet filter local_acl term terminal_access_denied from destination-port telnet
set firewall family inet filter local_acl term terminal_access_denied from destination-port http
set firewall family inet filter local_acl term terminal_access_denied from destination-port https
set firewall family inet filter local_acl term terminal_access_denied then discard
set firewall family inet filter local_acl term default-term then accept


fedora大版本升级记录

dnf update --refresh -y
dnf install dnf-plugin-system-upgrade -y
dnf system-upgrade download --releasever=$((`awk '{ print $3 }' /etc/fedora-release` + 1 )) --allowerasing -y
dnf system-upgrade reboot -y
dnf --releasever $((`awk '{ print $3 }' /etc/fedora-release` + 1 )) upgrade -y

一路从23逐步升级到31

nginx主机添加

AddNginxHost(){
cat>>/etc/nginx/conf/$1.conf<<EOF
server {
listen 80;
listen 443;
server_name www.$1 $1;
access_log /var/log/httpd/$1.log;
location /{
proxy_set_header   Host \$host;
proxy_set_header  X-Forwarded-For  \$remote_addr;
proxy_pass http://$2;
}
}
EOF
}
function banip () {
cat>/etc/nginx/ip/$1<<EOF
deny $1;
if (\$remote_addr = "$1"){return 400;}
if (\$http_x_forwarded_for = "$1"){return 400;}
if (\$proxy_add_x_forwarded_for = "$1"){return 400;}
EOF
nginx -s reload
}
function add_stream() { 
cat > /etc/nginx/stream/$1.conf << EOF
    server {
    	listen $1:80 reuseport;
        listen $1:443 reuseport;
        listen $1:623 udp reuseport;
        listen $1:5900 reuseport;
        listen $1:5985 reuseport;
        listen $1:7578 reuseport;
        listen $1:5120 reuseport;
        listen $1:5122 reuseport;
        listen $1:5123 reuseport;
        listen $1:7582 reuseport;
        listen $1:5124 reuseport;
        listen $1:5126 reuseport;
        listen $1:5127 reuseport;
        proxy_connect_timeout 5s;
        proxy_timeout 20s;
        proxy_pass $2:\$server_port;
    }
EOF
nginx -s reload
}
 add_stream 103.213.246.4 10.0.13.13
snap() 
{
if [ ! -n $1 ]; then exit 0 ;fi
	lvcreate -L 50G -s -n  $1_snap /dev/vg0/$1_img
	kpartx -av /dev/mapper/vg0-$1_snap
	mount /dev/mapper/vg0-$1_snap1 /mnt
	ls /mnt/root/.bash_history
}


powerdns系列记录

mysqlrootpwd=`openssl rand 6 -base64`
yum -y install epel-releas 
yum -y install mysql mysql-server pdns pdns-backend-mysql
yum -y install httpd php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash 
yum -y install php-pear-DB php-pear-MDB2-Driver-mysql
chkconfig --levels 235 httpd on
chkconfig --levels 235 mysqld on
chkconfig --levels 235 pdns on

#mysqladmin -u root password  $mysqlrootpwd
mysqladmin create powerdns
mysql -Bse "create user 'powerdns'@'localhost' identified by '$mysqlrootpwd'"
mysql -Bse "grant all privileges on powerdns.* to 'powerdns'@'localhost'"
mysql -Bse "GRANT ALL ON powerdns.* TO 'powerdns'@'108.171.205.98' IDENTIFIED BY '$mysqlrootpwd'"

wget http://files.soluslabs.com/solusvm/pdns/pdns.sql
mysql --user=powerdns --password=$mysqlrootpwd < pdns.sql
cat>/etc/pdns/pdns.conf<<EOF
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=powerdns
gmysql-password=$mysqlrootpwd
gmysql-dbname=powerdns  
EOF

/etc/init.d/mysqld restart
/etc/init.d/httpd restart
/etc/init.d/httpd start
/etc/init.d/pdns restart
wget -c https://github.com/poweradmin/poweradmin/tarball/master -O poweradmin.tar.gz
tar zxf poweradmin.tar.gz
mv poweradmin-* /var/www/html/poweradmin
chown -R apache:apache /var/www/html/poweradmin/


ESXI无法登陆问题

新装系统的esxi密码正确无法登陆, 在几年前就遇上过用,在shell下操作重置解决的, 但时间太久忘记了, 然后最近又遇上了几次像无头苍蝇一样,特此记录一下.
主要原因是ssh端口被爆破错误次数过多,导致锁死的问题.
新装系统,登陆上管理页面后在“管理”->"高级设置"里面搜索把Security.AccountLockFailures设置成0或者是关闭ssh服务

Security.AccountLockFailures
Security.AccountUnlockTime

也可以在设置成ssh key登陆, 对root账户进行重置解决

authorized_keys路径

/etc/ssh/keys-root/authorized_keys

重置命令

pam_tally2 --user root
pam_tally2 --user root --reset


如果新装系统已经被锁死还没设置key登陆, 则需要到ipmi下操作.
在Troubleshooting mode options项目下选择Restart Management Agents进行重置, 之后就可以再用web或者客户端进行登陆设置了.

nfsen-blackhole

记录

yum -y -q install monit tcsh  perl-Net-BGP
git clone https://github.com/zhecho/nfsen-blackhole 
cd nfsen-blackhole 
sed  -i "s#/usr/local/var/nfsen#/opt/nfsen/var/run#g" *
sed  -i "s#/usr/local/libexec/nfsen/plugins#/opt/nfsen/plugins#g" *
                          
install bgp_simple_restart.sh /opt/nfsen/plugins/
install blackHole.pm   /opt/nfsen/plugins/
install bgp_simple.pl  /opt/nfsen/plugins/
install blackHole.php  /opt/nfsen/www/plugins/
touch /opt/nfsen/var/run/{blackhole-pref.td2,blackHole.plugin.log}
chown nobody:nobody /opt/nfsen/var/run/{blackhole-pref.td2,blackHole.plugin.log}


WANsensor和WANconsole 安装

配置记录

yum install -y -q http://www.andrisoft.com/files/redhat7/WANrepo-7.2-0.noarch.rpm
yum install -y -q WANsensor
systemctl start ntpd
systemctl enable ntpd
/opt/andrisoft/bin/install_supervisor
systemctl start WANsupervisor
systemctl enable WANsupervisor
yum install -y -q http://www.andrisoft.com/files/redhat7/WANrepo-7.2-0.noarch.rpm
yum install -y -q  WANconsole 
yum install -y -q epel-release
yum install -y -q php-pecl-radius

其他

max_allowed_packet=64M
 max_connections=1000
 open_files_limit=5000
 skip-name-resolve
         
nano /etc/my.cnf #set max_allowed_packet=64M, max_connections=1000, open_files_limit=5000 and add skip-name-resolve in the [mysqld] section
systemctl start mariadb
mysql_secure_installation
systemctl start mariadb
systemctl enable mariadb
         
         
nano /etc/php.ini #set date.timezone in the [Date] section, according to http://php.net/manual/en/timezones.php
systemctl enable httpd
systemctl restart httpd
         
firewall-cmd --permanent --add-service=mysql
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
systemctl restart firewalld
         
/opt/andrisoft/bin/install_console
/opt/andrisoft/bin/install_supervisor
         
systemctl start WANsupervisor
systemctl enable WANsupervisor
         
         
yum install -y -q https://dl.influxdata.com/influxdb/releases/influxdb-1.7.9.x86_64.rpm
[[email protected] ~]# nano /etc/influxdb/influxdb.conf 
[data] 
index-version=”tsi1”
max-seriesper-database=0
max-values-per-tag=0
[retention]
enabled=true
[http] 
enabled=true
log-enabled=false
max-row_limit=0
max-body-size=0
[logging] 
level=”warn”
[continuous_queries]
enabled=true
systemctl restart influxdb


sflow-rt安装

sflow-rt这玩意挺方便, 可以用JS进行二次开发写APP

官方下载连接 https://sflow-rt.com/download.php


yum install java -y
yum install -y -q https://inmon.com/products/sFlow-RT/sflow-rt-3.0-1451.noarch.rpm 
/usr/local/sflow-rt/get-app.sh sflow-rt top-flows
/usr/local/sflow-rt/get-app.sh sflow-rt dashboard-example
/usr/local/sflow-rt/get-app.sh sflow-rt ddos-blackhole
/usr/local/sflow-rt/get-app.sh sflow-rt sflow-test
/usr/local/sflow-rt/get-app.sh sflow-rt ddos-protect
systemctl start sflow-rt
systemctl enable sflow-rt


firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --zone=public --add-forward-port=port=179:proto=tcp:toport=1179 --permanent
firewall-cmd --zone=public --add-port=179/tcp --permanent
firewall-cmd --zone=public --add-port=6343/udp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports


如果要用179端口做bgp需要在服务器启动文件加入authbind的命令

yum install -y https://s3.amazonaws.com/aaronsilber/public/authbind-2.1.1-0.1.x86_64.rpm
touch /etc/authbind/byport/179
chmod 755 /etc/authbind/byport/179


在 /etc/init.d/sflow-rt文件内找到START这一行

START='authbind --deep /usr/local/sflow-rt/bin/run-rt'



librenms简便安装

和observium很像,开源软件.

file bison mlocate flex diffutils
yum -y install cronie fping git ImageMagick whois mtr  net-snmp net-snmp-utils nmap  python-memcached rrdtool
useradd librenms -d /opt/librenms -M -r
cd /opt
git clone https://github.com/librenms/librenms.git
chown -R librenms:librenms /opt/librenms
chmod 770 /opt/librenms
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
runuser -l  librenms -c '/opt/php7/bin/php /opt/librenms/scripts/composer_wrapper.php install --no-dev'

nginx配置

server {
    listen 80;
    root /opt/observium;
    index index.php;
    server_name observium.example.com;
                                                               
    error_log /var/log/nginx/observium.error.log ;
    access_log /var/log/nginx/observium.log ;
                                                               
    location / {
    location ~ .php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/dev/shm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_read_timeout 300;
    }
        }
                                                               
    location ~/\.ht {
        deny all;
    }
}
                                                               
server {
 listen      80;
 server_name librenms.example.com;
 root        /opt/librenms/html;
 index       index.php;
 location / {
  try_files $uri $uri/ /index.php?$query_string;
 }
 location /api/v0 {
  try_files $uri $uri/ /api_v0.php?$query_string;
 }
 location ~ \.php {
  include fastcgi.conf;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/dev/shm/php-fpm.sock;
 }
 location ~ /\.ht {
  deny all;
 }
}

FPM配置文件

[librenms]
user = $pool
group = $pool
listen = /dev/shm/$pool.sock
listen.mode = 0666
pm = dynamic
pm.max_children = 15
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 5
chdir = /opt/bgpto
security.limit_extensions = .php .php3 .php4 .php5 .php7
env[HOSTNAME] = $pool.hostname
env[PATH] = /usr/local/bin:/usr/bin:/bin:/opt/php7/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
php_admin_value[error_log] = /var/log/fpm-php.$pool.log
php_admin_value[memory_limit] = 256M