• [热门活动] 【我与华为云认证】我与华为云相识之路
    华为云最早的接触是在学校的红帽社团,因为我的专业是云计算所以我参加了与云计算有关的社团,恰巧社团中有些活动是华为云的,也是从此打开了我与华为云的相识之路我学的课程大致上是这样的,云导论、linux、网络基础、java、虚拟化等,这些课程主要是围绕了openstack和虚拟化以及docker,同时我也参加了一些大赛,但是在此之中我的linux老师是红帽认证持有者同时也跟华为的一些授权伙伴有联系(因为我的linux老师是红帽社团的指导老师,而老师对于华为的交换机数通这块无论是硬件还是技术都很认可,也参加过许多活动因此认识了一些伙伴),而恰好当时华为ICT的大赛开始报名我比较幸运的参加了,也是在那个时候第一次接触了华为的活动,也正是这次活动我对于华为云有了初步的认识。所以我除了学习了原生的openstack,我在空余时间也在华为云学院这里也会看一些活动和课程向大厂学习,也就是在这个过程中我参加了一部分的活动考取了微认证,我第一份工作在华为云授权的合作伙伴也是在这里考取了第一个职业认证HCIP-cloudservice(云服务),这个职业认证更多的是对于华为云云上的产品考察,通过这个考证可以很好地掌握云产品和大部分的云常识,而微认证就比较细节性的面向于某一领域的深挖性学习,大家可以根据个人喜好各取所需的去学习(职业认证和微认证都分为很多种,职业认证分三个等级难度是比较大的,我在2020年花钱培训学习了cloud computing的IP但是无奈遇到了疫情所以耽误了)。这些微认证或职业认证可以在写简历的时候可以作为一个证明,同时这些认证享有众多福利权限!1.证明你学习过这个板块的知识,你对该认证的理论与技能有一定的把握2.既然是华为云的职业认证或者是微认证,有华为云大厂的加持会比没有认证的同学更加具有一定的优势3.官方认证证书4.华为云产品优惠使用权优先享有5.华为云新产品的使用权6.沙箱实验室免费使用权7.华为全连接大会嘉宾名额优先享有权8.华为云面试推荐优先享有权9.成为华为云合作伙伴10.华为云云享专家11.认证专家线下交流会具体的有很多,这里就不详细的罗列啦,努力就会有收获的,冲鸭!在这里也有一点心得分享给大家,对于学习这件事情最好是有规划且要耐心坚持下去,因为信息技术计算机这个领域比较大,虽然很多的知识与技术是相互的(比如开发也分前后端)但最好还是有一个专精,懂得多虽然是一件好事但同时也要谨记切勿邯郸学步,希望大家可以多多关注我,以后我会在论坛上分享一些干货,欢迎大家来批评吐槽,希望能和大家一起进步!
  • [交流分享] linux yum 查看软件包和软件包组
    ### ECS信息 * 规格:通用入门型 | t6.large.1 | 2vCPUs | 2GB * 镜像:openEuler 20.03 64bit | 公共镜像   ### linux yum 查看软件包和软件包组 #### 查看仓库及其状态 ``` bash # yum repolist all repo id repo name status EPOL EPOL enabled OS OS enabled debuginfo debuginfo enabled everything everything enabled source source enabled update update disabled ``` #### 查看yum的版本信息 ``` bash # yum info yum Last metadata expiration check: 2:21:15 ago on Tue 23 Mar 2021 07:59:26 PM CST. Installed Packages Name : yum Version : 4.2.15 Release : 8.oe1 Architecture : noarch Size : 4.0 Source : dnf-4.2.15-8.oe1.src.rpm Repository : @System From repo : anaconda Summary : Package manager URL : https://github.com/rpm-software-management/dnf License : GPLv2+ and GPLv2 and GPL Description : Utility that allows users to manage packages on their systems.\ : It supports RPMs, modules and comps groups & environments. ``` #### 查看已安装和未安装的软件包组 ``` bash # yum grouplist Last metadata expiration check: 2:21:55 ago on Tue 23 Mar 2021 07:59:26 PM CST. Available Environment Groups: Minimal Install Server Virtualization Host Available Groups: Container Management Development Tools Headless Management Legacy UNIX Compatibility Network Servers Scientific Support Security Tools System Tools Smart Card Support ``` ### 查看指定软件包组的信息 ``` bash # yum groupinfo Server Last metadata expiration check: 2:25:09 ago on Tue 23 Mar 2021 07:59:26 PM CST. Environment Group: Server Description: An integrated, easy-to-manage server. no group 'debugging' from environment 'server-product-environment' Mandatory Groups: Container Management Core Hardware Support Headless Management Server product core Standard Optional Groups: Basic Web Server DNS Name Server FTP Server File and Storage Server Hardware Monitoring Utilities Infiniband Support Mail Server Network File System Client Network Servers Performance Tools Remote Management for Linux Virtualization Hypervisor Windows File Server ```   ### 帮助文档(部分) ``` bash # yum --help usage: yum [options] COMMAND List of Main Commands: alias List or create command aliases autoremove remove all unneeded packages that were originally installed as dependencies check check for problems in the packagedb check-update check for available package upgrades clean remove cached data deplist List package's dependencies and what packages provide them distro-sync synchronize installed packages to the latest available versions downgrade Downgrade a package group display, or use, the groups information help display a helpful usage message history display, or use, the transaction history info display details about a package or group of packages install install a package or packages on your system list list a package or groups of packages makecache generate the metadata cache mark mark or unmark installed packages as installed by user. module Interact with Modules. provides find what package provides the given value reinstall reinstall a package remove remove a package or packages from your system repolist display the configured software repositories repoquery search for packages matching keyword repository-packages run commands on top of all packages in given repository search search package details for the given string shell run an interactive YUM shell swap run an interactive YUM mod for remove and install one spec updateinfo display advisories about packages upgrade upgrade a package or packages on your system upgrade-minimal upgrade, but only 'newest' package match which fixes a problem that affects your system List of Plugin Commands: ...... ```   ### 参考资料 * https://blog.csdn.net/yaoshixian/article/details/86298705   ### 学习资料 * openEuler-官网 openeuler.org/zh * openEuler-B站 space.bilibili.com/527064077 * openEuler-慕课 openeuler.org/zh/learn/mooc * openEuler-文档 openeuler.org/zh/documentation   欢迎各位同学来讨论~!
  • [交流分享] linux rpm 查看已安装的软件包信息
    ### ECS信息 * 规格:通用入门型 | t6.large.1 | 2vCPUs | 2GB * 镜像:openEuler 20.03 64bit | 公共镜像   ### linux rpm 查看已安装的软件包信息 #### 查看所有已经安装的软件包 ``` bash # rpm -qa tcpdump-4.9.3-3.oe1.x86_64 perl-ExtUtils-Install-2.14-419.oe1.noarch ncurses-base-6.1-14.oe1.noarch parted-3.3-2.oe1.x86_64 perl-Module-Load-0.32-418.oe1.noarch xkeyboard-config-2.24-6.oe1.noarch tar-1.30-11.oe1.x86_64 ...... ``` #### 查看已安装的软件包信息 ``` bash # rpm -qi dnf-4.2.15-8.oe1.noarch Name : dnf Version : 4.2.15 Release : 8.oe1 Architecture: noarch Install Date: Mon 18 May 2020 01:14:59 PM CST Group : Unspecified Size : 33740 License : GPLv2+ and GPLv2 and GPL Signature : RSA/SHA1, Tue 24 Mar 2020 03:47:22 AM CST, Key ID d557065eb25e7f66 Source RPM : dnf-4.2.15-8.oe1.src.rpm Build Date : Tue 24 Mar 2020 03:47:26 AM CST Build Host : obs-worker-100-0002.novalocal Packager : http://openeuler.org Vendor : http://openeuler.org URL : https://github.com/rpm-software-management/dnf Summary : A software package manager that manages packages on Linux distributions. Description : DNF is a software package manager that installs, updates, and removespackages on RPM-based Linux distributions. It automatically computes dependencies and determines the actions required to install packages.DNF also makes it easier to maintain groups of machines, eliminating the need to manually update each one using rpm. ``` #### 查看已安装软件包的配置文件 ``` bash # rpm -qc dnf-4.2.15-8.oe1.noarch /etc/dnf/automatic.conf /etc/dnf/dnf.conf /etc/dnf/protected.d/dnf.conf /etc/logrotate.d/dnf ``` #### 查看指定文件所属的软件包 ``` bash # rpm -qf /etc/dnf/automatic.conf dnf-4.2.15-8.oe1.noarch ``` #### 查看已安装软件包的依赖包 ``` bash # rpm -qR libarchive-3.4.1-2.oe1.x86_64 libacl.so.1()(64bit) libacl.so.1(ACL_1.0)(64bit) libbz2.so.1()(64bit) libc.so.6()(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.15)(64bit) libc.so.6(GLIBC_2.16)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libc.so.6(GLIBC_2.6)(64bit) libc.so.6(GLIBC_2.7)(64bit) libcrypto.so.1.1()(64bit) libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) liblz4.so.1()(64bit) liblzma.so.5()(64bit) liblzma.so.5(XZ_5.0)(64bit) liblzma.so.5(XZ_5.2)(64bit) libxml2.so.2()(64bit) libxml2.so.2(LIBXML2_2.4.30)(64bit) libxml2.so.2(LIBXML2_2.5.0)(64bit) libxml2.so.2(LIBXML2_2.5.2)(64bit) libxml2.so.2(LIBXML2_2.6.0)(64bit) libxml2.so.2(LIBXML2_2.6.5)(64bit) libz.so.1()(64bit) libzstd.so.1()(64bit) rpmlib(CompressedFileNames) = 3.0.4-1 rpmlib(FileDigests) = 4.6.0-1 rpmlib(PayloadFilesHavePrefix) = 4.0-1 rpmlib(PayloadIsXz) = 5.2-1 rtld(GNU_HASH) ``` ### 帮助文档(部分) ``` bash # rpm --help Usage: rpm [OPTION...] Query/Verify package selection options: -a, --all query/verify all packages -f, --file query/verify package(s) owning file -g, --group query/verify package(s) in group -p, --package query/verify a package file --pkgid query/verify package(s) with package identifier --hdrid query/verify package(s) with header identifier --triggeredby query the package(s) triggered by the package --whatconflicts query/verify the package(s) which require a dependency --whatrequires query/verify the package(s) which require a dependency --whatobsoletes query/verify the package(s) which obsolete a dependency --whatprovides query/verify the package(s) which provide a dependency --whatrecommends query/verify the package(s) which recommends a dependency --whatsuggests query/verify the package(s) which suggests a dependency --whatsupplements query/verify the package(s) which supplements a dependency --whatenhances query/verify the package(s) which enhances a dependency --nomanifest do not process non-package files as manifests Query/Verify file selection options: -c, --configfiles only include configuration files -d, --docfiles only include documentation files -L, --licensefiles only include license files -A, --artifactfiles only include artifact files --noghost exclude %%ghost files --noconfig exclude %%config files --noartifact exclude %%artifact files Query options (with -q or --query): --dump dump basic file information ...... ```   ### 学习资料 * openEuler-官网 openeuler.org/zh * openEuler-B站 space.bilibili.com/527064077 * openEuler-慕课 openeuler.org/zh/learn/mooc * openEuler-文档 openeuler.org/zh/documentation   欢迎各位同学来讨论~!
  • [交流分享] linux os-release 查看系统信息
    ### ECS信息 * 规格:通用入门型 | t6.large.1 | 2vCPUs | 2GB * 镜像:openEuler 20.03 64bit | 公共镜像   ### os-release 查看系统信息 ``` bash # cat /etc/os-release NAME="openEuler" VERSION="20.03 (LTS)" ID="openEuler" VERSION_ID="20.03" PRETTY_NAME="openEuler 20.03 (LTS)" ANSI_COLOR="0;31" ``` ``` bash # cat --help Usage: cat [OPTION]... [FILE]... Concatenate FILE(s) to standard output. With no FILE, or when FILE is -, read standard input. -A, --show-all equivalent to -vET -b, --number-nonblank number nonempty output lines, overrides -n -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank suppress repeated empty output lines -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit Examples: cat f - g Output f's contents, then standard input, then g's contents. cat Copy standard input to standard output. GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Full documentation <https://www.gnu.org/software/coreutils/cat> or available locally via: info '(coreutils) cat invocation' ```   ### 学习资料 * openEuler-官网 openeuler.org/zh * openEuler-B站 space.bilibili.com/527064077 * openEuler-慕课 openeuler.org/zh/learn/mooc * openEuler-文档 openeuler.org/zh/documentation   欢迎各位同学来讨论~!
  • [技术干货] Linux 中的多租户环境
    任何设置多租户环境的人都将面临是用虚拟机(VM)还是用容器来隔离环境的选择。如果使用虚拟机,虚拟机监控程序就会启动客户机,而每个客户机都有自己的操作系统及相应的应用和依赖项。同时,虚拟机监控程序还会确保用户之间彼此隔离。相比虚拟机,容器更加轻便、灵活且易于扩展。通过在单个主机上部署多个应用,并且使用内核和容器运行时来启动每个容器,容器可以简化多租户部署。与虚拟机(每个都包含自己的内核)相比,在容器中运行的应用则共享一个内核(甚至在多个租户之间)。在 Linux® 中,命名空间使得多个容器可以同时使用同一资源而不会产生冲突。确保容器的安全就等同于确保所有运行中进程的安全。 使用 Kubernetes 进行容器编排时,可以利用单个 Kubernetes 集群来设置多租户环境。您可以将租户分隔到自己的命名空间中,并创建能强制执行租户隔离的策略。
  • [存储] 云社区 博客 博客详情 Linux的Zombie进程的成因以及优化方法
    在linux系统中,进程(通过系统fork产生的)存在如下的一些状态(摘自ps官方manual手册)PROCESS STATE CODES       Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to       describe the state of a process:               D    uninterruptible sleep (usually IO)               R    running or runnable (on run queue)               S    interruptible sleep (waiting for an event to complete)               T    stopped by job control signal               t    stopped by debugger during the tracing               W    paging (not valid since the 2.6.xx kernel)               X    dead (should never be seen)               Z    defunct ("zombie") process, terminated but not reaped by its parent       For BSD formats and when the stat keyword is used, additional characters may be displayed:               <    high-priority (not nice to other users)               N    low-priority (nice to other users)               L    has pages locked into memory (for real-time and custom IO)               s    is a session leader               l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)               +    is in the foreground process group这些状态一般通过ps -x可以查看,我们本次探讨的主要是关于Z状态的进程。我们先以一个例子简单说明一下什么是Zombie状态进程,以C代码为例 pid_t child = 0;         if ((child = fork()) < 0) { printf("fork err\n"); return; } else if (child == 0) { printf("child pid : %d,father is %d\n",getpid(),getppid()); _exit(0); } printf("pid is %d\n",getpid()); sleep(10); return 0;执行一下结果:此时可以看到子进程先退了,但是是真的完全没有了么,我们再看一下ps的结果:可以看到4418的进程变成了defunct,也就是我们常说的Zombie进程,再看一下state:这个是怎么产生的呢,我们回来再看代码,子进程退出前,执行了exit(0),通过查看exit的手册,我们找到了答案       After  exit(), the exit status must be transmitted to the parent process.  There are three cases.  If the parent has set       SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the status is discarded.  If the  parent  was  waiting  on  the       child  it  is  notified  of the exit status.  In both cases the exiting process dies immediately.  If the parent has not       indicated that it is not interested in the exit status, but is not waiting, the exiting process turns  into  a  "zombie"       process (which is nothing but a container for the single byte representing the exit status) so that the parent can learn       the exit status when it later calls one of the wait(2) functions.这样也就是说,zombie状态实际是给父进程汇报子进程执行结束后的结果的,因此,如果父进程没有明确表示不关心这个结果,子进程会保持该状态,那么接下来就有两种处理方法:1、通过waitpid的方法,获取子进程的结束status,我们查看waitpid的系统调用可以了解到,最终的release_task是由父进程完成的(参考kernel3.10的源码调用)2、通过注册SIGCHLD信号处理的方式,明确父进程不关心子进程,这样在子进程退出时,则不会变成zombie状态(linux的wait手册)       A child that terminates, but has not been waited for becomes a "zombie".  The kernel maintains a minimal set of informa-       tion about the zombie process (PID, termination status, resource usage information) in order  to  allow  the  parent  to       later  perform  a  wait to obtain information about the child.  As long as a zombie is not removed from the system via a       wait, it will consume a slot in the kernel process table, and if this table fills, it will not  be  possible  to  create       further  processes.   If  a parent process terminates, then its "zombie" children (if any) are adopted by init(8), which       automatically performs a wait to remove the zombies.因此,可以看到,子进程的退出状态实际是由父进程来控制的(大概翻了一下代码实际是由进程组的leader的行为来决定的),而最为关键的一步,也是确保系统健康的一步,就是对于父进程退出后,所有的zombie进程都会由1号进程接管,因此,1号进程如果出现故障,或者回收的比较慢,就会造成zombie进程积压,最终引发系统崩溃。--------------------------------------------------------------------------------再来看一个python的案例(偷个懒,换个方便的语言,道理差不多,c整起来略麻烦):>>> import os>>> a = os.popen("date")>>> 通过a.close()的方法,可以回收掉这个defunct,python的popen实际是基于popen函数实现,内部会调用fork,这个和pclose成对,通过查看pclose源码,可以看到,这里面会调用waitpid来主动清理popen的Zombie进程。再来看一下通过信号明确不关心返回的处理方式SIGCHLD>>> import signal>>> signal.signal(signal.SIGCHLD,signal.SIG_IGN)0>>> b = os.popen("date")可以很明显看到不会残留一个Z状态的进程所以,我们在调用fork时(或者基于fork实现的功能时),要在代码中明确考虑SIGCHLD信号或者调用wait来清理子进程的退出状态,来防止Zombie进程的产生;当然,站在整个系统层面来说,尽量减少fork的总次数,也是一个不错的思路。原文链接:https://bbs.huaweicloud.com/blogs/178868【推荐阅读】【最新活动汇总】DWS活动火热进行中,互动好礼送不停(持续更新中)  HOT  【博文汇总】GaussDB(DWS)博文汇总1,欢迎大家交流探讨~(持续更新中)【维护宝典汇总】GaussDB(DWS)维护宝典汇总贴1,欢迎大家交流探讨(持续更新中)【项目实践汇总】GaussDB(DWS)项目实践汇总贴,欢迎大家交流探讨(持续更新中)【DevRun直播汇总】GaussDB(DWS)黑科技直播汇总,欢迎大家交流学习(持续更新中)【培训视频汇总】GaussDB(DWS) 培训视频汇总,欢迎大家交流学习(持续更新中)扫码关注我哦,我在这里↓↓↓
  • [技术干货] linux内核版本升级
    root@ecs-385f:~# uname -r4.15.0-128-genericroot@ecs-385f:~# sudo apt-get install linux-image-5.0.0-23-genericReading package lists... DoneBuilding dependency tree       Reading state information... DoneThe following additional packages will be installed:  linux-modules-5.0.0-23-genericSuggested packages:  fdutils linux-hwe-doc-5.0.0 | linux-hwe-source-5.0.0 linux-hwe-tools linux-headers-5.0.0-23-genericThe following NEW packages will be installed:  linux-image-5.0.0-23-generic linux-modules-5.0.0-23-generic0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.Need to get 22.0 MB of archives.After this operation, 76.0 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-modules-5.0.0-23-generic amd64 5.0.0-23.24~18.04.1 [13.6 MB]Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-image-5.0.0-23-generic amd64 5.0.0-23.24~18.04.1 [8,356 kB]                                    Fetched 22.0 MB in 1min 27s (254 kB/s)                                                                                                                                Selecting previously unselected package linux-modules-5.0.0-23-generic.(Reading database ... 111043 files and directories currently installed.)Preparing to unpack .../linux-modules-5.0.0-23-generic_5.0.0-23.24~18.04.1_amd64.deb ...Unpacking linux-modules-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...Selecting previously unselected package linux-image-5.0.0-23-generic.Preparing to unpack .../linux-image-5.0.0-23-generic_5.0.0-23.24~18.04.1_amd64.deb ...Unpacking linux-image-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...Setting up linux-modules-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...Setting up linux-image-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...I: /vmlinuz.old is now a symlink to boot/vmlinuz-4.15.0-128-genericI: /initrd.img.old is now a symlink to boot/initrd.img-4.15.0-128-genericI: /vmlinuz is now a symlink to boot/vmlinuz-5.0.0-23-genericI: /initrd.img is now a symlink to boot/initrd.img-5.0.0-23-genericProcessing triggers for linux-image-5.0.0-23-generic (5.0.0-23.24~18.04.1) .../etc/kernel/postinst.d/initramfs-tools:update-initramfs: Generating /boot/initrd.img-5.0.0-23-generic/etc/kernel/postinst.d/x-grub-legacy-ec2:Searching for GRUB installation directory ... found: /boot/grubSearching for default file ... found: /boot/grub/defaultTesting for an existing GRUB menu.lst file ... found: /boot/grub/menu.lstSearching for splash image ... none found, skipping ...Found kernel: /boot/vmlinuz-4.15.0-128-genericFound kernel: /boot/vmlinuz-4.15.0-29-genericFound kernel: /boot/vmlinuz-5.0.0-23-genericFound kernel: /boot/vmlinuz-4.15.0-128-genericFound kernel: /boot/vmlinuz-4.15.0-29-genericReplacing config file /run/grub/menu.lst with new versionUpdating /boot/grub/menu.lst ... done/etc/kernel/postinst.d/zz-update-grub:Sourcing file `/etc/default/grub'Generating grub configuration file ...Found linux image: /boot/vmlinuz-5.0.0-23-genericFound initrd image: /boot/initrd.img-5.0.0-23-genericFound linux image: /boot/vmlinuz-4.15.0-128-genericFound initrd image: /boot/initrd.img-4.15.0-128-genericFound linux image: /boot/vmlinuz-4.15.0-29-genericFound initrd image: /boot/initrd.img-4.15.0-29-genericdoneroot@ecs-385f:~# sudo apt-get install linux-headers-5.0.0-23-genericReading package lists... DoneBuilding dependency tree       Reading state information... DoneThe following packages were automatically installed and are no longer required:  linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic linux-modules-extra-4.15.0-29-genericUse 'sudo apt autoremove' to remove them.The following additional packages will be installed:  linux-headers-5.0.0-23The following NEW packages will be installed:  linux-headers-5.0.0-23 linux-headers-5.0.0-23-generic0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.Need to get 11.8 MB of archives.After this operation, 82.9 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-headers-5.0.0-23 all 5.0.0-23.24~18.04.1 [10.7 MB]Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-headers-5.0.0-23-generic amd64 5.0.0-23.24~18.04.1 [1,135 kB]                                  Fetched 11.8 MB in 20s (597 kB/s)                                                                                                                                     Selecting previously unselected package linux-headers-5.0.0-23.(Reading database ... 112326 files and directories currently installed.)Preparing to unpack .../linux-headers-5.0.0-23_5.0.0-23.24~18.04.1_all.deb ...Unpacking linux-headers-5.0.0-23 (5.0.0-23.24~18.04.1) ...Selecting previously unselected package linux-headers-5.0.0-23-generic.Preparing to unpack .../linux-headers-5.0.0-23-generic_5.0.0-23.24~18.04.1_amd64.deb ...Unpacking linux-headers-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...Setting up linux-headers-5.0.0-23 (5.0.0-23.24~18.04.1) ...Setting up linux-headers-5.0.0-23-generic (5.0.0-23.24~18.04.1) ...reboot之后root@ecs-385f:~# uname -r5.0.0-23-genericroot@ecs-385f:~# 
  • [交流分享] Linux内核hello world 驱动发开发(Ubuntu)
     前言linux 内 核 模 块 全 称 为 “ 动 态 可 加 载 内 核 模 块 (Loadable Kernel Module,LKM)”,是系统内核向外部提供的功能插口。作为宏内核结构,Linux 内核具有效率高的特点,但也有可扩展性和可维护性相对较差的不足,Linux 提供模块机制正是弥补这一缺陷。模块是具有独立功能的程序,它可以被单独编译,但不能独立运行。模块在运行时被链接到内核作为内核的一部分在内核空间运行,这与运行在用户控件的进程是不同的。模块通常有一组函数和数据结构组成,用来实现某种文件系统、驱动程序或其它内核上层功能。本文将介绍如何编写一个简单的内核模块以及如何传递参数给此模块。一、      Ubuntu系统安装1.1 安装Ubuntu 18.04系统安装比较简单,该文档不做累述。1.2 网络配置1.       配置IP:执行命令ip address先确认网卡设备名,然后在interfaces文件中添加IP相关属性。2.       添加DNS,因为/etc/resolv.conf文件不可编辑,需要创建/etc/rc.local文件来增加DNS服务器3.       重启系统后可ping通外网。1.3 安装软件如下图所示,在安装软件时发生“Unable to locate package make”报错1.       制作国内源,本次选用清华源1).备份原软件源sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup2).新開一个终端,在终端里输入sudo vim /etc/apt/source.list3).将source.list文件里的内容换成下面的(也可以把原来的注释掉) # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse4).保存后退出,在终端里输入:sudo apt-get update2.       再次安装make3.       Ubuntu系统默认没有安装ssh服务,建议安装。执行命令sudo ps –e|grep ssh没有任何输出说明没有安装执行命令sudo apt-get install openssh-server安装ssh服务如需开启sftp功能,还需要配置sftp权限。4.       安装gcc等。  二、      编写Makefile1  2  2.1 小程序测试创建文件a.c创建文件b.c编译:#gcc –o test a.c b.c(我也不知道implicit declaration of function ‘func_b’报错什么意思)运行./test,结果:2.2 小程序解析.c程序 –> 得到可执行程序要经过四个步骤:1.预处理2.编译3.汇编4.链接我们经常把前三个步骤统称为编译。具体分析这条命令:gcc -o test a.c b.c它们要经过下面几个步骤:1).对于a.c执行:预处理 编译 汇编 的过程,a.c –>xxx.s –>xxx.o 文件。2).对于b.c执行:预处理 编译 汇编 的过程,b.c –>yyy.s –>yyy.o 文件。3).最后:xxx.o和yyy.o链接在一起得到一个test应用程序。提示:gcc -o test a.c b.c -v :加上一个‘-v’选项可以看到它们的处理过程 第一次编译a.c得到xxx.o文件,这合乎情理, 执行完第一次之后,如果修改a.c ,又再次执行:gcc -o test a.c b.c,对于a.c应该重新生成xxx.o,但是对于b.c,又会重新编译一次,这完全没必要:b.c根本没有修改,直接使用第一次生成的yyy.o文件即可。 以上,不用Makefile的缺点:对所有的文件都会再处理一次,即使b.c没有经过修改,b.c也会被重新编译一次, 当文件比较少时,没什么问题,文件非常多的时候,编译的效率会很低。 如果文件非常多的时候,只是修改了一个文件,所有文件都会被重新编译一次,编译的时候就会需要很长时间。 对于这些源文件,我们应该分别处理,执行:预处理 编译 汇编 ,先分别编译它们,最后再把它们链接在一起,比如:编译:gcc -o a.o a.cgcc -o b.o b.c链接:gcc -o test a.o b.o 因此我们可以写出Makefile文件2.3 编写Makefile文件在小程序目录下写一个Makefile文件: 文件名:Makefile内容:  test:a.o b.o      gcc -o test a.o b.o    a.o : a.c     gcc -c -o a.o a.c    b.o : b.c      gcc -c -o b.o b.c         说明:         test :a.o b.o //test是目标,它依赖于a.o b.o文件,一旦a.o或者b.o比test新的时候,需要执行下面的命令,重新生成test可执行程序。gcc -o test a.o b.oa.o : a.c //a.o依赖于a.c,当a.c更加新的话,执行下面的命令来生成a.ogcc -c -o a.o a.cb.o : b.c //b.o依赖于b.c,当b.c更加新的话,执行下面的命令来生成b.ogcc -c -o b.o b.c  2.4 执行make直接执行make命令即可,一执行make命令它会生成第一个目标test可执行程序, 如果发现a.o 或者b.o没有,会先生成a.o或者b.o,发现a.o依赖a.c,有a.c但是没有a.o,它会认为a.c比a.o新,则执行它们下面的命令来生成a.o,同理,b.o和b.c的处理关系也是这样的。 如果修改a.c ,再次执行make,它的本意是想生成第一个目标test应用程序, 它需要先生成a.o, 发现a.o依赖a.c(假设我们修改了a.c),发现a.c比a.o更加新,就会执行gcc -c -o a.o a.c命令生成a.o文件。b.o依赖b.c,发现b.c并没有被修改,则不会执行gcc -c -o b.o b.c来重新生成b.o文件。 现在a.o b.o都有了,其中的a.o比test更加新,就会执行gcc -o test a.o b.o重新链接得到test可执行程序。所以当执行make命令,则会执行下面两条命令: gcc -c -o a.o a.cgcc -o test a.o b.o第一次执行make的时候,会执行下面三条命令(三条命令都执行): gcc -c -o a.o a.cgcc -c -o b.o b.cgcc -o test a.o b.o再次执行make 会有下面的提示: make: `test` is up to date.再次执行make 会判断Makefile文件中的依赖,发现依赖没有更新,所以目标文件就不会重新生成,于是有上面的提示。当我们修改a.c后,重新执行make会执行下面两条指令: gcc -c -o a.o a.cgcc -o test a.o b.o同时修改a.c b.c,执行make则会执行下面三条指令。 gcc -c -o a.o a.cgcc -c -o b.o b.cgcc -o test a.o b.oa.c文件被修改了,重新编译生成a.o, b.c被修改了,重新编译生成b.o, a.o, b.o都更新了,则重新链接生成test可执行程序,makefile的规则其实不难. 结果如下:三、      Makefile进阶3  3.1 通配符  1  创建一个c.c文件:并在a.c文件添加func_c()函数修改Makefile文件:编译make执行./test1 通配符说明:         %.o:表示所有的.o文件         %.c:表示所有的.c文件         $@:表示目标         $<:表示第一个依赖文件         $^:表示所有依赖文件   2  3  3.1  3.2 变量在Makefile中有两种变量:1)  简单变量(即时变量)A := xxx // A的值即可确定,在定义时即确定对于即时变量使用“:=”表示,它的值在定义的时候已被确定。2)  延时变量B = xxx // B的值被使用到时才确定对于延时变量使用“=”表示。它只有在使用到的时候才确定,在定义/等于时并没有确定下来当我们执行make命令的时候,make这个指令本身,会把整个Makefile读进去,进行全部分析,然后解析里面的变量。常用的变量的定义如下::= // 即时变量= // 延时变量?= // 延时变量, 如果是第一次定义才起效, 如果在前面该变量已定义则忽略这句+= // 附加, 它是即时变量还是延时变量取决于前面的定义?=: // 如果这个变量在前面已经被定义,这句话就不会起效果实例:A := $(C)B = $(C)C = abc#D = 100askD ?= weidongshanall:@echo A = $(A)@echo B = $(B)@echo D = $(D)C += 123编译后分析:1)A := $(C):A为即时变量,在定义时即确定,由于刚开始C的值为空,所以A的值也为空。2) B = (C):B为延时变量,只有使用到时它的值才确定,当执行make时,会解析Makefile里面的所用变量,所以先解析C=abc, 然后解析C+=123,此时C=abc123,当执行:@echoB=(C):B为延时变量,只有使用到时它的值才确定,当执行make时,会解析Makefile里面的所用变量,所以先解析C=abc, 然后解析C+=123,此时,C=abc123,当执行:@echoB=(B) B的值为 abc 123。3)D ?= weidongshan:D变量在前面没有定义,所以D的值为weidongshan,如果在前面添加D = 100ask,最后D的值为100ask。 我们还可以通过命令行存入变量的值例如执行:make D=huawei里面的D ?= weidongshan这句话便不再起作用。结果:   四、      编写一个简单的内核模块4  4.1 编写模块程序编写如下简单代码,本示例中代码文件命名“hello_module.c”。 //hello_module.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>static int __init hello_init(void){  //_init初始化编译器相关函数或变量。编译器将标__init的所有代码存在特殊的内存段中,初始化结束后就释放这段内存   printk("This is hello_module, welcome to Linux kernel \n");   return 0;}static void __exit hello_exit(void){   printk("see you next time!\n");}module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("Mr Q");MODULE_DESCRIPTION("hello kernel module");MODULE_ALIAS("hello");以上代码解释如下:(1) #include <linux/module.h>:必须。module.h 头文件包含了对模块的结构定义以及模块的版本控制,任何模块程序的编写都要包含这个头文件;(2) #include <linux/kernel.h>:kernel.h 包含了常用的内核函数,如以上程序中的 printk()函数;(3) #include <linux/init.h>:必须。init.h 包含了 module_init()和 module_exit()函数的声明;(4) module_init():必须。模块加载函数,加载模块式该函数自动执行,进行初始化操作;相当于c语言程序中的main()函数,是驱动程序初始化的入口点。对于内置的模块,内核在引导时调用该引导点,对于可加载模块则在模块插入到内核时才调用。(5) module_exit():必须。模块卸载函数,卸载模块时函数自动执行,进行清理操作;(6) MODULE_LICENSE():表示模块代码接受的软件许可协议。Linux 内核是使用 GPL V2 的开源项目,其要求所有使用和修改了 Linux 内核代码的个人或组织都有义务把修改后的源代码公开,这是一个强制的开源协议,所以一般编写驱动代码都需要显示的声明和遵循本协议,否则内核 UI 发出被污染的警告;(7) MODULE_AUTHOR():描述模块的作者信息;(8) MODULE_DESCRIPTION():简单描述模块的用途、功能介绍等;(9) MODULE_ALIAS():为用户控件提供的别名;           (7)-(9) 是模块声明与描述部分。这部分可以有,也可以省略。(10) printk():内核输出函数,模块加载函数和模块卸载函数中都会用到,默认打印系统文件 “ /var/log/kern.log”的内容。 4.2  编译内核模块编写 Makefile 文件,文件名必须为“Makefile”obj-m := hello_module.oKERNELBUILD := /lib/modules/$(shell uname -r)/buildCURRENT_PATH := $(shell pwd)all: make -C $(KERNELBUILD) M=$(CURRENT_PATH) modulesclean:  make -C $(KERNELBUILD) M=$(CURRENT_PATH) clean以上代码解释如下:(1) obj-m := <模块名>.o:定义要生成的模块名称(2) KERNELBUILD := /lib/modules/$(shell uname -r)/build :KERNELBUILD 为自定义名称,用于指向正在运行 Linux 的内核编译目录,其中“uname -r”标识显示对应的内核版本;(3) CURRENT_PATH := $(shell pwd):CURRENT_PATH 为自定义名称,用于指向当前当前目录;(4) all:编译执行的动作(5) clean:zhixing make clean 需要的动作。“make clean”用于清除上次的 make 命令所产生的 object 文件(后缀为“.o”的文件)及可执行文件。4.1 编译将以上两个文件(hello_module.c 和 Makefile)保存于同一目录下,将上文中代码存放在路径为“/code/hellomodule/”,编译需在文件保存目录中进行。编译成功后,可看到生成的 hello_module.ko 目标文件 4.2 检查编译模块可通过 file 命令检查编译的模块是否正确,可以看到 aarch64架构的 elf文件,说明编译成功:也可通过 modinfo 命令进一步检查 : 4.3 插入模块通过 insmod 命令插入模块,完成插入后可通过 lsmod 命令查看当前模块是否已经被加载到系统中:系统加载模块后,也会在“/sys/module”目录下新建以模块名命名的目录 :4.4 查看输出因 本 演示 中 prink()采 用 默认 输出 等级 ,可 通 过“ dmesg” 或“ tail /var/log/kern.log”命令查看输出结果。“ tail /var/log/kern.log”命令查看输出结果:4.5 卸载模块卸载模块,可通过“rmmod 模块名”实现,通 过“ tail /var/log/kern.log”命令查看输出结果。五、      内核模块参数5  5.1 说明Linux 内核提供一个宏来实现模块的参数传递#define module_param(name, type, perm) \module_param_named(name, name, type, perm)#define MODULE_PARM_DESC(_parm, desc) \_MODULE_INFO(parm, _parm, #_parm ":" desc);module_param()宏由 3 个参数组成,name 表示参数名,type 表示参数类型,perm 表示参数读写权限。MODULE_PARM_DESC()宏提供参数的简单说明,参数类型可为 byte、short、int、long、char、bool 等类型;perm 指定在 sysfs 中相应文件的访问权限,如设置为 0 则不会出现在 sysfs 文件系统中,设置为 0644 标识 root 用户可修改本参数。static int debug = 1;module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "enable debugging information");#define dprintk(args...) if(debug){printk(KERN_DEBUG args);}如上述实际代码所示(driver/misc/altera-stap1/altera.c),实际定义模块参数 debug,类型是 int,访问权限是 0644。参数用途是大概调试信息,实际内核编程中常用此方法进行内核调试。5.2 参数实现修改上文中的“hello_module.c”文件,改为以下内容://hello_module.c#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>static int debug = 1;module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "debugging information");#define dprintk(args...) if(debug){printk(KERN_DEBUG args);}static int myparm = 10;module_param(myparm, int, 0644);MODULE_PARM_DESC(myparm, "kernel module parameter experiment.");static int __init parm_init(void){   dprintk("my linux kernel module init.\n");   dprintk("module parameter = %d\n", myparm);   return 0;}static void __exit parm_exit(void){   printk("see you next time!\n");}module_init(parm_init);module_exit(parm_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("Mr Q");MODULE_DESCRIPTION("kernel module paramter experiment");MODULE_ALIAS("myparm");make编译,装载模块,并查看输出:通过查看日志信息,可发现输出以上程序中 参数 的默认值。卸载模块,赋值重新加载模块,修改参数 myparm 值为 116:insmod hello_module.ko myparm=116  通过查看日志信息,可发现 参数 值已经改变。 
  • [运维管理] linux下配置数据源为什么要重启
    产品文档《linux下配置数据源》这一章节中第6步配置数据库服务器中最后一步是重启集群前面的步骤都是使用reload的方式对参数进行设置,这种方式不需要重启,最后一步为什么又要重启呢?
  • [技术干货] Linux下删除过期日志文件
    使用前将工具包拖到/opt目录下即可写一个脚本文件,将以下内容复制进去,使用source或者. 执行脚本#!/bin/bashmount /dev/cdrom /mnt &> /dev/nullecho "---正在安装环境依赖包---"yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmakeecho "---正在配置软件模块---"cd /opttar zxvf mysql-5.7.17.tar.gztar zxvf boost_1_59_0.tar.gzcd /optmv boost_1_59_0 /usr/local/boost cd /opt/mysql-5.7.17/cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DSYSCONFDIR=/etc \-DSYSTEMD_PID_DIR=/usr/local/mysql \-DDEFAULT_CHARSET=utf8  \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_DATADIR=/usr/local/mysql/data \-DWITH_BOOST=/usr/local/boost \-DWITH_SYSTEMD=1echo "---编译安装中---"make && make installecho "---创建mysql用户---"useradd -M -s /sbin/nologin  mysqlecho "---修改mysql 配置文件---"echo '[client]port = 3306socket=/usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir=/usr/local/mysqldatadir=/usr/local/mysql/dataport = 3306character-set-server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket=/usr/local/mysql/mysql.sockbind-address = 0.0.0.0skip-name-resolvemax_connections=2048default-storage-engine=INNODBmax_allowed_packet=16Mserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnfecho "---更改mysql安装目录和配置文件的属主属组---"chown -R mysql:mysql /usr/local/mysql/chown mysql:mysql /etc/my.cnfecho "---设置路径环境变量---"echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile source /etc/profileecho "---正在初始化数据库---"cd /usr/local/mysql/bin/./mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/dataecho "---添加mysqld系统服务---"cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload              systemctl start mysqld.service  systemctl enable mysqld         netstat -anpt | grep 3306       echo "---修改mysql的登录密码---"mysqladmin -u root -p password "123456"echo "初始密码已设为:123456"echo "---正在登录---"mysql -uroot -p123456
  • [其他] 【升级】某局点在elk升级前执行补充rpm包命令时,其中一个节点报upgrade error,general error
    【问题描述】某局点在elk升级前执行补充rpm包命令时,其中一个节点报upgrade error,general error【分析过程】1、查看日志/tmp/fi-preinstall.log发现,失败节点报can not find /usr/local/diskmgt/ini-plugin/conf/datenode1.conf2、查看失败节点上对应目录下的文件缺失不存在datenode1.conf3、在将datanode1.conf重命名为datenode1.conf后,重新执行补包命令成功【规避方案】将失败节点上datanode1.conf重命名为datenode1.conf后,重新执行补包命令
  • [赋能学习] MRS3.0.2版本 二次开发(2/27): HDFS调用样例在linux环境下执行出错
    1,HDFS调用样例在linux环境下执行出错,提示如下:2,windows环境已经执行成功,输出:"C:\Program Files\Java\jdk1.8.0_261\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2\lib\idea_rt.jar=59295:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_261\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_261\jre\lib\rt.jar;D:\huaweicloud-mrs-example-mrs-3.0.2\src\hdfs-example-security\target\classes;D:\MyMaven\org\apache\hadoop\hadoop-common\3.1.1-hw-ei-302002\hadoop-common-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-annotations\3.1.1-hw-ei-302002\hadoop-annotations-3.1.1-hw-ei-302002.jar;C:\Program Files\Java\jdk1.8.0_261\lib\tools.jar;D:\MyMaven\com\google\guava\guava\11.0.2\guava-11.0.2.jar;D:\MyMaven\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;D:\MyMaven\org\apache\commons\commons-math3\3.1.1\commons-math3-3.1.1.jar;D:\MyMaven\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar;D:\MyMaven\org\apache\httpcomponents\httpcore\4.4.4\httpcore-4.4.4.jar;D:\MyMaven\commons-codec\commons-codec\1.14\commons-codec-1.14.jar;D:\MyMaven\commons-io\commons-io\2.5\commons-io-2.5.jar;D:\MyMaven\commons-net\commons-net\3.6\commons-net-3.6.jar;D:\MyMaven\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\MyMaven\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;D:\MyMaven\org\eclipse\jetty\jetty-server\9.4.20.v20190813\jetty-server-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-http\9.4.20.v20190813\jetty-http-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-io\9.4.20.v20190813\jetty-io-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-util\9.4.20.v20190813\jetty-util-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-servlet\9.4.20.v20190813\jetty-servlet-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-security\9.4.20.v20190813\jetty-security-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-webapp\9.4.20.v20190813\jetty-webapp-9.4.20.v20190813.jar;D:\MyMaven\org\eclipse\jetty\jetty-xml\9.4.20.v20190813\jetty-xml-9.4.20.v20190813.jar;D:\MyMaven\javax\servlet\jsp\jsp-api\2.1\jsp-api-2.1.jar;D:\MyMaven\com\sun\jersey\jersey-core\1.19\jersey-core-1.19.jar;D:\MyMaven\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\MyMaven\com\sun\jersey\jersey-servlet\1.19\jersey-servlet-1.19.jar;D:\MyMaven\com\sun\jersey\jersey-json\1.19\jersey-json-1.19.jar;D:\MyMaven\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;D:\MyMaven\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;D:\MyMaven\org\codehaus\jackson\jackson-core-asl\1.9.2\jackson-core-asl-1.9.2.jar;D:\MyMaven\org\codehaus\jackson\jackson-mapper-asl\1.9.2\jackson-mapper-asl-1.9.2.jar;D:\MyMaven\org\codehaus\jackson\jackson-jaxrs\1.9.2\jackson-jaxrs-1.9.2.jar;D:\MyMaven\org\codehaus\jackson\jackson-xc\1.9.2\jackson-xc-1.9.2.jar;D:\MyMaven\com\sun\jersey\jersey-server\1.19\jersey-server-1.19.jar;D:\MyMaven\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;D:\MyMaven\log4j\log4j\1.2.17-atlassian-13\log4j-1.2.17-atlassian-13.jar;D:\MyMaven\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\MyMaven\commons-beanutils\commons-beanutils\1.9.4\commons-beanutils-1.9.4.jar;D:\MyMaven\org\apache\commons\commons-configuration2\2.1.1\commons-configuration2-2.1.1.jar;D:\MyMaven\org\apache\commons\commons-lang3\3.7\commons-lang3-3.7.jar;D:\MyMaven\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\MyMaven\org\slf4j\slf4j-log4j12\1.7.30\slf4j-log4j12-1.7.30.jar;D:\MyMaven\org\apache\avro\avro\1.7.7\avro-1.7.7.jar;D:\MyMaven\com\thoughtworks\paranamer\paranamer\2.3\paranamer-2.3.jar;D:\MyMaven\org\xerial\snappy\snappy-java\1.0.5\snappy-java-1.0.5.jar;D:\MyMaven\com\google\re2j\re2j\1.1\re2j-1.1.jar;D:\MyMaven\com\google\protobuf\protobuf-java\2.5.0\protobuf-java-2.5.0.jar;D:\MyMaven\com\google\code\gson\gson\2.2.4\gson-2.2.4.jar;D:\MyMaven\org\apache\hadoop\hadoop-auth\3.1.1-hw-ei-302002\hadoop-auth-3.1.1-hw-ei-302002.jar;D:\MyMaven\com\nimbusds\nimbus-jose-jwt\7.9\nimbus-jose-jwt-7.9.jar;D:\MyMaven\com\github\stephenc\jcip\jcip-annotations\1.0-1\jcip-annotations-1.0-1.jar;D:\MyMaven\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\MyMaven\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\MyMaven\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\MyMaven\org\apache\curator\curator-framework\4.2.0\curator-framework-4.2.0.jar;D:\MyMaven\com\jcraft\jsch\0.1.54\jsch-0.1.54.jar;D:\MyMaven\org\apache\curator\curator-client\4.2.0\curator-client-4.2.0.jar;D:\MyMaven\org\apache\curator\curator-recipes\4.2.0\curator-recipes-4.2.0.jar;D:\MyMaven\com\google\code\findbugs\jsr305\3.0.0\jsr305-3.0.0.jar;D:\MyMaven\org\apache\htrace\htrace-core4\4.2.0-incubating-hw-1.0.0\htrace-core4-4.2.0-incubating-hw-1.0.0.jar;D:\MyMaven\org\apache\zookeeper\zookeeper\3.5.6-hw-ei-302002\zookeeper-3.5.6-hw-ei-302002.jar;D:\MyMaven\org\apache\zookeeper\zookeeper-jute\3.5.6-hw-ei-302002\zookeeper-jute-3.5.6-hw-ei-302002.jar;D:\MyMaven\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\MyMaven\io\netty\netty-handler\4.1.48.Final\netty-handler-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-common\4.1.48.Final\netty-common-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-resolver\4.1.48.Final\netty-resolver-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-buffer\4.1.48.Final\netty-buffer-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-transport\4.1.48.Final\netty-transport-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-codec\4.1.48.Final\netty-codec-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-transport-native-epoll\4.1.48.Final\netty-transport-native-epoll-4.1.48.Final.jar;D:\MyMaven\io\netty\netty-transport-native-unix-common\4.1.48.Final\netty-transport-native-unix-common-4.1.48.Final.jar;D:\MyMaven\org\apache\commons\commons-compress\1.4.1\commons-compress-1.4.1.jar;D:\MyMaven\org\tukaani\xz\1.0\xz-1.0.jar;D:\MyMaven\org\apache\kerby\kerb-simplekdc\1.0.1\kerb-simplekdc-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-client\1.0.1\kerb-client-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerby-config\1.0.1\kerby-config-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-core\1.0.1\kerb-core-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerby-pkix\1.0.1\kerby-pkix-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerby-asn1\1.0.1\kerby-asn1-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerby-util\1.0.1\kerby-util-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-common\1.0.1\kerb-common-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-crypto\1.0.1\kerb-crypto-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-util\1.0.1\kerb-util-1.0.1.jar;D:\MyMaven\org\apache\kerby\token-provider\1.0.1\token-provider-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-admin\1.0.1\kerb-admin-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-server\1.0.1\kerb-server-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerb-identity\1.0.1\kerb-identity-1.0.1.jar;D:\MyMaven\org\apache\kerby\kerby-xdr\1.0.1\kerby-xdr-1.0.1.jar;D:\MyMaven\com\fasterxml\jackson\core\jackson-databind\2.10.3\jackson-databind-2.10.3.jar;D:\MyMaven\com\fasterxml\jackson\core\jackson-annotations\2.10.3\jackson-annotations-2.10.3.jar;D:\MyMaven\com\fasterxml\jackson\core\jackson-core\2.10.3\jackson-core-2.10.3.jar;D:\MyMaven\org\codehaus\woodstox\stax2-api\3.1.4\stax2-api-3.1.4.jar;D:\MyMaven\com\fasterxml\woodstox\woodstox-core\5.0.3\woodstox-core-5.0.3.jar;D:\MyMaven\org\apache\hadoop\hadoop-client\3.1.1-hw-ei-302002\hadoop-client-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-hdfs-client\3.1.1-hw-ei-302002\hadoop-hdfs-client-3.1.1-hw-ei-302002.jar;D:\MyMaven\com\squareup\okhttp\okhttp\2.7.5\okhttp-2.7.5.jar;D:\MyMaven\com\squareup\okio\okio\1.6.0\okio-1.6.0.jar;D:\MyMaven\org\apache\hadoop\hadoop-yarn-api\3.1.1-hw-ei-302002\hadoop-yarn-api-3.1.1-hw-ei-302002.jar;D:\MyMaven\javax\xml\bind\jaxb-api\2.2.11\jaxb-api-2.2.11.jar;D:\MyMaven\org\apache\hadoop\hadoop-yarn-client\3.1.1-hw-ei-302002\hadoop-yarn-client-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-mapreduce-client-core\3.1.1-hw-ei-302002\hadoop-mapreduce-client-core-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-yarn-common\3.1.1-hw-ei-302002\hadoop-yarn-common-3.1.1-hw-ei-302002.jar;D:\MyMaven\com\sun\jersey\jersey-client\1.19\jersey-client-1.19.jar;D:\MyMaven\com\fasterxml\jackson\module\jackson-module-jaxb-annotations\2.10.3\jackson-module-jaxb-annotations-2.10.3.jar;D:\MyMaven\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;D:\MyMaven\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;D:\MyMaven\com\fasterxml\jackson\jaxrs\jackson-jaxrs-json-provider\2.10.3\jackson-jaxrs-json-provider-2.10.3.jar;D:\MyMaven\com\fasterxml\jackson\jaxrs\jackson-jaxrs-base\2.10.3\jackson-jaxrs-base-2.10.3.jar;D:\MyMaven\org\apache\hadoop\hadoop-yarn-registry\3.1.1-hw-ei-302002\hadoop-yarn-registry-3.1.1-hw-ei-302002.jar;D:\MyMaven\dnsjava\dnsjava\2.1.7\dnsjava-2.1.7.jar;D:\MyMaven\org\apache\hadoop\hadoop-mapreduce-client-jobclient\3.1.1-hw-ei-302002\hadoop-mapreduce-client-jobclient-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-mapreduce-client-common\3.1.1-hw-ei-302002\hadoop-mapreduce-client-common-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\apache\hadoop\hadoop-hdfs\3.1.1-hw-ei-302002\hadoop-hdfs-3.1.1-hw-ei-302002.jar;D:\MyMaven\org\eclipse\jetty\jetty-util-ajax\9.4.20.v20190813\jetty-util-ajax-9.4.20.v20190813.jar;D:\MyMaven\commons-daemon\commons-daemon\1.0.13\commons-daemon-1.0.13.jar;D:\MyMaven\io\netty\netty\3.10.6.Final\netty-3.10.6.Final.jar;D:\MyMaven\io\netty\netty-all\4.1.48.Final\netty-all-4.1.48.Final.jar;D:\MyMaven\org\fusesource\leveldbjni\leveldbjni-all\1.8\leveldbjni-all-1.8.jar;D:\MyMaven\com\huawei\mrs\hadoop-plugins\8.0.2-302002\hadoop-plugins-8.0.2-302002.jar" com.huawei.bigdata.hdfs.examples.HdfsExample1    [main] INFO  org.apache.hadoop.security.UserGroupInformation  - Login successful for user hdfsuser using keytab file user.keytab2    [main] INFO  com.huawei.hadoop.security.LoginUtil  - Login success!!!!!!!!!!!!!!852  [main] WARN  org.apache.hadoop.hdfs.shortcircuit.DomainSocketFactory  - The short-circuit local reads feature cannot be used because UNIX Domain sockets are not available on Windows.5940 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to create path /user/hdfs-examples6504 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to write.9045 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to append.9585 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - result is : hi, I am bigdata. It is successful if you can see me.I append this content.9585 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to read.9637 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete the file /user/hdfs-examples\test.txt9702 [main] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete path /user/hdfs-examples9810 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to create path /user/hdfs-examples/hdfs_example_19820 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to create path /user/hdfs-examples/hdfs_example_010136 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to write.10166 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to write.12858 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to append.12984 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to append.13094 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - result is : hi, I am bigdata. It is successful if you can see me.I append this content.13094 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to read.13139 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete the file /user/hdfs-examples/hdfs_example_1\test.txt13286 [hdfs_example_1] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete path /user/hdfs-examples/hdfs_example_113408 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - result is : hi, I am bigdata. It is successful if you can see me.I append this content.13409 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to read.13480 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete the file /user/hdfs-examples/hdfs_example_0\test.txt13525 [hdfs_example_0] INFO  com.huawei.bigdata.hdfs.examples.HdfsExample  - success to delete path /user/hdfs-examples/hdfs_example_0Process finished with exit code 0
  • 一起努力
    开源产品不仅具有低风险、品质好、低成本及更透明的四大优势,而且开源精神还是每个Linux技术人从骨子里自豪的情怀,刘遄老师会用通俗易懂的方式讲述Linux系统从1991年至2016年将近二十五年的发展历程,进一步了解整个开源行业的发展趋势。学习最常见的Linux系统、了解红帽阶梯认证体系以及红帽RHEL7系统的战略定位,进而帮助每位同学更好的确定今后学习方向。
  • [技术干货] 性能之巅:定位和优化程序CPU、内存、IO瓶颈(下)
    ## 进程、线程、协程在linux内核中,进程和线程是同样的系统调用(clone),进程跟线程的区别:线程是共享存储空间的,每个执行流有一个执行控制结构体,这里面会有一个指针,指向地址空间结构,一个进程内的多个线程,通过指向同一地址结构实现共享同一虚拟地址空间。通过fork创建子进程的时候,不会马上copy一份数据,而是推迟到子进程对地址空间进行改写,这样做是合理的,此即为COW(Copy On Write),在应用开发中,也有大量的类似借鉴。协程是用户态的多执行流,C语言提供makecontext/getcontext/swapcontext系列接口,很多协程库也是基于这些接口实现的,微信的协程库libco(已开源)通过hook慢速系统调用(比如write,read)做到静默替换,非常巧妙。## 链接C/C++源代码经编译链接后产生可执行程序,其中数据和代码分段存储,我们写的函数将进入text节,全局数据将进入数据段,未初始化的全局变量进入bss,堆和栈向着相反的方向生长,局部变量在栈里,参数通过栈传递,返回值一般通过eax寄存器返回。想要程序运行的更快,最好把相互调用,关系紧密的函数放到代码段相近的地方,这样能提高icache命中性。减少代码量、减少函数调用、减少函数指针同样能提高i-cache命中性。内联既避免了栈帧建立撤销的开销,又避免了控制跳转对i-cache的冲刷,所以有利于性能。同样,关键路径的性能敏感函数也应该避免递归函数。减少函数调用(就地展开)跟封装是相违背的,有时候,为了性能,我们不得不破坏封装和损伤可读性的代码,这是一个权衡利弊的问题。## 常识和数据CPU拷贝数据一般一秒钟能做到几百兆,当然每次拷贝的数据长度不同,吞吐不同。一次函数执行如果耗费超过1000 cycles就比较大了(刨除调用子函数的开销)。pthread_mutex_t是futex实现,不用每次都进入内核,首次加解锁大概耗时4000-5000 cycles左右,之后,每次加解锁大概120 cycles,O2优化的时候100 cycles,spinlock耗时略少。lock内存总线+xchg需要50 cycles,一次内存屏障要50 cycles。有一些无锁的技术,比如CAS,比如linux kernel里的kfifo,主要利用了整型回绕+内存屏障。#四、怎么做性能优化(TODO)两个⽅向:提⾼运⾏速度 + 减少计算量。性能优化监控先⾏,要基于数据⽽⾮基于猜测,要搭建能尽量模拟真实运⾏状态的压⼒测试环境,在此基于上获取的profiling数据才是有⽤的。方法论:监控 -> 分析 -> 优化 三部曲。##工具:perf是linux内核自带的profiling工具,除之之外还有gprof,但gprof是侵入式的(插桩),编译的时候需要加-pg参数,会导致运行变慢(慢很多)。perf采集的数据,可以用来生成火焰图,也可以用gprof2dot.py这个工具来产生比火焰图更直观的调用图,这些工具就是我经常用的。gprof2dot.py链接:https://github.com/jrfonseca/gprof2dot/blob/master/gprof2dot.py性能优化一个重要原则就是用数据说话,而不能凭空猜测。瓶颈点可能有多个,如果不解决最狭窄的瓶颈点,性能优化就不能达到预期效果。所以性能优化之前一定要先进行性能测试,摸清家底,建立测试基线。例子:之前做SIP协议栈,公司的产品需要提高SIP性能。美国的一个团队经过理论分析,单凭理论分析认为主要是动态内存分配是主要瓶颈,把内存申请成一大块内存,指针都变成的一大块内存的偏移量,非常难于调试,最后效果也不好。我们又通过测试分析的方式重构了程序,性能是它们的五倍。另外,性能优化要一个点一个点的做,做完一点,马上做性能验证。这样可以避免无用的修改。#五、几个具体问题(TODO)##1. 如何定位CPU瓶颈?CPU是通常大家最先关注的性能指标,宏观维度有核的CPU使用率,微观有函数的CPU cycle数,根据性能的模型,性能规格与CPU使用率是互相关联的,规格越高,CPU使用率越高,但是处理器的性能往往又受到内存带宽、Cache、发热等因素的影响,所以CPU使用率和规格参数之间并不是简单的线性关系,所以性能规格翻倍并不能简单地翻译成我们的CPU使用率要优化一倍。至于CPU瓶颈的定位工具,最有名也是最有用的工具就是perf,它是性能分析的第一步,可以帮我们找到系统的热点函数。就像人看病一样,只知道症状是不够的,需要通过医疗机器进一步分析病因,才能对症下药。所以我们通过性能分析工具PMU或者其他工具去进一步分析CPU热点的原因比如是指令数本身就比较多,还是Cache miss导致的等,这样在做性能优化的时候不会走偏。##2. 如何定位IO瓶颈?系统IO的瓶颈可以通过CPU和负载的非线性关系体现出来。当负载增大时,系统吞吐量不能有效增大,CPU不能线性增长,其中一种可能是IO出现阻塞。系统的队列长度特别是发送、写磁盘线程的队列长度也是IO瓶颈的一个间接指标。对于网络系统来讲,我建议先从外部观察系统。所谓外部观察是指通过观察外部的网络报文交换,可以用tcpdump, wireshark等工具,抓包看一下。比如我们优化一个RPC项目,它的吞吐量是10TPS,客户希望是100TPS。我们使用wireshark抓取TCP报文流,可以分析报文之间的时间戳,响应延迟等指标来判断是否是由网络引起来的。然后可以通过netstat -i/-s选项查看网络错误、重传等统计信息。还可以通过iostat查看cpu等待IO的比例。IO的概念也可以扩展到进程间通信。对于磁盘类的应用程序,我们最希望看到写磁盘有没有时延、频率如何。其中一个方法就是通过内核ftrace、perf-event事件来动态观测系统。比如记录写块设备的起始和返回时间,这样我们就可以知道磁盘写是否有延时,也可以统计写磁盘时间耗费分布。有一个开源的工具包perf-tools里面包含着iolatency, iosnoop等工具。##3. 如何定位IO瓶颈?应用程序常用的IO有两种:Disk IO和网络IO。判断系统是否存在IO瓶颈可以通过观测系统或进程的CPU的IO等待比例来进行,比如使用mpstat、top命令。系统的队列长度特别是发送、写磁盘线程的队列长度也是IO瓶颈的一个重要指标。对于网络 IO来讲,我们可以先使用netstat -i/-s查看网络错误、重传等统计信息,然后使用sar -n DEV 1和sar -n TCP,ETCP 1查看网路实时的统计信息。ss (Socket Statistics)工具可以提供每个socket相关的队列、缓存等详细信息。更直接的方法可以用tcpdump, wireshark等工具,抓包看一下。对于Disk IO,我们可以通过iostat -x -p xxx来查看具体设备使用率和读写平均等待时间。如果使用率接近100%,或者等待时间过长,都说明Disk IO出现饱和。一个更细致的观察方法就是通过内核ftrace、perf-event来动态观测Linux内核。比如记录写块设备的起始和返回时间,这样我们就可以知道磁盘写是否有延时,也可以统计写磁盘时间耗费分布。有一个开源的工具包perf-tools里面包含着iolatency, iosnoop等工具。##4.如何定位锁的问题?大家都知道锁会引入额外开销,但锁的开销到底有多大,估计很多人没有实测过,我可以给一个数据,一般单次加解锁100 cycles,spinlock或者cas更快一点。使用锁的时候,要注意锁的粒度,但锁的粒度也不是越小越好,太大会增加撞锁的概率,太小会导致代码更难写。多线程场景下,如果cpu利用率上不去,而系统吞吐也上不去,那就有可能是锁导致的性能下降,这个时候,可以观察程序的sys cpu和usr cpu,这个时候通过perf如果发现lock的开销大,那就没错了。如果程序卡住了,可以用pstack把堆栈打出来,定位死锁的问题。##5. 如何提⾼Cache利用率?内存/Cache问题是我们常见的负载瓶颈问题,通常可利用perf等一些通用工具来辅助分析,优化cache的思想可以从两方面来着手,一个是增加局部数据/代码的连续性,提升cacheline的利用率,减少cache miss,另一个是通过prefetch,降低miss带来的开销。通过对数据/代码根据冷热进行重排分区,可提升cacheline的有效利用率,当然触发false-sharing另当别论,这个需要根据运行trace进行深入调整了;说到prefetch,用过的人往往都有一种体会,现实效果比预期差的比较远,确实无论是数据prefetch还是代码prefetch,不确定性太大,我们和无线做过一些实践,最终以无线输出预取pattern,编译器自动插入prefetch的方案,效果还算可以。剩下的,下次我们接着说!
  • 优雅的build最新xtrabackup-8.0.x.el7.aarch64 版本rpm包姿势
    1 环境准备yum install centos-release-scl epel-release yum install cmake3 openssl-devel libaio libaio-devel automake autoconf bison libtool ncurses-devel \ libgcrypt-devel libev-devel libcurl-devel zlib-devel vim-common readline-devel python-sphinx rpm-build # centos7需要单独安装新版本gcc yum install devtoolset-7 # a little hack ln -snf /opt/rh/devtoolset-7/root/usr/bin/g++ /usr/bin/ ln -snf /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/2 获取最新包https://repo.percona.com/yum/release/8/SRPMS/如:https://repo.percona.com/yum/release/8/SRPMS/percona-xtrabackup-80-8.0.25-17.1.generic.src.rpm3 编译打包rpm -ivh percona-xtrabackup-80-8.0.25-17.1.generic.src.rpm cd ~/rpmbuild rpmbuild -bb --nodebuginfo SPECS/percona-xtrabackup.specover.
总条数:1204 到第 页
上滑加载中