os: centos7 minimal


partition:

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048      976895      487424   83  Linux

/dev/sda2          976896    98631679    48827392   83  Linux

/dev/sda3        98631680   129880063    15624192   82  Linux swap / Solaris

/dev/sda4       129880064   488396799   179258368    5  Extended

/dev/sda5       129882112   488388607   179253248   83  Linux


network:

]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s25

TYPE=Ethernet

BOOTPROTO=static

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

NAME=enp0s25

UUID=f5aad67b-0b2e-46b9-b17d-126c9eaae4b1

DEVICE=enp0s25

ONBOOT=yes

IPADDR=123.140.248.88

NETMASK=255.255.255.0

GATEWAY=123.140.248.254


]# vi /etc/resolv.conf

search .

nameserver 210.220.163.82


selinux:

]# vi /etc/selinux/config

SELINUX=disabled


update:

]# yum update

]# yum install net-tools

]# reboot


kvm install:

# xming install in pc

https://sourceforge.net/projects/xming/


]# yum install qemu-kvm qemu-kvm-tools libvirt virt-install virt-manager virt-viewer virt-top dejavu-lgc-sans-fonts xorg-x11-xauth wget vim

]# systemctl start libvirtd

]# systemctl enable libvirtd

]# export NO_AT_BRIDGE=1

]# alis vi=vim

]# setterm -blength 0

]# mkdir /home/isos

]# cd /home/isos

]# wget http://ftp.daumkakao.com/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso 

]# virsh net-destroy default

]# virsh net-autostart default --disable

]# mkdir /root/rpms

]# cd /root/rpms

]# wget https://rdo.fedorapeople.org/openstack/openstack-kilo/rdo-release-kilo.rpm

]# rpm -Uvh rdo-release-kilo.rpm

]# yum install openvswitch

]# systemctl start openvswitch

]# systemctl enable openvswitch

]# vi /etc/sysconfig/network-scripts/ifcfg-ovsbr0

DEVICE=ovsbr0

ONBOOT=yes

DEVICETYPE=ovs

TYPE=OVSBridge

BOOTPROTO=static

IPADDR=192.168.100.1

NETMASK=255.255.255.0

HOTPLUG=no

ZONE=trusted


]# ifup ovsbr0

]# iptables -A POSTROUTING -s 192.168.100.0/24 -t nat -j MASQUERADE


]# vi /etc/libvirt/qemu/networks/public.xml

<network>

  <name>public</name>

  <forward mode='bridge'/>

  <bridge name='ovsbr0'/>

  <virtualport type='openvswitch'/>

</network>


]# vi /etc/libvirt/qemu/networks/private.xml

<network>

  <name>private</name>

  <forward mode='nat'/>

  <bridge name='virbr0' stp='on' delay='0'/>

  <mac address='52:54:00:e3:83:e1'/>

  <ip address='192.168.122.1' netmask='255.255.255.0'>

    <dhcp>

      <range start='192.168.122.2' end='192.168.122.254'/>

      <host mac='52:54:00:e5:22:c1' name='test-001' ip='192.168.122.2'/>

      <host mac='52:54:00:e5:22:c2' name='test-002' ip='192.168.122.3'/>

      <host mac='52:54:00:e5:22:c3' name='test-003' ip='192.168.122.4'/>

      <host mac='52:54:00:e5:22:c4' name='test-004' ip='192.168.122.5'/>

    </dhcp>

  </ip>

</network>


]# virsh net-define /etc/libvirt/qemu/networks/public.xml

]# virsh net-define /etc/libvirt/qemu/networks/private.xml

]# virsh net-start public

]# virsh net-start private

]# virsh net-autostart public

]# virsh net-autostart private


]# vi /etc/libvirt/qemu/test-001.xml

]# vi /etc/libvirt/qemu/test-002.xml

]# vi /etc/libvirt/qemu/test-003.xml

]# vi /etc/libvirt/qemu/test-004.xml

<domain type='kvm'>

  <name>test-001</name>

  <memory unit='KiB'>1048576</memory>

  <currentMemory unit='KiB'>1048576</currentMemory>

  <vcpu placement='static'>1</vcpu>

  <os>

    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>

    <boot dev='hd'/>

  </os>

  <features>

    <acpi/>

    <apic/>

  </features>

  <cpu mode='custom' match='exact'>

    <model fallback='allow'>Penryn</model>

  </cpu>

  <clock offset='utc'>

    <timer name='rtc' tickpolicy='catchup'/>

    <timer name='pit' tickpolicy='delay'/>

    <timer name='hpet' present='no'/>

  </clock>

  <on_poweroff>destroy</on_poweroff>

  <on_reboot>restart</on_reboot>

  <on_crash>restart</on_crash>

  <pm>

    <suspend-to-mem enabled='no'/>

    <suspend-to-disk enabled='no'/>

  </pm>

  <devices>

    <emulator>/usr/libexec/qemu-kvm</emulator>

    <disk type='file' device='disk'>

      <driver name='qemu' type='raw'/>

      <source file='/var/lib/libvirt/images/test-001.img'/>

      <target dev='vda' bus='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>

    </disk>

    <controller type='usb' index='0' model='ich9-ehci1'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x7'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci1'>

      <master startport='0'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0' multifunction='on'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci2'>

      <master startport='2'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x1'/>

    </controller>

    <controller type='usb' index='0' model='ich9-uhci3'>

      <master startport='4'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x2'/>

    </controller>

    <controller type='pci' index='0' model='pci-root'/>

    <controller type='virtio-serial' index='0'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>

    </controller>

    <interface type='network'>

      <mac address='52:54:00:05:d1:c1'/>

      <source network='public'/>

      <model type='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

    </interface>

    <interface type='network'>

      <mac address='52:54:00:e5:22:c1'/>

      <source network='private'/>

      <model type='virtio'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>

    </interface>

    <serial type='pty'>

      <target port='0'/>

    </serial>

    <console type='pty'>

      <target type='serial' port='0'/>

    </console>

    <channel type='unix'>

      <target type='virtio' name='org.qemu.guest_agent.0'/>

      <address type='virtio-serial' controller='0' bus='0' port='1'/>

    </channel>

    <channel type='spicevmc'>

      <target type='virtio' name='com.redhat.spice.0'/>

      <address type='virtio-serial' controller='0' bus='0' port='2'/>

    </channel>

    <input type='tablet' bus='usb'>

      <address type='usb' bus='0' port='1'/>

    </input>

    <input type='mouse' bus='ps2'/>

    <input type='keyboard' bus='ps2'/>

    <graphics type='spice' autoport='yes'>

      <listen type='address'/>

      <image compression='off'/>

    </graphics>

    <sound model='ich6'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>

    </sound>

    <video>

      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>

    </video>

    <redirdev bus='usb' type='spicevmc'>

      <address type='usb' bus='0' port='2'/>

    </redirdev>

    <redirdev bus='usb' type='spicevmc'>

      <address type='usb' bus='0' port='3'/>

    </redirdev>

    <memballoon model='virtio'>

      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>

    </memballoon>

  </devices>

</domain>


]# qemu-img convert test-001.img test-002.img 

]# qemu-img convert test-001.img test-003.img 

]# qemu-img convert test-001.img test-004.img 


]# virsh define test-001.xml

]# virsh define test-002.xml

]# virsh define test-003.xml

]# virsh define test-004.xml


]# virsh start test-001

]# virsh start test-002

]# virsh start test-003

]# virsh start test-004



test-001~ test-004

]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=static

IPADDR=192.168.100.2

NETMASK=255.255.255.0

GATEWAY=192.168.100.1


]# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=dhcp

ONBOOT=yes


]# yum remove NetworkManager


]# /usr/sbin/dhclient-script

506c506

<     make_resolv_conf

---

>     #make_resolv_conf

592c592

<             make_resolv_conf

---

>             #make_resolv_conf

608c608

<                 make_resolv_conf

---

>                 #make_resolv_conf


]# vi /etc/resolv.conf

search .

nameserver 210.220.163.82


etc

]# ovs-vsctl list-ports ovsbr0

vnet0

vnet2

vnet4

vnet6

[root@localhost qemu]# brctl show

bridge name     bridge id               STP enabled     interfaces

virbr0          8000.525400e383e1       yes             virbr0-nic

                                                        vnet1

                                                        vnet3

                                                        vnet5

                                                        vnet7




http://prolinuxhub.com/configure-start-up-scripts-for-ovs-on-centos-and-red-hat/


[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s25

TYPE=OVSPort

BOOTPROTO=none

DEVICE=enp0s25

DEVICETYPE=ovs

ONBOOT=yes

HOTPLUG=no

OVS_BRIDGE=ovsbr0


[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ovsbr0

DEVICE=ovsbr0

ONBOOT=yes

DEVICETYPE=ovs

TYPE=OVSBridge

BOOTPROTO=static

IPADDR=123.140.248.88

NETMASK=255.255.255.0

GATEWAY=13.140.248.254

HOTPLUG=no










'Virtualization' 카테고리의 다른 글

ceph  (0) 2017.01.19
LVM2  (0) 2017.01.12


from boto.s3.connection import S3Connection


access_key = "*****5JJPZD6WYG*****"

secret_key = "*****GnYf/bmdJ9NfkveFF+Mb8IPjVIGybC*****"

region = "s3-ap-northeast-2.amazonaws.com"

conn = S3Connection(access_key, secret_key, host=region)

bucket = conn.get_bucket('ghpark-mp3')

for key in bucket.list():

    print key.name

 


regions 

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html


seoul region을 명시해줘야 400 에러 발생하지 않음 ㅡㅜ 


http://boto.cloudhackers.com/en/latest/s3_tut.html


import os

import fnmatch

from boto.s3.connection import S3Connection


conn = S3Connection('*****5JJPZD6WYG*****','*****GnYf/bmdJ9NfkveFF+Mb8IPjVIGybC*****', host="s3-ap-northeast-2.amazonaws.com")

bucket = conn.get_bucket('ghpark-mp3')

for key in bucket.list():

    print key.name

    # download

    #key.get_contents_to_filename(key.name)

    # delete

    #key.delete()


for f in os.listdir("."):

    if fnmatch.fnmatch(f, "*.mp3"):

        f = f.encode("UTF-8")

        k = bucket.new_key(f)

        # upload

        k.set_contents_from_filename(f)



s3bucket 용량 구하는거 ... 깔끔하네

https://gist.github.com/robinkraft/2667939



import boto

s3 = boto.connect_s3(aws_id, aws_secret_key)


# based on http://www.quora.com/Amazon-S3/What-is-the-fastest-way-to-measure-the-total-size-of-an-S3-bucket


def get_bucket_size(bucket_name):

    bucket = s3.lookup(bucket_name)

    total_bytes = 0

    n = 0

    for key in bucket:

        total_bytes += key.size

        n += 1

        if n % 2000 == 0:

            print n

    total_gigs = total_bytes/1024/1024/1024

    print "%s: %i GB, %i objects" % (bucket_name, total_gigs, n)

    return total_gigs, n


bucket_list = []

bucket_sizes = []


for bucket_name in bucket_list:

    size, object_count = get_bucket_size(bucket_name)

    bucket_sizes.append(dict(name=bucket_name, size=size, count=object_count))


print "\nTotals:"

for bucket_size in bucket_sizes:

    print "%s: %iGB, %i objects" % (bucket_size["name"], bucket_size["size"], bucket_size["count"]) 




'Python' 카테고리의 다른 글

Django + djangorestframework + django_rest_swagger 시작  (0) 2017.02.01
Pika Python AMQP Client Library  (0) 2017.01.31
daemonizing  (0) 2016.12.22
Threading  (0) 2016.12.22
pidlockfile.py for windows  (0) 2016.12.19

데몬으로 python script 를 실행할때 직접 daemonizing 코드를 구형하여 만들었는데

python-daemon 이라는 패키지를 사용해보니 cmdline 에서 start/stop/restart 도 지원하고 filelock 도 지원한다.

쓸만해보여서 정리해둠 


wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
tar zxf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/home/apps/python2.7 --enable-unicode=ucs4 --enable-shared
make
make install
wget --no-check-certificate https://pypi.python.org/packages/25/4e/1b16cfe90856235a13872a6641278c862e4143887d11a12ac4905081197f/setuptools-28.8.0.tar.gz
tar zxf setuptools-28.8.0.tar.gz
cd setuptools-28.8.0
python2.7 setup.py build
python2.7 setup.py install
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
python2.7 get-pip.py
pip install python-daemon
 
mkdir /daemon_sample
cd /daemon_sample
mkdir  bin lib log run
cd bin
vi daemon_sample.py
--------------------------------------------------------------------------------------------
#!/home/apps/python2.7/bin/python
# -*- coding: UTF-8 -*-
import time
from daemon.runner import DaemonRunner
class TestDaemon(object):
    def __init__(self):
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/tty'
        self.stderr_path = '/dev/tty'
        self.pidfile_timeout = 0
        self.pidfile_path="/usr/mgmt/apm_package_manager/run/TestDaemon.pid"
    def run(self):
        while 1:
            time.sleep(3)
DaemonRunner(TestDaemon()).do_action()
--------------------------------------------------------------------------------------------
chmod 700 daemon_sample.py
./daemon_sample.py
usage: test.py start|stop|restart
 
 
./daemon_sample.py start
started with pid 24751
 
 
./daemon_sample.py start
  File "./test.py", line 19, in <module>
    DaemonRunner(TestDaemon()).do_action()
  File "/home/apps/python2.7/lib/python2.7/site-packages/daemon/runner.py", line 274, in do_action
    func(self)
  File "/home/apps/python2.7/lib/python2.7/site-packages/daemon/runner.py", line 187, in _start
    raise error
daemon.runner.DaemonRunnerStartFailureError: PID file '/usr/mgmt/apm_package_manager/run/TestDaemon.pid' already locked


'Python' 카테고리의 다른 글

Pika Python AMQP Client Library  (0) 2017.01.31
s3 example  (0) 2016.12.28
Threading  (0) 2016.12.22
pidlockfile.py for windows  (0) 2016.12.19
cygwin + ssh + rsync  (0) 2016.12.10

+ Recent posts