#!/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."
Showing posts with label centos. Show all posts
Showing posts with label centos. Show all posts
2016/01/20
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
/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
/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/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 account required /lib64/security/pam_permit.so" "" >> /etc/pam.d/vsftpd echo " # 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
# 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
# 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
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
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
# 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
# Update virus database
freshclam
systemctl enable clamd.service
2013/08/08
yum
Error: pkgKey doesn't exist in repo base (centos5.x)
yum clean all ; yum clean metadata ; yum -y update
###
The program package-cleanup is found in the yum-utils package.
yum install yum-utils
yum-complete-transaction --cleanup-only
package-cleanup --dupes ; package-cleanup --problems
###Proxy
vi /etc/yum.conf
yum clean all ; yum clean metadata ; yum -y update
###
The program package-cleanup is found in the yum-utils package.
yum install yum-utils
yum-complete-transaction --cleanup-only
package-cleanup --dupes ; package-cleanup --problems
###Proxy
vi /etc/yum.conf
proxy=http://proxy_ip:port
http://wiki.debian.org.hk/w/Manage_software_with_YUM
2012/11/24
clinet snmp install
CentOS
yum -y install net-snmp
#install tools
#yum -y install net-snmp-utils
# setup secret
echo 'rocommunity XXXXXX' >> /etc/snmp/snmpd.conf
# setup snmp proxy
# squid sample
# proxy -v 1 -c public 127.0.0.1:3401 .1.3.6.1.4.1.3495
chkconfig snmpd on
service snmpd start
Ubuntu Server
apt-get install snmpd
#mv /etc/snmp/snmpd.conf snmpd.conf.old
#vim /etc/snmp/snmpd.conf
#rocommunity XXXXXX "ip address" (from monitor)
echo 'rocommunity XXXXXX "ip address" (from monitor) ' >> /etc/snmp/snmpd.conf
sudo /etc/init.d/snmpd restart
2012/07/16
HAproxy
設定檔
global
log 127.0.0.1 local0
#chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
#listen stats 184.82.2.32:808 ###查看状态的地址和端口http://184.82.2.32:808/haproxy?stats
#balance
# mode http
# stats enable
# stats auth taobao:Tao@2011
# timeout connect 10000 # default 10 second time out if a backend is not found
# timeout client 300000
# timeout server 300000
# maxconn 60000
# retries 3
listen smtp 192.168.0.111:25
mode tcp
log global
timeout connect 10000 # default 10 second time out if a backend is not found
timeout client 300000
timeout server 300000
maxconn 60000
retries 3
balance roundrobin ###负载策略
server smtpb 192.168.0.113:25 check ###后端真实服务器
server smtpb 192.168.0.114:25 check ###后端真实服务器
安裝
cd /tmp/
useradd haproxy
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gz
tar -xf haproxy-1.4.21.tar.gz
cd haproxy-1.4.21
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install
vi /usr/local/haproxy/haproxy.cfg
haproxy -f /usr/local/haproxy/haproxy.cfg
啟動
/usr/local/sbin/haproxy -f /etc/haproxy/haproxy.cfg
停止
ps aux |grep haproxy
kill (pid number)
Postfix 綁上多個IP
vi /etc/postfix/main.cf
inet_interfaces = $myhostname, localhost
vi /etc/postfix/master.cf
#IP前面不能有任何空白
192.168.1.6:25 inet n - n - - smtpd -o content_filter=
192.168.1.7:25 inet n - n - - smtpd -o content_filter=
192.168.1.8:25 inet n - n - - smtpd -o content_filter=
#IP前面不能有任何空白
service postfix reload
netstat -tnlp
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7008/master
tcp 0 0 192.168.1.6:25 0.0.0.0:* LISTEN 7008/master
tcp 0 0 192.168.1.7:25 0.0.0.0:* LISTEN 7008/master
tcp 0 0 192.168.1.8:25 0.0.0.0:* LISTEN 7008/master
Postfix install
yum -y update
yum -y install wget gcc make man db*-devel telnet
wget ftp://ftp.porcupine.org/mirrors/project-history/postfix/experimental/postfix-2.9-20110130.tar.gz
mv postfix-2.9-20110130.tar.gz /tmp
cd /tmp/
tar -xf postfix-2.9-20110130.tar.gz
cd postfix-2.9-20110130
chmod 755 postfix-install
make
make install
groupadd postfix -g 1000
groupadd postdrop
useradd postfix -u 1000 -g postfix -G postdrop
postalias hash:/etc/aliases
#這個aliases檔案有可能出現在/etc/postfix/aliases內
開機啟動
vi /etc/rc.d/rc.local
加上 /usr/sbin/postfix start
2012/04/30
Centos + httpd
yum -y install httpd
iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
service iptables save
vi /etc/httpd/conf/httpd.conf
/ Listen
add
--
Listen *:443
--
netstat -tlunp | grep httpd
關於SSL部分設定參閱
http://www.twisu.com.tw/5/linset/www1.htm
http://docdb.fnal.gov/doc/sslconf.html
http://www.twbsd.org/cht/book/ch14.htm
http://www.apache-ssl.org/httpd.conf.example
關於SSL部分設定參閱
http://www.twisu.com.tw/5/linset/www1.htm
http://docdb.fnal.gov/doc/sslconf.html
http://www.twbsd.org/cht/book/ch14.htm
http://www.apache-ssl.org/httpd.conf.example
2012/04/03
traceroute (centos)
yum -y install
traceroute
~
traceroute 192.168.0.1
traceroute to 192.168.0.1 (192.168.0.1), 30 hops max, 60 byte packets
1 router.corp.*.* (192.168.0.1) 0.673 ms 0.697 ms 0.785 ms
2011/10/24
Centos install PHP
yum -y install php php-mbstring php-mysql
chkconfig httpd on
chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
/etc/rc.d/init.d/httpd start
chkconfig httpd on
chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
/etc/rc.d/init.d/httpd start
Centos 5.5 install MySQL
Centos 5.5 install MySQL
yum -y install mysql-server
vi /etc/my.cnf
--
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8
[mysql.server]
user=mysql
basedir=/var/lib
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set = utf8
--
chkconfig mysqld on
chkconfig --list mysqld
2-5 開啟
/etc/rc.d/init.d/mysqld start
--
正在初始化 MySQL 資料庫: Neither host 'ip位置' nor 'localhost' could be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option
--
vi /etc/hosts
--
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
--
/etc/rc.d/init.d/mysqld start
mysqladmin -u root password 'Your Password'
yum -y install mysql-server
vi /etc/my.cnf
--
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set = utf8
[mysql.server]
user=mysql
basedir=/var/lib
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set = utf8
--
chkconfig mysqld on
chkconfig --list mysqld
2-5 開啟
/etc/rc.d/init.d/mysqld start
--
正在初始化 MySQL 資料庫: Neither host 'ip位置' nor 'localhost' could be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option
--
vi /etc/hosts
--
# Do not remove the following line, or various programs
# that require network functionality will fail.
#::1 localhost.localdomain localhost
127.0.0.1 localhost.localdomain localhost
--
/etc/rc.d/init.d/mysqld start
mysqladmin -u root password 'Your Password'
2011/10/19
2011/10/18
cvs2git
這是在本地端的方法
需事先安裝cvs2git
cvs2git \
--blobfile=user/user-blob.dat \
--dumpfile=user/user-dump.dat \
--username=cvs2git \
/mnt/HDD/jspspace/user/ --fallback-encoding=big5
--
cvs2git \
--blobfile=原專案名稱/原專案名稱-blob.dat \
--dumpfile=原專案名稱/原專案名稱-dump.dat \
--username=cvs2git \
/mnt/HDD/原專案名稱/
2011/10/07
SSH strart on Cent OS
/etc/init.d/sshd restart
vim /etc/hosts.allow
sshd:ALL
vim /etc/hosts.deny
sshd:ip-a ,ip-b ,
Subscribe to:
Posts (Atom)