Tag: centos7

  • centos7下vi显示彩色如何设置

    centos7下vi显示彩色如何设置

    首先确保安装了3个包: vim-minimal,vim-enhanced,vim-common 并且设置了别名: 看下面代码,把 -n “$ID” -a “$ID” -le 200 这行注释掉,重新登录linux即可。 # vi /etc/profile.d/vim.sh if [ -n “$BASH_VERSION” -o -n “$KSH_VERSION” -o -n “$ZSH_VERSION” ]; then [ -x /usr/bin/id ] || return ID=`/usr/bin/id -u` #[ -n “$ID” -a “$ID” -le 200 ] && return ### hash out this line # for bash and zsh, only…

  • 在Linux Centos7下,如何定时对日志文件进行切割?

    在Linux Centos7下,如何定时对日志文件进行切割?

    使用logrotate通用方法来切割日志:(1).logrotate的配置文件logrotate配置文件主要在两个地方:/etc/logrotate.conf以及/etc/logrotate.d/下的明细配置文件。其中/etc/logrotate.conf文件是主配置文件,/etc/logrotate.d/下的明细配置文件都会被读入/etc/logrotate.conf进行执行,所以请注意这里还涉及到了公有变量和私有变量。 logrotate的执行是由crond服务来调用的,其脚本是/etc/cron.daily/logrotate,每天自动执行。我们可以看一下脚本具体内容: [root@moneyslow.com ~]# cat /etc/cron.daily/logrotate#!/bin/sh/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.confEXITVALUE=$?if [ $EXITVALUE != 0 ]; then/usr/bin/logger -t logrotate “ALERT exited abnormally with [$EXITVALUE]”fiexit 0简单的说明:/usr/sbin/logrotate工具调用了/var/lib/logrotate/logrotate.status和/etc/logrotate.conf两个文件。然后将执行的结果(就是那个$?,成功为0,不成功为非0)进行判断,非0时执行/usr/bin/logger命令。最后退出。看完定时计划任务,我们再来看主配置文件/etc/logrotate.conf(也就是公有变量)。具体内容如下:[root@moneyslow.com ~]# grep -vE “^$|^#” /etc/logrotate.conf weekly  //每周一次rotate(翻译是旋转,其实就是切割)rotate 4  //保留4份切割文件,多余删除,不计算新建日志文件create  //结束后创建一个新的空白日志文件dateext  //用日期作为切切割文件的后缀include /etc/logrotate.d  //将/etc/logrotate.d目录下的文件都加载进来(全都执行)/var/log/wtmp {  //仅针对/var/log/wtmp文件monthly  //每月执行一次create 0664 root utmp  //结束后创建新的空白日志,权限0664,所有者root,所属组utmpminsize 1M  //切割文件最少需要1M,否则不执行rotate 1  //保留1份,多余删除,不计算新建日志文件}/var/log/btmp {  //仅针对/var/log/btmpmissingok  //丢失不报错monthly  //每月执行一次create 0600 root utmp  //结束后创建新的空白日志,权限0600,所有者root,所属组utmprotate 1  //保留1份,多余删除,不计算新建日志文件}配置文件参数说明:missingok  日志切割期间产生错误将被忽略(如果日志丢失,不报错继续切割)daily、weekly、monthly、yearly  每天、每周、每月、每年执行create MODE OWNER GROUP  切割后指定创建新的空白文件的属性nocreate  不建立新的日志文件rotate N  保留N份,多余删除,不计算新建日志文件dateext  用当前日期作为后缀命名格式(默认年月日)dateformat .%s  配合dateext使用,紧跟在下一行出现,定义切割后的文件名,只支持%Y,%m,%d,%ssize/minsize  达到指定大小才会切割,默认单位bytes,还可以是KB和MBcompress  切割结束后,归档并使用gzip格式压缩nocompress  解除compress参数delaycompress  总是与compress参数一起使用,指示logrotate不要将最近的归档压缩,压缩将在下一次切割进行。nodelaycompress  解除delaycompress参数ifempty  即使日志为空,也执行切割notifempty  如果日志为空,切割不执行prerotate/endscript  在所有其他指令之前执行prerotate和endscript之间的命令。postrotate/endscript  在所有其他指令完成后,postrotate和endscript之间的命令将被执行。sharescripts  所有日志切割后统一执行一次脚本,如果没有配置该参数,则每个日志切割后都会执行一次脚本。errors ADDRESS  切割时的错误信息发送到指定的Emial地址mail ADDRESS  切割日志发送到指定的Email地址nomail  切割日志不发送邮件olddir DIRECTORY  切割后的日志文件放入指定目录,必须与当前日志处在同一文件系统noolddir  切割后的日志文件与当前文件放在同一目录下copytruncate  用于还在打开中的日志文件,把当前日志备份并截断;先拷贝后清空,可能丢失部分日志nocopytruncate  备份日志文件,但不截断。(2).查看上次切割日志时间/var/lib/logrotate/logrotate.status中默认记录logrotate上次切割日志文件的时间 [root@moneyslow.com logrotate]# cat /var/lib/logrotate/logrotate.statuslogrotate state…

  • CentOS7 解决TIME_WAIT过多的内核参数调整

    CentOS7 解决TIME_WAIT过多的内核参数调整

    默认情况下,我们会消除对操作系统施加的各种限制,以充分发挥硬件的性能。 主要的方法就是打开文件数的上限,启动进程数的上限,TCP/IP端口数的上限,促进TCP连接的重用,针对TCP欺诈的一些对策,以及通过禁用IPv6来提高资源效率等。 以下是具体方法,但是修改正式业务以前请务必进行彻底测试!!! 一、更改操作系统文件的最大数量和用户启动进程的最大数量 打开/etc/systemd/system.conf并更改以下内容 DefaultLimitNOFILE = 1048576 DefaultLimitNPROC = 1048576 二、打开/etc/sysctl.conf并更改以下内容 #kernel.threads-max = 29990 kernel.threads-max = 1060863 #fs.file-max = 379862 fs.file-max = 5242880 #net.ipv4.ip_local_port_range = 32768 60999 net.ipv4.ip_local_port_range = 1024 65535 #net.core.somaxconn = 128 net.core.somaxconn = 65535 #net.ipv4.tcp_max_syn_backlog = 128 net.ipv4.tcp_max_syn_backlog = 65535 #net.core.netdev_max_backlog = 1000 net.core.netdev_max_backlog = 16384 #net.ipv4.tcp_tw_reuse = 0 net.ipv4.tcp_tw_reuse =…

  • centos7的systemctl启动项优化

    centos7的systemctl启动项优化

    使用 systemctl list-unit-files 可以查看启动项 systemctl list-unit-files | grep enable 过滤查看启动项如下 abrt-ccpp.service enabled abrt为auto bug report的缩写 用于bug报告 关闭 abrt-oops.service enabled ———————- abrt-vmcore.service enabled ———————- abrt-xorg.service enabled ———————- abrtd.service enabled ———————- auditd.service enabled 安全审计 保留 autovt@.service enabled 登陆相关 保留 crond.service enabled 定时任务 保留 dbus-org.freedesktop.NetworkManager.service enabled 桌面网卡管理 关闭 dbus-org.freedesktop.nm-dispatcher.service enabled ———————- getty@.service enabled tty控制台相关 保留 irqbalance.service enabled 优化系统中断分配…

  • CentOS/RHEL 6/7 升级PHP版本 version 5.4 到 5.6

    CentOS/RHEL 6/7 升级PHP版本 version 5.4 到 5.6

    For CentOS/RHEL 7: # rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm # rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm For CentOS/RHEL 6: # rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm For CentOS/RHEL 5: # rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm After installing Webtatic yum repository, you have to remove the old version of php-common package. It will also delete it dependencies packages. # yum remove php-common yum install -y php56w…

  • centos7 开机自启动程序设置

    centos7 开机自启动程序设置

    修改开机脚本添加文件的权限  chmod +x /etc/rc.d/rc.local vi 这个rc.local 可以添加要开机自启动的脚本: systemctl start xxx.service 通过以上操作,就可以像CentOS6一样添加开机脚本了

  • Centos 7 安装mysql

    Introduction MySQL is a popular open source relational database. The popularity of MySQL means there is an abundance of information online and well documented client libraries available. MySQL supports many common database features such as replication, partitioning, triggers, views, and stored procedures. A plugin storage architecture allows support for multiple storage engines. Requirements Single server…

  • 如何在Centos7下修改网卡名称

    首先,禁止系统自带的命名规则,需要添加一个参数到内核启动文件中。 编辑 /etc/default/grub 添加 “net.ifnames=0” 如下图 利用如下命令重新生成grub配置文件: $ sudo grub2-mkconfig -o /boot/grub2/grub.cfg 编辑 /etc/sysconfig/network-scripts 下的相应文件 运行命令 udevadm control –reload-rules 重启网络服务

  • 如何禁止IPv6 on CentOS 7 / RHEL 7

    方法 1: Edit the /etc/sysctl.conf. # vi /etc/sysctl.conf Put the following entry to disable IPv6 for all adapter. net.ipv6.conf.all.disable_ipv6 = 1 For particular adapter. (If the network card name is eno16777736). net.ipv6.conf.eno16777736.disable_ipv6 = 1 To reflect the changes by executing the following command. # sysctl -p 方法 2: Create file called disableipv6.conf in /etc/sysctl.d. # vi /etc/sysctl.d/disableipv6.conf Put the…

  • Centos7 下如何配置静态ip地址

    Centos7 下如何配置静态ip地址

    In this small tutorial i will explain how to configure static ip address on CentOS 7 minimal. First, need to edit the set up for the ethernet. Let’s start with editing “/etc/sysconfig/network-scripts/ifcfg-enp0s3″ file: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 HWADDR=08:00:27:6C:FF:91 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPADDR=192.168.0.88 IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=ea68db6e-461e-427d-b9a8-bfcf6e1a4fc6 ONBOOT=yes Save and exit. Now, configure default getaway:…

  • Centos7  install sssssssssssssssssssssssssssssssssssssssssssss

    Centos7 install sssssssssssssssssssssssssssssssssssssssssssss

    如果没有netstat ,先安装:yum -y install net-tools [root@vultr ~]# curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py” % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1488k 100 1488k 0 0 3186k 0 –:–:– –:–:– –:–:– 3188k [root@vultr ~]# python get-pip.py Collecting pip Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB) 100% |████████████████████████████████| 1.2MB 607kB/s Collecting…