2017/09/18

CentOS 7

replace Firewalld to iptables

 systemctl mask firewalld
 systemctl stop firewalld
 yum install iptables-services
 systemctl enable iptables
 systemctl start iptables


install some tools

yum install net-tools telnet yum-utils

2016/01/20

CentOS 7 rename hostname

#!/usr/bin/env bash

OLD_HOSTNAME="$( cat /etc/hostname )"
NEW_HOSTNAME="$1"

if [ -z "$NEW_HOSTNAME" ]; then
 echo -n "Please enter new hostname: "
 read NEW_HOSTNAME < /dev/tty
fi

if [ -z "$NEW_HOSTNAME" ]; then
 echo "Error: no hostname entered. Exiting."
 exit 1
fi

echo "Changing hostname from $OLD_HOSTNAME to $NEW_HOSTNAME..."

hostname "$NEW_HOSTNAME"

echo $NEW_HOSTNAME > /etc/hostname

if [ -n "$( grep "$OLD_HOSTNAME" /etc/hosts )" ]; then
 sed -i "s/$OLD_HOSTNAME/$NEW_HOSTNAME/g" /etc/hosts
else
 echo -e "$( hostname -I | awk '{ print $1 }' )\t$NEW_HOSTNAME" >> /etc/hosts
fi

echo "Done."

Make CentOS 7 as template

echo "Clean system"
/sbin/service rsyslog stop
/sbin/service auditd stop
/usr/bin/package-cleanup --oldkernels --count=1 -y
/usr/bin/yum  clean all -y
/usr/sbin/logrotate -f /etc/logrotate.conf
/bin/rm -f /var/log/*-???????? /var/log/*.gz
/bin/rm -f /var/log/dmesg.old
/bin/rm -rf /var/log/anaconda
/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby
/bin/rm -f /etc/udev/rules.d/70*
/bin/sed -i '/^HWADDR=/d' /etc/sysconfig/network-scripts/ifcfg-*
/bin/sed -i '/^UUID=/d' /etc/sysconfig/network-scripts/ifcfg-*
/bin/sed -i 's/static/dhcp/g' /etc/sysconfig/network-scripts/ifcfg-*
/bin/sed -i '/^IPADDR=/d' /etc/sysconfig/network-scripts/ifcfg-*
/bin/sed -i '/^NATMASK=/d' /etc/sysconfig/network-scripts/ifcfg-*
/bin/sed -i '/^GATEWAY=/d' /etc/sysconfig/network-scripts/ifcfg-*
/bin/rm -rf /tmp/*
/bin/rm -rf /var/tmp/*
/bin/rm -f /etc/ssh/*key*
/bin/rm -f ~root/.bash_history
unset HISTFILE
/bin/rm -rf ~root/.ssh/
/bin/rm -f ~root/anaconda-ks.cfg
history -c

2015/11/13

Make CentOS 6 as template

echo "Clean system"
/sbin/service rsyslog stop
/sbin/service auditd stop
/usr/bin/package-cleanup --oldkernels --count=1 -y
/usr/bin/yum  clean all -y
/usr/sbin/logrotate -f /etc/logrotate.conf
/bin/rm -f /var/log/*-???????? /var/log/*.gz
/bin/rm -f /var/log/dmesg.old
/bin/rm -rf /var/log/anaconda
/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby
/bin/rm -f /etc/udev/rules.d/70*
/bin/sed -i '/^HWADDR=/d' /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/sed -i '/^UUID=/d' /etc/sysconfig/network-scripts/ifcfg-eth0
/bin/rm -rf /tmp/*
/bin/rm -rf /var/tmp/*
/bin/rm -f /etc/ssh/*key*
/bin/rm -f ~root/.bash_history
unset HISTFILE
/bin/rm -rf ~root/.ssh/
/bin/rm -f ~root/anaconda-ks.cfg

2015/11/11

CentOS 6 install ClamAV via yum

yum -y install epel-release
yum -y install clamav clamd
# setup & start
chkconfig clamd on
service clamd start
# update
/usr/bin/freshclam
# auto update 
echo '#!/bin/bash' >> /etc/cron.hourly/update
echo '/usr/bin/freshclam' >> /etc/cron.hourly/update
chmod +x /etc/cron.hourly/update
# daily scan
echo '#!/bin/bash' >> /etc/cron.daily/manual_clamscan
echo 'SCAN_DIR="/" ' >> /etc/cron.daily/manual_clamscan
echo 'LOG_FILE="/var/log/clamav/manual_clamscan.log" ' >> /etc/cron.daily/manual_clamscan
echo '/usr/bin/clamscan -i -r $SCAN_DIR >> $LOG_FILE ' >> /etc/cron.daily/manual_clamscan
chmod +x /etc/cron.daily/manual_clamscan

2015/04/16

Cisco Switch Port Mirror setting

monitor session 1 source interface Gi0/2 - 4
monitor session 1 destination interface Gi0/7

SJ2000 time setup

add text file and rename as time.txt

add date and time with this format
Note: there has a space between data and time .


2014.05.07 09:26:00

2015/03/17

vsftp install on CentOS 7

# install on CentOS 7 without iptables and seLinux 

# install something we need
 
yum install vsftpd gcc pam-devel unzip php -y 
 
# Setup for virtual user 
 
curl 'https://codeload.github.com/tiwe-de/libpam-pwdfile/zip/master' > master.zip 
unzip master.zip 
cd libpam-pwdfile-master/ 
make 
cp pam_pwdfile.so /lib64/security/
mv /etc/pam.d/vsftpd /etc/pam.d/vsftpd.org
echo "auth required /lib64/security/pam_pwdfile.so pwdfile  /etc/vsftpd/users" "" >> /etc/pam.d/vsftpd 
echo  "account required /lib64/security/pam_permit.so" "" >>  /etc/pam.d/vsftpd 

# backup config mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.org

# Setup vsftpd main config
echo "local_umask=022" >> /etc/vsftpd/vsftpd.conf
echo "anonymous_enable=NO" >> /etc/vsftpd/vsftpd.conf
echo "local_enable=YES" >> /etc/vsftpd/vsftpd.conf
echo "virtual_use_local_privs=YES" >> /etc/vsftpd/vsftpd.conf
echo "write_enable=YES" >> /etc/vsftpd/vsftpd.conf
echo "connect_from_port_20=YES" >> /etc/vsftpd/vsftpd.conf
echo "secure_chroot_dir=/var/run/vsftpd" >> /etc/vsftpd/vsftpd.conf
echo "pam_service_name=vsftpd" >> /etc/vsftpd/vsftpd.conf
echo "guest_enable=YES" >> /etc/vsftpd/vsftpd.conf
echo "user_sub_token=$USER" >> /etc/vsftpd/vsftpd.conf
echo "local_root=/data/ftp/$USER" >> /etc/vsftpd/vsftpd.conf
echo "chroot_local_user=YES" >> /etc/vsftpd/vsftpd.conf
echo "hide_ids=YES" >> /etc/vsftpd/vsftpd.conf
echo "user_config_dir=/etc/vsftpd/user_config" >> /etc/vsftpd/vsftpd.conf
echo "allow_writeable_chroot=YES" >> /etc/vsftpd/vsftpd.conf

# Setup up for vsftpd running folder

mkdir -p /var/run/vsftpd
mkdir -p /etc/vsftpd/user_config

# Setup up for ftp user

mkdir -p /ftp/users
chown -Rf ftp:ftp /ftp/users

# Note: this command must turn on "short tag"
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php.ini
# ftp user config
mkdir -p  /etc/vsftpd/user_config/

# ftp user account add
echo "<?php echo 'username:' . crypt('passwd'); ?>"| php >> /etc/vsftpd/users
echo "" >> /etc/vsftpd/users
echo "local_root=/ftp/users/username_home""" >> /etc/vsftpd/user_config/username

# Create ftp user home
mkdir -p /ftp/users/username_home
chown -Rf ftp:ftp /ftp/users/username_home

# setup 
systemctl enable vsftpd.service
systemctl start vsftpd.service

#BTW...... add ftp user shell

echo "<?php echo '$1:' . crypt('$2'); ?>"| php >> /etc/vsftpd/users
echo "" >> /etc/vsftpd/users
#mkdir -p  /etc/vsftpd/user_config/
echo "local_root=/ftp/users/$1" "" >> /etc/vsftpd/user_config/$1
mkdir -p /ftp/users/$1

chown -Rf ftp:ftp /ftp/users/$1

##
firewall-cmd --permanent --add-port=21/tcp 
firewall-cmd --permanent --add-service=ftp
Restart firewall:firewall-cmd --reload

2015/03/13

CentOS 7 Samba 4 Clamav

# install Centos 7
# update os

yum -y update
yum install samba samba-common

mv /etc/samba/smb.conf /etc/samba/smb.conf.org
cat /etc/samba/smb.conf.org |grep -v '#' | grep -v ';'|grep -v '^$' > /etc/samba/smb.conf

vi /etc/samba/smb.conf

[global]
        workgroup = MYGROUP
        server string = Samba Server Version %v
        log file = /var/log/samba/log.%m
        max log size = 50
        security = user
        map to guest = Bad User
        load printers = no

[ftp_upload]
        comment    = FTP upload
        path       = /ftp
        browseable = yes
        writable   = yes
        public     = yes
        readonly   = no


systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

--

# install clamav

vi /etc/yum.repos.d/dag.repo


[dag]

name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag/
gpgcheck=1
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
enabled=1



yum install clamd
# Update virus database
freshclam
systemctl enable clamd.service

2015/02/11

My ABP list (Ad Block Plus)

This summary is not available. Please click here to view the post.

2015/02/05

MySQL Backup / mysqldump

-- 備份某個資料庫

# mysqldump -u root -p db > db.sql;

-- 備份資料庫中的某個資料表

# mysqldump -u root -p db table > backup.sql;

-- 備份所有資料庫

# mysqldump -u root -p --all-databases > backup.sql;

-- 復原一個資料庫 (需先建好db_name 這個資料庫, 若沒建立請先執行 mysqladmin create db_name 建立即可)

# mysql -u root -p db < backup.sql

-- 復原多個資料庫 ( 因為backup.sql 內已有 CREATE DATABASE指令,因此不需先建DB)

# mysql -u root -p < backup.sql

注意:
因為新版mysqldump預設會使用UTF8,所以還原較沒問題, 若為舊版的mysqldump, 則需要使用--default-character-set 指定字集

# mysql -u root -p --default-character-set=latin1 db_name < backup.sql
只輸出MySQL DB Schema

mysqldump 資料庫名稱 --no-data > 輸出檔名

2014/12/01

Nagios monitor ESX server

1.install vSphere Perl SDK for vSphere
http://communities.vmware.com/community/developer/forums/vsphere_sdk_perl

2.download perl
http://exchange.nagios.org/directory/Plugins/Operating-Systems/*-Virtual-Environments/VMWare/Vmware-ESX-%26-VM-host/details

3./check_esx3.pl -D 192.168.1.1 -u root -p password -l vmfs

/check_esx3.pl --help
check_esx3.pl 0.5.0

This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
It may be used, redistributed and/or modified under the terms of the GNU
General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).

VMWare Infrastructure plugin

Usage: check_esx3.pl -D | -H [ -N ]
    -u -p | -f
    -l [ -s ]
    [ -x ] [ -o ]
    [ -t ] [ -w ] [ -c ]
    [ -V ] [ -h ]

 -?, --usage
   Print usage information
 -h, --help
   Print detailed help screen
 -V, --version
   Print version information
 --extra-opts=[section][@file]
   Read options from an ini file. See http://nagiosplugins.org/extra-opts
   for usage and examples.
 -H, --host=
   ESX or ESXi hostname.
 -C, --cluster=
   ESX or ESXi clustername.
 -D, --datacenter=
   Datacenter hostname.
 -N, --name=
   Virtual machine name.
 -u, --username=
   Username to connect with.
 -p, --password=
   Password to use with the username.
 -f, --authfile=
   Authentication file with login and password. File syntax :
   username=
   password=
 -w, --warning=THRESHOLD
   Warning threshold. See
   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT
   for the threshold format.
 -c, --critical=THRESHOLD
   Critical threshold. See
   http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT
   for the threshold format.
 -l, --command=COMMAND
   Specify command type (CPU, MEM, NET, IO, VMFS, RUNTIME, ...)
 -s, --subcommand=SUBCOMMAND
   Specify subcommand
 -S, --sessionfile=SESSIONFILE
   Specify a filename to store sessions for faster authentication
 -x, --exclude=
   Specify black list
 -o, --options=
   Specify additional command options
 -t, --timeout=INTEGER
   Seconds before plugin times out (default: 30)
 -v, --verbose
   Show details for command-line debugging (can repeat up to 3 times)
Supported commands(^ means blank or not specified parameter) :
    Common options for VM, Host and DC :
        * cpu - shows cpu info
            + usage - CPU usage in percentage
            + usagemhz - CPU usage in MHz
            ^ all cpu info
        * mem - shows mem info
            + usage - mem usage in percentage
            + usagemb - mem usage in MB
            + swap - swap mem usage in MB
            + overhead - additional mem used by VM Server in MB
            + overall - overall mem used by VM Server in MB
            + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooning
            ^ all mem info
        * net - shows net info
            + usage - overall network usage in KBps(Kilobytes per Second)
            + receive - receive in KBps(Kilobytes per Second)
            + send - send in KBps(Kilobytes per Second)
            ^ all net info
        * io - shows disk io info
            + read - read latency in ms (totalReadLatency.average)
            + write - write latency in ms (totalWriteLatency.average)
            ^ all disk io info
        * runtime - shows runtime info
            + status - overall host status (gray/green/red/yellow)
            + issues - all issues for the host
            ^ all runtime info
    VM specific :
        * cpu - shows cpu info
            + wait - CPU wait time in ms
            + ready - CPU ready time in ms
        * mem - shows mem info
            + swapin - swapin mem usage in MB
            + swapout - swapout mem usage in MB
            + active - active mem usage in MB
        * io - shows disk I/O info
            + usage - overall disk usage in MB/s
        * runtime - shows runtime info
            + con - connection state
            + cpu - allocated CPU in MHz
            + mem - allocated mem in MB
            + state - virtual machine state (UP, DOWN, SUSPENDED)
            + consoleconnections - console connections to VM
            + guest - guest OS status, needs VMware Tools
            + tools - VMWare Tools status
    Host specific :
        * net - shows net info
            + nic - makes sure all active NICs are plugged in
        * io - shows disk io info
            + aborted - aborted commands count
            + resets - bus resets count
            + kernel - kernel latency in ms
            + device - device latency in ms
            + queue - queue latency in ms
        * vmfs - shows Datastore info
            + (name) - free space info for datastore with name (name)
            ^ all datastore info
        * runtime - shows runtime info
            + con - connection state
            + health - checks cpu/storage/memory/sensor status
            + maintenance - shows whether host is in maintenance mode
            + list(vm) - list of VMWare machines and their statuses
        * service - shows Host service info
            + (names) - check the state of one or several services specified by (names), syntax for (names):,,...,
            ^ show all services
        * storage - shows Host storage info
            + adapter - list bus adapters
            + lun - list SCSI logical units
            + path - list logical unit paths
    DC specific :
        * io - shows disk io info
            + aborted - aborted commands count
            + resets - bus resets count
            + kernel - kernel latency in ms
            + device - device latency in ms
            + queue - queue latency in ms
        * vmfs - shows Datastore info
            + (name) - free space info for datastore with name (name)
            ^ all datastore info
        * runtime - shows runtime info
            + list(vm) - list of VMWare machines and their statuses
            + listhost - list of VMWare esx host servers and their statuses
            + tools - VMWare Tools status
        * recommendations - shows recommendations for cluster
            + (name) - recommendations for cluster with name (name)
            ^ all clusters recommendations

2014/11/06

ESXi 5.x snmp setting

0. download and install  VMware vSphere CLI 5.0 and turn on cmd


1.

cd "C:\Program Files (x86)\VMware\VMware vSphere CLI\bin\"

2.

vicfg-snmp.pl --server 192.168.200.212 --username root --password password --c public

3.

vicfg-snmp.pl --server 192.168.200.212  --username root --password password --enable

4.

vicfg-snmp.pl --server 192.168.200.212  --username root --password password  --show

2014/02/13

smokeping (v2.6.9) install CentOS 6

Download from http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz

yum install perl cpan rrdtool-perl gcc gcc-c++
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz
tar zxvf smokeping-2.6.9.tar.gz
cd smokeping-2.6.9
./configure
##--install lost perl--with--
##perl -MCPAN -e 'install "the perl u need to install'
./setup/build-perl-modules.sh /usr/local/smokeping-2.6.9/thirdparty
./configure --prefix=/usr/local/smokeping
make ; make install
## install fping

wget http://fping.sourceforge.net/download/fping.tar.gz
tar zxvf fping.tar.gz
cd fping-2.4b2_to/
./configure
make ; make install

##Make dir

mkdir -p /usr/local/smokeping/cache
mkdir -p /usr/local/smokeping/data
##cp /usr/local/smokeping/htdocs/smokeping.fcgi.dist  /usr/local/smokeping/htdocs/smokeping.fcgi

## Edit config

cp  /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config
vi /usr/local/smokeping/etc/config

## Start up

/usr/local/smokeping/bin/smokeping start
/usr/local/smokeping/bin/smokeping --reload
/usr/local/smokeping/bin/smokeping --restart
/usr/local/smokeping/bin/smokeping --debug
/usr/local/smokeping/bin/smokeping --check


## http server

vi /etc/httpd/conf.d/smokeping.conf   

----
ScriptAlias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi.dist"

alias /cache "/usr/local/smokeping/cache"



AllowOverride None

AddHandler cgi-script cgi

Options ExecCGI
 

----

service httpd reload





2014/01/23

Cacti install spine

1.download spine

wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
tar xvf cacti-spine-0.8.8b.tar.gz
cd cacti-spine-0.8.8b

2.install

./configure && make && make install
cp spine.conf.dist /etc/spine.conf


3.edit mysql login user

vi  /etc/spine.conf



2013/12/17

nagios install

 useradd nagios
 wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.2.tar.gz
 wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
 tar xfv nagios-4.0.2.tar.gz
 tar xvf nagios-plugins-1.5.tar.gz
 cd nagios-4.0.2
 ./configure --prefix=/usr/local/nagios
 make ; make all ; make install
 make install-init
 make install-config
 cd ../nagios-plugins-1.5
 ./configure --prefix=/usr/local/nagios && make all && make install

-- for nagios map --

yum install gd gd-devel

make clean
 ./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib   --with-gd-inc=/usr/include
 ./configure --with-command-group=nagcmd
 make all; make install; make install-init; make install-config; make install-commandmode; make install-webconf 

-- for mail command --

yum install mailx


-- for perl --
yum -y install perl-Params-Validate perl-Math-Calc-Units perl-Regexp-Commonperl-Class-Accessor perl-Config-Tiny perl-Nagios-Plugin.noarch

2013/12/12

Convert a VMX to an OVF
ovftool f:/myvms/BigDemo.vmx x:/ovf/BigDemo.ovf


Convert a VMX to an OVA
ovftool vmxs/Nostalgia.vmx ovfs/Nostalgia.ova


Convert an OVF to a VMX
ovftool BigDemo.ovf x:/myvms/BigDemo.vmx

2013/12/11

send from Linux with file

yum -y install mutt mailx

echo "This is backup" | mutt -a "/backup/2013-12-11-10:59:09.tgz" -s "Master *** backup" --wtf@mail.mail

2013/12/03

bashrc







# .bashrc
export PS1='\[\033[01;32m\][`date +%T`]\[\033[01;31m\][\u@\h]\[\033[00m\] \w \$'

# User specific aliases and functions
alias ll='ls -lah'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ls='ls --color'
alias today="date '+%F week %u'"
alias bye='history -c;exit'
alias zhutf8='setenv LC_ALL zh_TW.utf8;setenv LANG zh_TW.utf8'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi


2013/11/29

建立SSL使用憑證

##建立SSL使用憑證
mkdir -p /ssl/
cd /ssl
openssl genrsa -out privatekey.pem 2048
openssl req -new -key privatekey.pem -out  certerq.csr

openssl x509 -req -days 3650 -in certerq.csr -signkey privatekey.pem -out cert.pem

openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -out /ssl/apache2/apache.crt -keyout /ssl/apache2/apache.key