cobbler無人值守批量安裝Linux系統

来源:http://www.cnblogs.com/f-ck-need-u/archive/2017/08/11/7347883.html
-Advertisement-
Play Games

本文目錄: 1.1 pxe安裝系統 1.2 cobbler基本介紹 1.3 安裝和配置cobbler 1.3.1 安裝cobbler 1.3.2 配置dhcp和tftp 1.4 cobbler從本地光碟安裝系統 1.4.1 生成distro 1.4.2 提供kickstart文件 1.4.3 提供p ...



本文目錄:

1.1 pxe安裝系統

1.2 cobbler基本介紹

1.3 安裝和配置cobbler

1.3.1 安裝cobbler

1.3.2 配置dhcp和tftp

1.4 cobbler從本地光碟安裝系統

1.4.1 生成distro

1.4.2 提供kickstart文件

1.4.3 提供profile

1.4.4 開始安裝

1.5 比pxe+kickstart好的地方

1.6 讓新機器自動執行腳本


1.1 pxe安裝系統

pxe的大致過程如下圖。

其中pxelinux.0為bootloader。pxelinux.cfg目錄下的文件(一般使用預設的default文件)定義了安裝操作系統前的菜單項,如kernel和Initrd的路徑,kickstart的路徑等。

首先客戶端請求pxe伺服器上的dhcp,dhcp上指定了next-server和filename,它們分別是tftpd的地址和pxelinux.0的路徑;然後客戶端請求tftpd獲取pxelinux.0,執行pxelinux.0後將引導進入安裝界面,隨後獲取pxelinux.cfg目錄下的文件並讀取其中的配置,從中獲取kernel和initrd的路徑所在,如果有定義kickstart項則還會去獲取kickstart文件並讀取配置;再然後客戶端請求獲取kernel和initrd文件,以展開內核併進入到根文件系統;最後客戶端獲取完成系統安裝所需的其他文件,這些文件可以是在pxe的本地,也可以是互聯網上等能獲取到的地方。

在閱讀本文之前,如果不懂pxe+kickstart,建議先學習下,對學習cobbler很有幫助。可以參考我所寫的pxe+kickstart文章。

 

1.2 cobbler基本介紹

cobbler可以看作是一個更多功能的pxe,它實現系統安裝和pxe也差不多,需要的文件和過程大致都一樣。

cobbler能自動管理dns/tftp/dhcp/rsync這四個服務(但似乎對tftp的管理有點bug,需要手動啟動tftp),且cobbler依賴於httpd(pxe支持http/nfs/ftp)。

基本的系統安裝,cobbler只需生成一個distro和一個profile即可。

distro相當於一個鏡像,它提供安裝系統過程中所需的一切文件,如vmlinuz,initrd以及rpm包等。

profile的作用是為了自動修改pxelinux.cfg/default文件,每生成或修改一次profile,都會在default文件中修改或追加對應的label。

除了distro/profile之外,cobbler還管理system/images/repositories等,但是用的很少。

1.3 安裝和配置cobbler

1.3.1 安裝cobbler

cobbler在epel源中提供。由於還依賴於httpd、dhcp,所以httpd和dhcp也應該裝上。

yum -y install cobbler cobbler-web pykickstart debmirror httpd dhcp

其中cobbler-web是提供web管理界面的,pykicstart是檢查kicstart文件語法錯誤的,debmirror是維護debian源的工具,此處用不上但有依賴關係,所以裝上。

安裝後,在/etc/cobbler生成以下文件。

[root@xuexi ~]# cd /etc/cobbler/

[root@xuexi cobbler]# ls
auth.conf       distro_signatures.json  modules.conf    reporting           tftpd.template  zone_templates
cheetah_macros  dnsmasq.template        mongodb.conf    rsync.exclude       users.conf
cobbler_bash    import_rsync_whitelist  named.template  rsync.template      users.digest
completions     iso                     power           secondary.template  version
dhcp.template   ldap                    pxe             settings            zone.template

先啟動httpd,再啟動cobblerd。

[root@xuexi cobbler]# systemctl start httpd.service
[root@xuexi cobbler]# systemctl start cobblerd.service
[root@xuexi cobbler]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1298/sshd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1402/master        
tcp        0      0 127.0.0.1:25151             0.0.0.0:*                   LISTEN      14091/python2       
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2261/mysqld        
tcp        0      0 :::22                       :::*                        LISTEN      1298/sshd          
tcp        0      0 ::1:25                      :::*                        LISTEN      1402/master        
tcp        0      0 :::443                      :::*                        LISTEN      14037/httpd        
tcp        0      0 :::80                       :::*                        LISTEN      14037/httpd

啟動之後,首先執行cobbler check檢查配置是否正確。根據提示修改相關的配置項。

[root@xuexi cobbler]# cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
3 : some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
4 : change 'disable' to 'no' in /etc/xinetd.d/rsync
5 : comment out 'dists' on /etc/debmirror.conf for proper debian support
6 : comment out 'arches' on /etc/debmirror.conf for proper debian support
7 : ksvalidator was not found, install pykickstart
8 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.

第一和第二個問題:

[root@xuexi cobbler]# vim /etc/cobbler/settings

next_server: 172.16.10.10
server: 172.16.10.10

第三個問題:獲取pxelinux.0和menu.c32文件(對於centos來說只需這兩個文件),可以像pxe一樣從syslinux包中手動複製到/var/lib/cobbler/loaders目錄下,也可以執行cobbler get-loaders自動下載,但要求聯網。

[root@xuexi cobbler]# cobbler get-loaders

第四個問題:有可能該問題不是如此的,而是說要將rsyncd.service使用給start且enable,只需systemctl enable rsyncd,systemctl start rsyncd。

[root@xuexi cobbler]# vim /etc/xinetd.d/rsync
disable=no
[root@xuexi cobbler]# service xinetd start

第5、6個問題,註釋掉/etc/debmirror.conf中相關項即可。

第7個問題:因為之前安裝的時候寫成了pykicstart,所以出錯了這裡。

[root@xuexi cobbler]# yum -y install pykickstart

第8個問題:

[root@xuexi cobbler]# openssl passwd -1 -salt `openssl rand -hex 8` '123456'
$1$77e1022c$D9rxuxUWdc0NN46gzj9XT.
[root@xuexi cobbler]# vim /etc/cobbler/settings
default_password_crypted: "$1$77e1022c$D9rxuxUWdc0NN46gzj9XT."

第九個問題和電源管理有關,不用管了。直接重啟cobbler,然後cobbler sync。

[root@xuexi cobbler]# service cobblerd restart

[root@xuexi cobbler]# cobbler check
The following are potential configuration items that you may want to fix:
1 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
[root@xuexi cobbler]# cobbler sync

 cobbler sync命令用於將tftpboot目錄和/var/www/cobbler保持最新,當/var/lib/cobbler或者kickstart文件發生了變化,應該執行一次cobbler sync或者直接重啟cobbler服務。

1.3.2 配置dhcp和tftp

如果在/etc/cobbler/setting中設置了manage_dhcp:1,表示由cobbler管理dhcp(預設為0即人為手動管理),則cobbler管理的dhcp的配置模板/etc/cobbler/dhcp.template會覆蓋/etc/dhcp/dhcpd.conf中配置,所以應該修改dhcp.template。

此處採用預設的不由cobbler管理dhcp。

[root@xuexi cobbler]# yum-y install dhcp
[root@xuexi cobbler]# vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
default-lease-time 259200;
max-lease-time 518400;
subnet 172.16.10.0 netmask 255.255.255.0 {
        range 172.16.10.20 172.16.10.50;
        option subnet-mask 255.255.255.0;
        next-server 172.16.10.10;          # tftp的地址
        filename "pxelinux.0";             # pxelinux.0的路徑,此為tftp根目錄(/var/lib/tftpboot)的相對路徑
}
[root@xuexi cobbler]# service dhcpd restart

關於tftp,在/etc/cobbler/settings中預設啟用了由cobbler管理tftp,所以此處無需配置它。只要知道它的根目錄為/var/lib/tftpboot即可。但是如果後面裝系統的時候如果找不到tftp(應該是cobbler管理tftp的bug),則手動啟動tftp即可。

1.4 cobbler從本地光碟安裝系統

1.4.1 生成distro

生成distro的方法有多種,可以從本地鏡像導入生成,也可以根據網路上的資源生成。顯然,從本地生成的效率是最好的。

從本地導入的過程實際上是將系統鏡像中的文件複製到/var/www/cobbler/目錄(預設)下。

mkdir /mnt
mount /dev/cdrom /mnt
cobbler import --name=CentOS7.2 --path=/mnt

等待導入完成,則表示distro生成完成。

[root@xuexi cobbler]# ls -l /var/www/cobbler/images/CentOS7.2-x86_64/
total 38056
-r--r--r-- 3 root root 34815427 Oct 24  2014 initrd.img
-r-xr-xr-x 3 root root  4152336 Oct 24  2014 vmlinuz
[root@xuexi cobbler]# ls -l /var/www/cobbler/ks_mirror/CentOS7.2/   # 此目錄完全來源於鏡像
total 340
-r--r--r-- 1 root root     14 Oct 24  2014 CentOS_BuildTag
dr-xr-xr-x 3 root root   4096 Oct 24  2014 EFI
-r--r--r-- 1 root root    212 Nov 28  2013 EULA
-r--r--r-- 1 root root  18009 Nov 28  2013 GPL
dr-xr-xr-x 3 root root   4096 Oct 24  2014 images
dr-xr-xr-x 2 root root   4096 Oct 24  2014 isolinux
dr-xr-xr-x 2 root root 278528 Oct 24  2014 Packages
-r--r--r-- 1 root root   1354 Oct 20  2014 RELEASE-NOTES-en-US.html
dr-xr-xr-x 2 root root   4096 Oct 24  2014 repodata
-r--r--r-- 1 root root   1706 Nov 28  2013 RPM-GPG-KEY-CentOS-6
-r--r--r-- 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 1 root root   1734 Nov 28  2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 root root   3380 Oct 24  2014 TRANS.TBL

確保url路徑http://172.16.10.10/cobbler/ks_mirror/CentOS7.2/是有效的。

 

1.4.2 提供kickstart文件

以下是CentOS7的Kickstart內容。如果要改為適合CentOS6的內容,只需將keyboard項設置為"keyboard us",並修改下分區方式(如有必要的話)以及%post腳本段的內容即可。

[root@xuexi ~]# vim /var/lib/cobbler/kickstarts/CentOS7.2.ks
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree
# Use text mode install
text
# Firewall configuration
firewall --disabled
firstboot --disable
# ignoredisk --only-use=sda   # 此項是CentOS7預設的項,但cobbler編譯ks文件時不支持此語法,所以必須將此項註釋掉
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --onboot=yes --bootproto=dhcp --device=eth0 --noipv6
network  --hostname=node1.xuexi.com
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $6$KIPkwGVYqtjHln80$quxmkE5MKKA2LyzLOAc/s3FWH/jX76sObq6hqwOsEBoeMc/wIrzGG4xm72lkXwLeOfRLS/sl5vdajY9j34D4J. 
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="quiet crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="xfs" --size=250
part swap --fstype="swap" --size=2000
part / --asprimary --fstype="xfs" --grow --size=5000

# 如果是要LVM分區,則考慮以下分區
# part /boot --fstype ext4 --size=100
# part swap --fstype=swap --size=2048
# part pv26 --size=100 --grow
# volgroup VG00 --pesize=32768 pv26
# logvol / --fstype ext4 --name=LVroot --vgname=VG00 --size=29984
# logvol /data --fstype ext4 --name=LVdata --vgname=VG00 --size=100 --grow

%post
rm -f /etc/yum.repos.d/*
cat >>/etc/yum.repos.d/my.repo<<eof
[base]
name=sohu
baseurl=http://mirrors.sohu.com/centos/7/os/x86_64/
gpgcheck=0
enable=1
[epel]
name=epel
baseurl=http://mirrors.aliyun.com/epel/7Server/x86_64/
enable=1
gpgcheck=0
eof
sed -i "s/rhgb //" /boot/grub2/grub.cfg
sed -i "/UUID/d" /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DNS1=114.114.114.114" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "UseDNS no" >> /etc/ssh/sshd_config
sed -i "s/GSSAPIAuthentication yes/GSSAPIAuthentication no/" /etc/ssh/ssh_config
sed -i "s/^SELINUX=.*$/SELINUX=disabled/" /etc/sysconfig/selinux
systemctl disable firewalld
%end

%packages
@base
@core
@development
@platform-devel
kexec-tools
lftp
tree
lrzsz

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

 上面的url也可以寫成url --url="http://172.16.10.10/cobbler/ks_mirror/CentOS7.2/"。

 

1.4.3 提供profile

在導入鏡像生成distro的過程中,會自動生成一個profile。

[root@xuexi cobbler]# cobbler profile list
   CentOS7.2-x86_64

該profile預設使用的kickstart是/var/lib/cobbler/kickstarts/sample_end.ks,所以需要修改此項。

[root@xuexi cobbler]# cobbler profile report --name=CentOS7.2-x86_64
Name                           : CentOS7.2-x86_64
TFTP Boot Files                : {}
Comment                        : 
DHCP Tag                       : default
Distribution                   : CentOS7.2-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.ks
Kickstart Metadata             : {}
Management Classes             : []
Management Parameters          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
Template Files                 : {}
Virt Auto Boot                 : 1
Virt Bridge                    : xenbr0
Virt CPUs                      : 1
Virt Disk Driver Type          : raw
Virt File Size(GB)             : 5
Virt Path                      : 
Virt RAM (MB)                  : 512
Virt Type                      : kvm
[root@xuexi cobbler]# cobbler profile edit --name=CentOS7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7.2.ks
[root@xuexi cobbler]# cobbler profile report
--name=CentOS7.2-x86_64 | grep -i kickstart Kickstart : /var/lib/cobbler/kickstarts/CentOS7.2.ks Kickstart Metadata : {}

對於centos7系列,則加上內核啟動參數net.ifnames和biosdevname使得網卡名使用ethN系列而不使用enoXXXXXXX這樣的隨機名稱。

[root@xuexi cobbler]# cobbler profile edit --name=CentOS7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7.2.ks --kopts="net.ifnames=0 biosdevname=0"
[root@xuexi cobbler]# cobbler profile report --name=CentOS7.2-x86_64 | grep -Ei 'kernel|kickstart'                                                  
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS7.2.ks Kickstart Metadata : {}

當然,不使用自生成的profile,自己添加一個profile也可以,同時還可以設置profile選項,如"--kickstart"項。如下:其中"--distro"指定該profile是添加到哪個distro下的。

[root@xuexi cobbler]# cobbler profile add --name=CentOS7.2.1-x86_64 --distro=CentOS7.2-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS7.2.ks

實際上,每添加一個profile都是在向/var/lib/tftpboot/pxelinux.cfg/default中添加一個label。

[root@xuexi cobbler]# cat /var/lib/tftpboot/pxelinux.cfg/default   
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
        MENU LABEL (local)
        MENU DEFAULT
        LOCALBOOT -1

LABEL CentOS7.2-x86_64
        kernel /images/CentOS7.2-x86_64/vmlinuz
        MENU LABEL CentOS7.2-x86_64
        append initrd=/images/CentOS7.2-x86_64/initrd.img ksdevice=bootif lang=  text net.ifnames=0 biosdevname=0 kssendmac  ks=http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2-x86_64
        ipappend 2

LABEL CentOS7.2.1-x86_64
        kernel /images/CentOS7.2-x86_64/vmlinuz
        MENU LABEL CentOS7.2.1-x86_64
        append initrd=/images/CentOS7.2-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64
        ipappend 2

MENU end

也就是說,其實可以不用生成profile,自己手動編輯label也可以。

預設使用的菜單背景圖片是menu.c32,此處我改為vesamenu.c32,該背景圖片是從syslinux包中提取的,背景圖片而已,看個人喜好了。另外預設菜單等待時間是2秒,在自動安裝的環境中,可以將其設置的短些。並且進入菜單預設停留在local,即從本地啟動系統,但是此時系統還沒裝,所以要實現自動化,建議修改此項。

以下是修改後的項。

DEFAULT vemamenu
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 20
TOTALTIMEOUT 6000
ONTIMEOUT CentOS7.2-x86_64

LABEL local
        MENU LABEL (local)
        LOCALBOOT -1

LABEL CentOS7.2-x86_64
        kernel /images/CentOS7.2-x86_64/vmlinuz
        MENU DEFAULT
        MENU LABEL CentOS7.2-x86_64
        append initrd=/images/CentOS7.2-x86_64/initrd.img ksdevice=bootif lang=  text net.ifnames=0 biosdevname=0 kssendmac  ks=http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2-x86_64
        ipappend 2

LABEL CentOS7.2.1-x86_64
        kernel /images/CentOS7.2-x86_64/vmlinuz
        MENU LABEL CentOS7.2.1-x86_64
        append initrd=/images/CentOS7.2-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64
        ipappend 2

MENU end

在開始安裝之前,要確保該ks路徑是有效的且kickstart內容是正確的。有時候提供的Kickstart內容錯誤了,在製作成profile的時候不會報錯,但實際上瀏覽器訪問該ks路徑的內容提示錯誤。例如,訪問CentOS7.2.1-x86_64這個LABEL的kickstart文件,將其ks文件url地址http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64輸入瀏覽器中。如果得到如下結果,則表示出錯了,很大的可能是cobbler不支持kickstart中的某指令,這個需要慢慢檢查。

# This kickstart had errors that prevented it from being rendered correctly.
# The cobbler.log should have information relating to this failure.

修改kickstart文件後,需要重新編譯profile載入新的kickstart文件。只需使用cobbler profile edit --name=XXXXX --kickstart=YYYYY即可重新編譯XXXXX這個profile,或者執行cobbler sync命令。直到瀏覽器中能獲取到kickstart的內容時才算成功。

或者,使用cobbler profile getks --name=XXXXX命令獲取名為XXXXX的profile的ks內容。

總之,必須要保證能正確獲取到ks內容。

1.4.4 開始安裝

準備一個新的機器開機就會自動進入菜單,2-3秒超時後自動進行安裝,安裝完成後自動重啟,重啟時自動從本地啟動。

所以,除了對新機器進行開機,其他的一切完完全全是全自動的。

建議在真正開始安裝前,將dhcpd/rsyncd/tftp/cobbler等給重啟一遍,防止中間改過哪些地方忘記重啟而導致裝機時出錯。

1.5 比pxe+kickstart好的地方

僅就cobbler基本功能而言,它跟pxe的能力基本是一樣的,只是提供了更多花哨的功能。

但cobbler能夠使用變數,能夠通過幾個命令自動完成文件複製,修改等繁瑣的動作,另外它提供了api介面,常用的是它的圖形界面。在這一點上,它還是不錯的。

1.6 讓新機器自動執行腳本

有些時候新機器上要進行很多配置,在kickstart的%post段也可以配置,但是這裡能進行的配置是有限的。

可以在cobbler服務端寫好要執行的腳本,然後在新機器上將腳本使用scp複製過去,但是scp複製需要確認和輸入密碼,所以需要在kickstart的選包部分指定安裝expect包,然後使用expect進行非交互scp。

最後在%post段直接執行此腳本即可。

 

回到系列文章大綱:http://www.cnblogs.com/f-ck-need-u/p/7048359.html

轉載請註明出處:http://www.cnblogs.com/f-ck-need-u/p/7347883.html

註:若您覺得這篇文章還不錯請點擊下右下角的推薦,有了您的支持才能激發作者更大的寫作熱情,非常感謝!


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Android MediaRecorder自定義解析度 工作這麼久了,確實積累了不少東西,但都是以文檔的形式存在U盤裡的,為什麼不寫博客呢?因為懶啊!!!總感覺博客太難寫了(大概是上學時候寫作文恐懼症 的後遺症吧……),不過現在看看那些積累的有些是自己總結,但也有不少是綜合網上各位大佬的文章提煉出來 ...
  • Android Studio 是個發工具,其自身帶調式環境是很強大的,我們要擺脫只會使用Log列印日誌的低效的方法,掌握高級調試技巧對每個Android開發者都是很必要的,廢話少說,直入正題 調試方式:通過下麵方法進入調試 運行調試:點擊齒輪運行按鈕,IDE出現調試視窗; 附加進程: 如果App正在 ...
  • 近期在做一個答題類型的APP,而其中最重要的是答題卡。而答題卡要如何做? 1.將數據插入到SQLite資料庫中 2.建立entity實體包,創建實體類,封裝。 3.創建實體與view的List集合 4.迴圈讀取數據,加入到實體集合中 5.根據實體集合(size)進行迴圈,將佈局文件轉化為view,加 ...
  • 1、創建應用 獲取AK (我理解為Application key) 通過百度賬號登錄百度地圖開放平臺,進入API控制台 http://lbsyun.baidu.com/apiconsole/key 創建自己的應用,輸入應用名稱 ,選擇Android SDK 應用類型,選擇需要的服務(預設全選) 輸入 ...
  • 1. 泛型 AysncTask Params:啟動任務時傳入的參數,通過調用asyncTask.execute(param)方法傳入。 Progress:後臺任務執行的進度,若不用顯示進度條,則不需要指定。 Result:後臺任務結束時返回的結果。 2. 重要方法 doInBackground(Pa ...
  • 一,效果圖。 二,代碼。 ViewController.m ...
  • Desktop:基本的桌面系統,包括常用的桌面軟體,如文檔查看工具;Minimal Desktop:基本的桌面系統,包含的軟體更少;Minimal:基本的系統,不包含任何可選的軟體包;Basic Server:安裝的基本系統的平臺支持,不包含桌面;Database Server:基本系統平臺,加上M... ...
  • 1.1 wrap簡介 wrap工作在內核空間和應用程式中間的庫層次中。在內核接受到數據包准備傳送到用戶空間時都會經過庫層次,對於部分(只是部分)應用程式會在經過庫層次時會被wrap庫文件阻擋下來檢查一番,如果允許通過則交給應用程式。 1.2 查看是否支持wrapper wrap只會檢查tcp數據包, ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...