分类目录归档:CentOS

CentOS7 Lsyncd 文件实时同步(替代Rsync和Inotify)

Lsyncd结合了inotify + rsync,Lsyncd监视本地目录树事件监视器接口(inotify或fsevents)。它聚合和组合事件几秒钟,然后生成一个(或多个)进程(es)来同步更改。

部署环境

# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

# uname -a                
Linux filesync-20.203.localdomain 3.10.0-693.11.1.el7.x86_64 #1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    
# rsync --version   
rsync  version 3.0.9  protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
    
# lsyncd --version         
Version: 2.2.2

  安装部署 lsyncd

部署机器

Server-A  192.168.20.203   [主文件服务器,  读写]
Server-B  192.168.20.204   [备份文件服务器,只读]

密钥登录

Server-A服务器上操作

#生成密钥文件
ssh-keygen -t rsa
#将公钥拷贝到B
ssh-copy-id username@192.168.20.204
#测试
ssh username@192.168.20.204

安装 lsyncd

yum -y install lsyncd

配置文件

settings {
    logfile    = "/tmp/lsyncd.log",
    statusFile = "/tmp/lsyncd.status",
    insist = true,
    statusInterval = 10
}
sync {
    default.rsyncssh,
    source="/data",
    host="username@192.168.20.204",
    targetdir="/data",
    rsync = {
        archive = true,
        compress = false,
        whole_file = false,
        _extra = {"--bwlimit=40960"}
    },
    ssh = {
        port = 22
    }
}

测试

lsyncd -nodaemon /etc/lsyncd.conf

后台启动 lsyncd

systemctl start lsyncd
systemctl enable lsyncd

系统优化

echo -e "\nfs.inotify.max_user_watches = 8192000" >> /etc/sysctl.conf 
sysctl -p

参考文档

CentOS6 安装Webmin

官网:http://www.webmin.cn/download.html
参考:http://spikedighole.blog.163.com/blog/static/176998045201562805435418/

# uname -a                
Linux localhost.localdomain 2.6.32-573.18.1.el6.x86_64 #1 SMP Tue Feb 9 22:46:17 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release 
CentOS release 6.7 (Final)
# rpm -qa|grep webmin
webmin-1.780-1.noarch


# webadmin安装升级会用到perl-Net-SSLeay
yum -y install perl-Net-SSLeay
# wget http://prdownloads.sourceforge.net/webadmin/webmin-1.740-1.noarch.rpm
wget http://jaist.dl.sourceforge.net/project/webadmin/webmin/1.780/webmin-1.780-1.noarch.rpm
rpm -ivh webmin-1.780-1.noarch.rpm 
netstat -ntlp|grep 10000

 

CentOS 使用lynx更新3322.org DDNS

参考文档:
http://www.pubyun.com/products/dyndns/download/

# 安装lynx
# yum install lynx

# lynx -mime_header -auth=hahaha:2016! "http://members.3322.net/dyndns/update?system=dyndns&hostname=hahaha.f3322.net"
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 Feb 2016 09:12:23 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
Vary: Cookie

good 16.26.19.26
#
# 
# lynx -mime_header -auth=hahaha:2016! "http://members.3322.net/dyndns/update?system=dyndns&hostname=hahaha.f3322.net"
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 23 Feb 2016 09:14:00 GMT
Content-Type: text/plain; charset=utf-8
Connection: close
Vary: Cookie

nochg 16.26.19.26

 

CentOS6 安装phpMyAdmin

# cat /etc/redhat-release 
CentOS release 6.7 (Final)
# rpm -qa|grep phpMyAdmin
phpMyAdmin-4.0.10.14-1.el6.noarch
# rpm -qa|grep mysql-server
mysql-server-5.1.73-5.el6_6.x86_64

# 添加epel源
# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm

# 安装相关软件包
# yum -y install httpd mysql php php-mysql phpmyadmin

# 修改index文件
# vi /etc/httpd/conf/httpd.conf 
DirectoryIndex index.php index.html index.html.var

# 允许远程登录phpMyAdmin
# vi /etc/httpd/conf.d/phpMyAdmin.conf 
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 1.1.1.2
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
   
# 重启httpd
service httpd restart

# 登录
http://server_ip/phpmyadmin/

 

kickstart_示例

kickstart 示例

 

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --enabled --http --ssh --port=123:udp
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8
# Use network installation
url --url=http://192.168.211.50/cblr/links/centos7mini-x86_64
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.211.50/cobbler/ks_mirror/centos7mini-x86_64

# Network information
# # Using "new" style networking config, by matching networking information to the physical interface's 
# MAC-address
# %include /tmp/pre_install_network_config

network  --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto
# --device=eth0 由于网卡的名字可能是eth0、em1、eno16777736等,--device制定的与目标机器网卡不一致时,会报错无法启动,顾不指定--device
# network --bootproto=static --ip=192.168.100.52 --netmask=255.255.255.0 --gateway=192.168.100.1 --nameserver=223.5.5.5,223.6.6.6 --onboot=on --ipv6=auto
# network --bootproto=dhcp --onboot=on --noipv6
# network --device team0 --activate --bootproto=static --ip=10.34.102.222 --netmask=255.255.255.0 --gateway=10.34.102.254 --nameserver=10.34.39.2 -teamslaves="p3p1'{\"prio\": -10, \"sticky\": true}',p3p2'{\"prio\": 100}'" --teamconfig="{\"runner\": {\"name\": \"activebackup\"}}"

# Reboot after installation
reboot

#Root password
rootpw --iscrypted $1$allgo$sjkKoGvJXV2AuBNFeHyxP.

# 加密密码生成
# 格式 openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
# 其中 random-phrase-here 为干扰码

#add user
# user --name=<username> [--groups=<list>] [--homedir=<homedir>] [--password=<password>] [--iscrypted] [--shell=<shell>] [--uid=<uid>]
user --name="centos" --password="$1$allgo$sjkKoGvJXV2AuBNFeHyxP." --iscrypted --uid=1000

# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
# timezone  Asia/Shanghai
timezone --ntpservers=110.75.186.247,cn.ntp.org.cn Asia/Shanghai
# --nontp Disable automatic starting of NTP service

# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
# autopart

# CentOS6 不支持xfs
# part / --asprimary --fstype="ext4" --size=20480
# part /boot --asprimary --fstype="ext4" --size=512
# part swap --asprimary --fstype="swap" --size=2048
# part /data --asprimary --fstype="ext4" --grow --size=1


# CentOS7 支持xfs
# part / --asprimary --fstype="xfs" --size=20480
# part /boot --asprimary --fstype="xfs" --size=512
# part swap --asprimary --fstype="swap" --size=2048
# part /data --asprimary --fstype="xfs" --grow --size=1

# CentOS7 使用LVM分区
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part pv.01 --size=1 --grow
volgroup centos pv.01
logvol  / --fstype="xfs" --vgname=centos  --size=10240  --name=root
logvol  /data  --fstype="xfs" --vgname=centos  --size=1  --grow  --name=data


# %pre部分脚本(系统安装前执行)系统在解析 ks.cfg 文件之后立即运行,而且必须以 %pre 命令开头。注意,你在 %pre 部分可以访问网络;然而,名称服务(name service)在此时还没有被配置,因此只有 IP 地址才能奏效。
%pre
set -x -v
exec 1>/tmp/ks-pre.log 2>&1

# Once root's homedir is there, copy over the log.
while : ; do
    sleep 10
    if [ -d /mnt/sysimage/root ]; then
        cp /tmp/ks-pre.log /mnt/sysimage/root/
        logger "Copied %pre section log to system"
        break
    fi
done &


curl "http://192.168.211.50/cblr/svc/op/trig/mode/pre/system/test" -o /dev/null
# Start pre_install_network_config generated code
# generic functions to be used later for discovering NICs
mac_exists() {
  [ -z "$1" ] && return 1

  if which ip 2>/dev/null >/dev/null; then
    ip -o link | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  elif which esxcfg-nics 2>/dev/null >/dev/null; then
    esxcfg-nics -l | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  else
    ifconfig -a | grep -i "$1" 2>/dev/null >/dev/null
    return $?
  fi
}
get_ifname() {
  if which ip 2>/dev/null >/dev/null; then
    IFNAME=$(ip -o link | grep -i "$1" | sed -e 's/^[0-9]*: //' -e 's/:.*//')
  elif which esxcfg-nics 2>/dev/null >/dev/null; then
    IFNAME=$(esxcfg-nics -l | grep -i "$1" | cut -d " " -f 1)
  else
    IFNAME=$(ifconfig -a | grep -i "$1" | cut -d " " -f 1)
    if [ -z $IFNAME ]; then
      IFNAME=$(ifconfig -a | grep -i -B 2 "$1" | sed -n '/flags/s/:.*$//p')
    fi
  fi
}

# Start of code to match cobbler system interfaces to physical interfaces by their mac addresses
#  Start eno16777736
# Configuring eno16777736 (00:0C:29:48:30:63)
if mac_exists 00:0C:29:48:30:63
then
  get_ifname 00:0C:29:48:30:63
  echo "network --device=$IFNAME --bootproto=static --ip=192.168.211.11 --netmask=255.255.255.0 --gateway=192.168.211.1 --hostname=test.mydomain.com" >> /tmp/pre_install_network_config
fi
# End pre_install_network_config generated code

# Enable installation monitoring

%end

# %packages 指令也支持下面的选项:
# --nobase,不要安装@Base 组.如果想创建一个很小的系统,可以使用这个选项.
# --resolvedeps,选项已经被取消了.目前依赖关系可以自动地被解析.
# --ignoredeps,选项已经被取消了.目前依赖关系可以自动地被解析.
# --ignoremissing,忽略缺少的软件包或软件包组,而不是暂停安装来向用户询问是中止还是继续安装.
# 例如:%packages --ignoremissing
%packages --ignoremissing --nobase
@Core
vim
wget
%end

# %post部分脚本系统安装后执行, DHCP配置网络没有配置dns服务器
%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1

%end

%post
set -x -v
exec 1>/root/ks-post.log 2>&1

# Start yum configuration
# curl "http://192.168.211.50/cblr/svc/op/yum/system/test" --output /etc/yum.repos.d/cobbler-config.repo

# End yum configuration



# Start post_install_network_config generated code

# create a working directory for interface scripts
mkdir /etc/sysconfig/network-scripts/cobbler
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/cobbler/

# set the gateway in the network configuration file
grep -v GATEWAY /etc/sysconfig/network > /etc/sysconfig/network.cobbler
echo "GATEWAY=192.168.211.1" >> /etc/sysconfig/network.cobbler
rm -f /etc/sysconfig/network
mv /etc/sysconfig/network.cobbler /etc/sysconfig/network

# set the hostname in the network configuration file
grep -v HOSTNAME /etc/sysconfig/network > /etc/sysconfig/network.cobbler
echo "HOSTNAME=test.mydomain.com" >> /etc/sysconfig/network.cobbler
rm -f /etc/sysconfig/network
mv /etc/sysconfig/network.cobbler /etc/sysconfig/network

# Also set the hostname now, some applications require it
# (e.g.: if we're connecting to Puppet before a reboot).
/bin/hostname test.mydomain.com

# Start configuration for eno16777736
echo "DEVICE=eno16777736" > /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
echo "HWADDR=00:0C:29:48:30:63" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
IFNAME=$(ip -o link | grep -i '00:0C:29:48:30:63' | sed -e 's/^[0-9]*: //' -e 's/:.*//')
if [ -f "/etc/modprobe.conf" ] && [ $IFNAME ]; then
    grep $IFNAME /etc/modprobe.conf | sed "s/$IFNAME/eno16777736/" >> /etc/modprobe.conf.cobbler
    grep -v $IFNAME /etc/modprobe.conf >> /etc/modprobe.conf.new
    rm -f /etc/modprobe.conf
    mv /etc/modprobe.conf.new /etc/modprobe.conf
fi
echo "TYPE=Ethernet" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
echo "IPADDR=192.168.211.11" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/cobbler/ifcfg-eno16777736
# End configuration for eno16777736

sed -i 's/ONBOOT=yes/ONBOOT=no/g' /etc/sysconfig/network-scripts/ifcfg-eth*

rm -f /etc/sysconfig/network-scripts/ifcfg-eno16777736
mv /etc/sysconfig/network-scripts/cobbler/* /etc/sysconfig/network-scripts/
rm -r /etc/sysconfig/network-scripts/cobbler
if [ -f "/etc/modprobe.conf" ]; then
cat /etc/modprobe.conf.cobbler >> /etc/modprobe.conf
rm -f /etc/modprobe.conf.cobbler
fi
# End post_install_network_config generated code




# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)

# Start koan environment setup
echo "export COBBLER_SERVER=192.168.211.50" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.211.50" > /etc/profile.d/cobbler.csh
# End koan environment setup

# begin Red Hat management server registration
# not configured to register to any Red Hat management server (ok)
# end Red Hat management server registration

# Begin cobbler registration
# skipping for system-based installation
# End cobbler registration

# Enable post-install boot notification

# Start final steps

curl "http://192.168.211.50/cblr/svc/op/ks/system/test" -o /root/cobbler.ks
curl "http://192.168.211.50/cblr/svc/op/trig/mode/post/system/test" -o /dev/null
# End final steps
%end

 

 

 

CentOS7x64下安装Cobbler

测试中发现,无法导入32位系统镜像,使用32位的CentOS安装Cobbler也不行,目前未解决。

 

# 安装环境
# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 

# uname -a
Linux localhost.localdomain 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


# cat /etc/redhat-release 
CentOS Linux release 7.1.1503 (Core) 
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

# rpm -qa cobbler
cobbler-2.6.10-1.el7.noarch

####################################################################################
#
#安装过程
#
####################################################################################
# 增加repo源
rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
# 或
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 安装Cobbler及相关软件
yum -y install httpd xinetd tftp-server dnsmasq rsync syslinux
yum -y install cobbler fence-agents pykickstart

# 关闭selinux
# vi /etc/selinux/config 
SELINUX=disabled

# 获取selinux状态
# getenforce

# 关闭iptables
systemctl stop firewalld
systemctl disable firewalld 

# 生成系统安装后,root的密码 (默认密码为 cobbler)
# 格式 openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
# 其中 random-phrase-here 为干扰码

# openssl passwd -1 -salt 'allgo' 'allgo.cc'                                 
$1$allgo$sjkKoGvJXV2AuBNFeHyxP.

# 修改Cobbler配置/etc/cobbler/settings
manage_dhcp:1
manage_dns:1
manage_tftpd:1
restart_dhcp:1
restart_dns:1
next_server:<服务器的 IP 地址>
server:<服务器的 IP 地址>
default_password_crypted: "$1$allgo$sjkKoGvJXV2AuBNFeHyxP."

# 修改 modules,使用dnsmasq作为DHCP、DNS服务器
# vi /etc/cobbler/modules.conf
[dns]
module = manage_dnsmasq

[dhcp]
module = manage_dnsmasq

[tftpd]
module = manage_in_tftpd

# 修改dnsmasq配置文件 /etc/dnsmasq.conf 
# vi /etc/dnsmasq.conf 

# Cobbler generated configuration file for dnsmasq
# $date
#

# resolve.conf .. ?
#no-poll
#enable-dbus
read-ethers
addn-hosts = /var/lib/cobbler/cobbler_hosts

dhcp-range=192.168.211.10,192.168.211.29,255.255.255.0
dhcp-ignore=tag:!known
dhcp-option=3,$next_server
dhcp-lease-max=1000
dhcp-authoritative
dhcp-boot=pxelinux.0
dhcp-boot=net:normalarch,pxelinux.0
dhcp-boot=net:ia64,$elilo

$insert_cobbler_system_definitions

# TFTP配置
# cat /etc/xinetd.d/tftp 
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operati