centos系统LVM逻辑卷如何使用调整

首先需要了解几个概念

  • PE (Physical Extend)  物理拓展
  • PV (Physical Volume)  物理卷
  • VG (Volume Group)  卷组
  • LV (Logical Volume)  逻辑卷

未分类

首先使用fdisk -l 查看硬盘状态,这次我们使用的是2块新硬盘sdb 和 sdc

未分类

接着使用fdisk /dev/sdb 对第一块硬盘进行分区

选择p显示分区状态,选择n进行分区,选择t进行标记 lvm的标记为8e,最后使用w保存分区信息。

未分类

接着就需要创建物理卷,也就是PV。

使用pvcreate /dev/sdb1 命令创建

使用pvs 命令查看 (pvdisplay查看详细)

未分类

可以看到系统中增加了sdb1的pv,大小为5G 未使用5G

接着创建卷组,也就是VG

使用vgcreate work /dev/sdb1 命令创建work卷组,同时将/dev/sdb1 加入进来。

使用vgs命令查看 (vgdisplay查看详细)

未分类

其中cl组是系统原有的,这次新的work组已经建立,大小5G,未使用5G

然后我们需要从VG上创建出逻辑卷,也就是LV

使用lvcreate -L 500M -n lv1 work 命令来从work卷组中分配500M大小,用于创建lv1的逻辑卷

用lvs可以查看

未分类

可以看到新的lv1逻辑卷已经建立。这个时候使用vgs查看会发现work组未使用空间只有4.5G了

随后我们需要在LV上建立文件系统,使用mkfs.ext4 /dev/work/lv1 命令创建ext4文件系统

未分类

最后就是需要挂载到相应的目录上了,使用mount /dev/work/lv1 /data 命令来挂载到/data目录

如果需要系统一启动就自动挂载,需要修改/etc/fstab 其中UUID可以使用blkid命令查询

未分类

未分类

第一步我们完成了,将一块新硬盘设置了LVM逻辑卷挂在到了一个目录(/data)下面。

未分类

那如果/data经过一段时间使用,剩余空间不足怎么办?这就需要我们来扩充lv1这个逻辑卷。

使用 lvextend -L +500M /dev/work/lv1 来增加500M空间,给逻辑卷增加空间不会影响文件系统,所以不需要卸载文件系统。

未分类

可以看到 /data目录已经进行了扩容,lv1逻辑卷扩容前后也发生了变化。需要记得使用resize2fs /dev/work/lv1 来同步文件系统

于是我们可以继续使用/data目录了,但当卷组不够用了怎么办?这就需要我们扩容了。

未分类

可以看到此时work卷组几乎没有未使用空间了,我们通过之前的方法把另外一块硬盘也创建PV 。过程就省略了,使用pvs查看新的sdc1分区已经创建了PV

未分类

使用vgextend work /dev/sdc1 命令将sdc1也加入到work卷组中来。使用vgs查看效果

未分类

发现work卷组变大了,有5G空间未使用,接着重复上述操作将它分配给lv1即可。

未分类

突然有一天,我们发现给/data(lv1)分配的空间用不掉,但其他地方缺少空间怎么办?

首先卸载目录/data

然后通过e2fsck -f /dev/mapper/work-lv1命令检测逻辑卷上的空余空间

未分类

使用resize2fs /dev/mapper/work-lv1 700M 将文件系统减少到700M

未分类

使用 lvreduce -L 700M /dev/work/lv1 使lv1卷缩小到700M

未分类

使用vgs发现work卷组未使用空间变大了。接着可以分给其他逻辑卷,这里就不再重复说明了。

至此,基础的LVM操作都涉及到了。但是使用虚拟机的时候,会发生另外一种情况,就是我们的sdb硬盘是可以修改变大的。这本身没有太大区别,当硬盘变大时,使用fdisk继续分区,然后依次创建pv、加入vg、分配给lv就可以了。

centos中apache使用问题

以下总结在配置及启动apache2时出现报错的处理方法

一、启动apache遇到错误:httpd: Could not reliably determine the server’s fully qualified domain name

[root@server httpd-2.2.4]# /usr/local/apache/bin/apachectl start
 
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

1)进入apache的安装目录:(视个人安装情况而不同) [root@server ~]# cd /usr/local/apache/conf
 
2)编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80

[root@server conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@server conf]# vi httpd.conf
#ServerName www.example.com:80
ServerName localhost:80

3)再重新启动apache 即可。

[root@server ~]# /usr/local/apache/bin/apachectl restart

二、重启报错apache2 address already in use:make_sock:could not bind to address [::]:80

此错误为端口被占用,只有进入root用户,才可以查看所有端口被占用的情况。

$su

#netstat -lnp | grep 80

tcp 0      x x.x.x.x:8084        ...   listen   1167/mono

tcp 0      x x.x.x.x:80          ...   listen   1194/inetd

udp 0      x x.x.x.x:2080        ...   listen   14427/drcomauthsvr

查看知道是Inetd占用了80端口

#kill 1194

#exit //退出root用户

$sudo apapche2ctl -k start

启动成功!

三、在安装完apache2之后的默认index.html网页里面输入文字显示乱码,修改AddDefaultCharset 也没有用,即使在网页头部添加meta,指定charset=GB2312|GBK也没有用

注意,亲,此处因为默认文档的字号为h1,大号字体,中文无法显示,此处修改为小号字体即可,本人修改为h5,乱码消失,正常显示中文!

四、在网页运行html文件调用cgi程序时,提示找不到cgi程序以及找到程序后得不到想要的结果。

首先查看apache2配置文件,在/etc/apache2/site-enables查看系统默认的cgi-bin目录,可以在这个里面根据需要来修改默认cgi-bin目录。apt安装完后默认的cgi-bin目录是在/usr/lib/cgi-bin/

具体是修改ScriptAlias参数,如果你不知道你的类似site-enables的目录在哪,毕竟各个版本有些不一样,可以直接搜索ScriptAlisa这个参数,因为不管哪个版本,这个参数基本没改动。

CENTOS 使用ANSIBLE 将PYTHON 包安装到VIRTUALENV环境中

使用root用户,则直接安装

pip: name=pkgname virtualenv=虚拟环境目录

如果以!root用户安装,ansible无法获取virtualenv可执行文件,需要手动将执行路径添加到PATH环境变量,在用户家目录的.local/bin目录下

environment:
      PATH: "{{ansible_env.PATH}}/{{ansible_user_dir}}/.local/bin"

完整实例:

tasks:
  - name: install pip packages
    pip: name={{item}} virtualenv=envdir
    with_items:
      - requests
      - flask
    environment:
      PATH: "{{ansible_env.PATH}}/{{ansible_user_dir}}/.local/bin"

CentOS&.NET Core初试-4-安装守护服务(Supervisor)

Supervisor是什么?

Supervisor 是一个用 Python 写的进程管理工具,可以很方便的用来启动、重启、关闭进程(不仅仅是 Python 进程)。除了对单个进程的控制,还可以同时启动、关闭多个进程,比如很不幸的服务器出问题导致所有应用程序都被杀死,此时可以用 supervisor 同时启动所有应用程序而不是一个一个地敲命令启动。

Supervisor能干什么?

Supervisor帮助我们解决在开发过程中遇到的以下问题:

  • ASP.NET Core应用程序运行在shell之中,如果关闭shell则会发现ASP.NET Core应用被关闭,从而导致应用无法访问,这种情况当然是我们不想遇到的,而且生产环境对这种情况是零容忍的。

  • 如果ASP.NET Core进程意外终止那么需要人为连进shell进行再次启动,往往这种操作都不够及时。

  • 如果服务器宕机或需要重启我们则还是需要连入shell进行启动。

安装Supervisor

首先安装Python包管理工具(Supervisor使用Python开发的),然后再安装supervisor。

yum install python-setuptools
easy_install supervisor

supervisor安装完成后会生成三个执行程序:

  • supervisortd :supervisor的守护进程服务(用于接收进程管理命令)

  • supervisorctl :客户端(用于和守护进程通信,发送管理进程的指令)

  • echo_supervisord_conf :生成初始配置文件程序。

配置Supervisor

添加supervisor文件夹以及conf.d配置文件夹

mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
mkdir /etc/supervisor/conf.d

修改supervisord.conf文件,在文件尾部:

[include]
files=/etc/supervisor/conf.d/*.conf

启动Supervisor服务

supervisord -c /etc/supervisor/supervisord.conf

program的配置

在supervisor的conf.d文件夹下新建一个程序配置文件,hellocore.conf:

#配置程序名称
[program:hellocore]
#运行程序的命令
command=dotnet hellocore.dll 
#命令执行的目录
directory=/home/hellocore/ 
#错误日志文件
stderr_logfile=/var/log/hellocore.err.log
#输出日志文件
stdout_logfile=/var/log/hellocore.out.log 
#进程环境变量
environment=ASPNETCORE_ENVIRONMENT=Production 
#进程执行的用户身份
user=root
#程序是否自启动
autostart=true
#程序意外退出是否自动重启
autorestart=true
#启动时间间隔(秒)
startsecs=5
stopsignal=INT

重载Supervisor的配置文件

supervisorctl reload #重新加载配置文件

客户端相关命令:

supervisorctl status #查看程序配置的状态
supervisorctl stop programname    #停止某一个程序配置
supervisorctl start programname   #加载某一个程序配置
supervisorctl restart programname #重新加载某一个程序配置
supervisorctl reload #重新加载配置
supervisorctl update

查看配置程序是否启动:

ps -ef | grep hellocore #programdllname

如下图,则Supervisor配置成功:

未分类

Supervisor配置成功

设置Supervisor开机启动

在 /usr/lib/systemd/system文件夹下新建supervisor.service配置文件,内容如下:

[Unit]
Description=supervisor
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target

将服务设置为开机启动:

systemctl enable supervisor.service
systemctl start supervisor.service

supervisor开机启动服务配置成功

未分类

配置Supervisor图形化管理

打开supervisor的配置文件

vi /etc/supervisor/supervisord.conf

找到配置:

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
;username=user              ; (default is no username (open server))ls
;password=123               ; (default is no password (open server))

修改成:

[inet_http_server] ; inet (TCP) 服务,默认是关闭的
port=*:9001      ;ip:端口,*代表所有IP
username=root               ;登陆账号,可以不设
password=root123              ;登陆账户,可以不设

保存好修改后,重启supervisor。

supervisorctl reload

防火墙查看9001端口是否开启

firewall-cmd --list-ports #查看已开放的端口

开启端口:

firewall-cmd --zone=public  --add-port=9001/tcp --permanent
firewall-cmd --reload #重启防火墙

命令含义:

--zone #作用域
--add-port=9001/tcp  #添加端口,格式为:端口/通讯协议
--permanent  #永久生效,没有此参数重启后失效

成功访问:

未分类

Centos关闭SELinux和防火墙的关闭

CentOS6.5 查看防火墙的状态:

[linuxidc@localhost ~]$service iptable status

显示结果:

[linuxidc@localhost ~]$service iptable status
Redirecting to /bin/systemctl status  iptable.service
  iptable.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)  –表示防火墙已经关闭

CentOS 6.5 关闭防火墙

[root@localhost ~]#servcie iptables stop                    –临时关闭防火墙
[root@localhost ~]#chkconfig iptables off                    –永久关闭防火墙

CentOS 7.2 关闭防火墙

CentOS 7.0 默认使用的是 firewall 作为防火墙,这里改为 iptables 防火墙步骤。

firewall-cmd –state #查看默认防火墙状态(关闭后显示 notrunning,开启后显示 running)

[root@localhost ~]#firewall-cmd –state
not running

检查防火墙的状态:

从 centos7 开始使用 systemctl 来管理服务和程序,包括了 service 和 chkconfig。

[root@localhost ~]#systemctl list-unit-files|grep firewalld.service            –防火墙处于关闭状态
firewalld.service                          disabled

或者

[root@localhost ~]#systemctl status firewalld.service
   firewalld.service – firewalld – dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

关闭防火墙:

systemctl stop firewalld.service #停止 firewall
systemctl disable firewalld.service #禁止 firewall 开机启动

[root@localhost ~]#systemctl stop firewalld.service
[root@localhost ~]#systemctl disable firewalld.service
 启动一个服务:systemctl start firewalld.service
 关闭一个服务:systemctl stop firewalld.service
 重启一个服务:systemctl restart firewalld.service
 显示一个服务的状态:systemctl status firewalld.service
 在开机时启用一个服务:systemctl enable firewalld.service
 在开机时禁用一个服务:systemctl disable firewalld.service
 查看服务是否开机启动:systemctl is-enabled firewalld.service;echo $?
 查看已启动的服务列表:systemctl list-unit-files|grep enabled

Centos 7 firewall 命令:
查看已经开放的端口:

firewall-cmd –list-ports

开启端口

firewall-cmd –zone=public –add-port=80/tcp –permanent

命令含义:

  • –zone #作用域

  • –add-port=80/tcp #添加端口,格式为:端口/通讯协议

  • –permanent #永久生效,没有此参数重启后失效

重启防火墙

firewall-cmd –reload #重启 firewall
systemctl stop firewalld.service #停止 firewall
systemctl disable firewalld.service #禁止 firewall 开机启动
firewall-cmd –state #查看默认防火墙状态(关闭后显示 notrunning,开启后显示 running)

CentOS 7 以下版本 iptables 命令
如要开放 80,22,8080 端口,输入以下命令即可

/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT

然后保存:

/etc/rc.d/init.d/iptables save

查看打开的端口:

/etc/init.d/iptables status

关闭防火墙
1) 永久性生效,重启后不会复原

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后复原

开启: service iptables start

关闭: service iptables stop

查看防火墙状态: service iptables status

下面说下 CentOS7 和 6 的默认防火墙的区别

CentOS 7 默认使用的是 firewall 作为防火墙,使用 iptables 必须重新设置一下

1、直接关闭防火墙

systemctl stop firewalld.service #停止 firewall

systemctl disable firewalld.service #禁止 firewall 开机启动

2、设置 iptables service

yum -y install iptables-services

如果要修改防火墙配置,如增加防火墙端口 3306

vi /etc/sysconfig/iptables

增加规则

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

保存退出后

systemctl restart iptables.service #重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

最后重启系统使设置生效即可。

systemctl start iptables.service #打开防火墙

systemctl stop iptables.service #关闭防火墙

解决主机不能访问虚拟机 CentOS 中的站点
前阵子在虚拟机上装好了 CentOS6.2,并配好了 apache+php+mysql,但是本机就是无法访问。一直就没去折腾了。

具体情况如下
1. 本机能 ping 通虚拟机
2. 虚拟机也能 ping 通本机
3. 虚拟机能访问自己的 web
4. 本机无法访问虚拟机的 web

后来发现是防火墙将 80 端口屏蔽了的缘故。

检查是不是服务器的 80 端口被防火墙堵了,可以通过命令:telnet server_ip 80 来测试。

解决方法如下:

/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT

然后保存:

/etc/rc.d/init.d/iptables save

重启防火墙

/etc/init.d/iptables restart

CentOS 防火墙的关闭,关闭其服务即可:
查看 CentOS 防火墙信息:/etc/init.d/iptables status
关闭 CentOS 防火墙服务:/etc/init.d/iptables stop

Centos 7 安装配置Zabbix 3.4和报错解决方法

Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案 访问官网https://www.zabbix.com/

1. 运行环境搭建

Zabbix组成:Web展示端(Zabbix-Web)、服务端(Zabbix-Server)、数据存储端和客户端(Zabbix-Agents)。可以安装在同一台服务器上,但是如果你拥有一个更大更复杂的环境,将它们安装在不同的主机上也是一个选项。
Zabbix服务器能够直接监控到同一网络中的设备,如果其他网络的设备也需要被监控,那还需要一台Zabbix代理服务器(Zabbix-Proxy)。

环境准备:lnmp(linux+nginx+mysql+php)或者lamp(linux+apache+mysql+php),大同小异,本文采用宝塔面板(linux管理面板)编译安装nginx+mysql+php,首先新建Zabbix站点和创建Zabbix数据库。

2. 安装 Repository with MySQL database

rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

3. 安装 Zabbix server

yum install zabbix-server-mysql

说明:

  • 如果出现类似以下报错
Loaded plugins: fastestmirror
...
One of the configured repositories failed (Unknown),and yum doesn't have enough cached data to continue.
...
Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again
  • 解决办法:

1、将/etc/yum.repos.d/epel.repo中的mirrorlist改为baseurl
2、/etc/resolv.conf文件中增加nameserver 144.144.144.144

4. 导入数据库

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

由于我使用的是宝塔面板,直接通过面板导入create.sql文件。

5. 配置数据库用户及密码

vi /etc/zabbix/zabbix_server.conf

找到添加下面三项,按自己数据库实际信息填写(数据库如果在本地,DBHost默认即可)。

DBHost=localhost    
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpw

启动zabbix-server并允许开机自启

systemctl enable zabbix-server
systemctl start zabbix-server

6. 配置Web前端

前端路径是/zabbix-3.4.9/frontends/php,上传到网站根目录,运行。

  • 根据报错,修改PHP参数:
max_input_time = 300
date.timezone = Asia/Shanghai
  • 安装完成后,出现下面报错:
zabbix server is not running: the information displayed may not be current.

查看log:

cat /var/log/zabbix/zabbix_server.log

看到类似如下信息:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

查看/var/lib/mysql文件夹的确没有mysql.sock文件,通过find查找mysql:

find / -name mysql.sock

文件在/tmp/mysql.sock这个位置,做个软连接报错消失。

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

centos 7 安装HAproxy四层TCP负载均衡配置及测试

未分类

haproxy负载均衡166.110.110.100
后端服务器1 166.110.110.1
后端服务器2 166.110.110.2

--------------------------------------------------centos 7 处理----------------------------------------------------
关闭SELinux
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq!  #保存退出
setenforce 0 #使配置立即生效

关闭centos 7的防火墙(仅在测试的时候)
systemctl stop firewalld.service
systemctl disable firewalld.service
--------------------------------------------------haproxy安装----------------------------------------------------
yum install wget gcc -y && wget -c --no-check-certificate https://src.fedoraproject.org/repo/pkgs/haproxy/haproxy-1.8.12.tar.gz && tar -xvf haproxy-1.8.12.tar.gz && cd haproxy-1.8.12

groupadd haproxy #添加haproxy组
useradd -g haproxy haproxy -s /bin/false #创建nginx运行账户haproxy并加入到haproxy组,不允许haproxy
--------------------------------------------------haproxy配置----------------------------------------------------
vi /etc/haproxy/haproxy.cfg

修改为以下配置
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
listen admin_stats  
        bind 127.0.0.1:1080               #监听端口  
        mode http                       #http的7层模式  
        option httplog                  #采用http日志格式  
        #log 127.0.0.1 local0 err  
        maxconn 10  
        stats refresh 30s               #统计页面自动刷新时间  
        stats uri /stats                #统计页面url  
        stats realm Proxy Haproxy  #统计页面密码框上提示文本  
        stats auth admin:admin          #统计页面用户名和密码设置  
        stats hide-version              #隐藏统计页面上HAProxy的版本信息  


listen test1  
        bind 0.0.0.0:80  
        mode tcp
        balance leastconn
        #maxconn 40000  
        #log 127.0.0.1 local0 debug  
        server s1 166.110.110.1:80  
        server s2 166.110.110.2:80
------------------------------------------------------------------------------------------------------
centos7下haproxy启动停止重启重载状态等控制命令
systemctl (start, stop, restart, try-restart, reload, force-reload, status) haproxy.service

haproxy web监控信息166.110.110.100为haproxy安装所在服务器IP
http://166.110.110.100:1080/status
-----------------------------后端安装lighttpd 作为测试用----------------------------------------------
systemctl stop firewalld.service
systemctl disable firewalld.service
关闭SELinux
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled

安装
yum install -y epel-release gcc gcc-c++ autoconf automake  zlib zlib-devel pcre-devel zip unzip libtool bzip2-* && yum install -y lighttpd && systemctl enable lighttpd

编辑配置文件关闭ipv6
vi /etc/lighttpd/lighttpd.conf
注释掉ipv6

启动服务器
systemctl restart lighttpd.service

默认目录及首页
/var/www/lighttpd/index.html

对两个index.html进行修改进行区别
后端第一个服务器
echo "<h1>this is upstream server 1" >> /var/www/lighttpd/index.html

后端第二个服务器
echo "<h1>this is upstream server 2" >> /var/www/lighttpd/index.html

访问haproxy所在服务器IP或者解析的域名刷新试试

-----------------------------Haproxy 负载均衡的8种算法----------------------------------------
balance roundrobin # 轮询,软负载均衡基本都具备这种算法

balance static-rr # 根据权重,建议使用

balance leastconn # 最少连接者先处理,建议使用

balance source # 根据请求源IP,建议使用

balance uri # 根据请求的URI

balance url_param,# 根据请求的URl参数'balance url_param' requires an URL parameter name

balance hdr(name) # 根据HTTP请求头来锁定每一次HTTP请求

balance rdp-cookie(name) # 根据据cookie(name)来锁定并哈希每一次TCP请求

Centos安装Python2.7与Python3.5双版本

前言

最近博主一直忙于工作之中,无法自拔(别问我为什么,因为穷 👿 );最近有个小项目用到了Python,但是无奈服务端的有个Python2.7,但是也不能更新他,因为有程序在用,无奈只能弄双版本的Python,下面就来说说具体的步骤。

未分类

正文

首先,先下载Python的源码包:https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tgz,执行

wget https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tgz

然后解压:

tar zxvf Python-3.5.5.tgz

将解压目录移动至/usr/local:

mv Python-3.5.5 /usr/local

进入目录,然后配置编译:

cd /usr/local/Python-3.5.5
./configure 
make
make install

创建软链接

ln -s /usr/local/Python3.5/python /usr/bin/python3

到这一步就全部完成了,此时在终端输入python3 -V即可看见输出Python 3.5.5

但是有时候安装上Python3,却没有pip3,那么继续执行如下脚本:

wget https://bootstrap.pypa.io/3.2/get-pip.py
python3 get-pip.py 

为了大家方便,我将这些操作整合成了一个shell脚本,运行下方的脚本即可一键安装:

yum install -y wget && wget -O install.sh https://www.licoy.cn/go/api/shell/python3.sh && sh install.sh

后记

有人说,这些东西网上都有,为什么自己还要写一份呢?

我也知道网上有,不过博客主要就是用来记录自己的所见所闻、所知所想,爹有娘有不如自己有,反正就相当于好记性不如烂笔头,自己写一遍更有利于加深对它的理解以及更好的去使用它。

CentOS 6.X 上安装配置 NFS 目录共享

NFS 简介

NFS(Network File System)即网络文件系统,是 FreeBSD 支持的文件系统中的一种,它允许网络中的计算机之间通过 TCP/IP 网络共享资源。在 NFS 的应用中,本地 NFS 的客户端应用可以透明地读写位于远端 NFS 服务器上的文件,就像访问本地文件一样。
目前 NFS 主要有三个版本(NFSv2,NFSv3,NFSv4)。 NFSv2 和 NFSv3 除了 3 版本支持更多的新特性以外,最主要的区别应该就是 NFSv2 是使用 UDP 协议进行传输的,所以 NFSv2 的连接在复杂网络环境下可能没有那么可靠,而 NFSv3 同时支持 UDP 和 TCP 协议。而 NFSv4 则是在 NFSv3 的基础上提升了性能,强制了安全策略,引入有状态的协议等…
当 Client 端要挂载 NFS 共享卷的时候,会发送 RPC 请求给服务端,而 NFS 服务端会在用户验证后将一个随机的 Cookie 传送至客户端,以便客户端使用这个 Cookie 来认证那些要访问的共享卷。
NFS 的验证支持内置的 IP/主机权限分配,同时也被 tcp wrappers 所限制。

未分类

上面这段话以及架构图都是我从网上找的,主要的作用大概就是撑个场子这样,你懂的。如果你只想快速地搭建一个 CentOS 上的 NFS 环境,跳过这段 …

一、环境

1、软件环境

  • Windows 10 x64

  • VMWare 12 x64

  • CentOS 6.7 x64 * 3

  • nfs-utils

  • nfs-utils-lib

  • rpcblind

2、服务器规划

未分类

注:

  • NFS Client 的数量可以根据实际情况自行调增更多。

二、NFS Server 环境准备

1、创建共享目录

登录连接到规划的 NFS Server 节点,使用 root 用户执行如下命令创建共享目录

[root@hadoop1 ~]# mkdir -p /data/shared

注:

  • 创建的共享目录的位置根据实际情况而定。比如,如果你的服务器上专门挂载了一块用于存放数据的大容量磁盘,该磁盘挂载到了 /data1 目录,那么你可以将共享目录创建在 /data1 下面(/data1/shared)

  • 这个共享目录是实际存放数据文件的位置,其他的 NFS Client 访问该位置获取共享的文件信息。

2、给共享目录读写权限

root 用户执行如下命令

[root@hadoop1 data]# cd /data

[root@hadoop1 data]# pwd

/data

[root@hadoop1 data]# chmod -R 777 shared

[root@hadoop1 data]# ll -d shared

drwxrwxrwx. 2 root root 4096 Aug  6 06:18 shared

三、安装与配置 NFS Server

可以根据服务器的配置以及具体的业务需求选取一台服务器作为 NFS Server,NFS Server 是用作文件物理存储的节点。因此,要考虑的是 NFS Server 服务器的磁盘资源是否满足需求。此处我选取 192.168.174.200 作为 NFS Server。SSH 连接到 192.168.174.200 服务器过程省略…

1、检查服务器是否已经安装有 nfs-utils

[root@hadoop1 ~]# rpm -qa | grep nfs-utils

[root@hadoop1 ~]#

如果已经安装了 nfs-utils 及 nfs-utils-lib 包,可以直接跳过第 2 步

2、安装 nfs-utils

root 用户执行如下命令安装 nfs-utils

[root@hadoop1 ~]# yum install -y nfs-utils

注:

  • 执行如上命令会安装 nfs-utils.x86_64 1:1.2.3-78.el6 包以及其依赖的包(版本可能不同)
nfs-utils-lib.x86_64 0:1.1.5-13.el6

keyutils.x86_64 0:1.4-5.el6

libgssglue.x86_64 0:0.1-11.el6

libtirpc.x86_64 0:0.2.1-15.el6

rpcbind.x86_64 0:0.2.0-16.el6
...
  • rpcbind 是用于端口映射的包,在 CentOS 5 上对应的是 portmap。

3、配置 NFS Server

NFS 的配置文件位于 /etc/exports,在 CentOS 6.7 中,/etc/exports 文件已经存在,内容为空。因此,我这儿使用 root 用户直接编辑此文件配置即可(如果没有此文件,可以直接创建此文件即可 touch /etc/exports 或者 vim /etc/exports)。

[root@hadoop1 ~]# vim /etc/exports

在文件中添加如下内容:

/data/shared 192.168.174.201(rw,sync,all_squash)
/data/shared192.168.174.202(rw,sync,all_squash)

注:

  • /data/shared192.168.174.201(rw,sync,all_squash) 表示 NFS Server 上的共享目录 /data/shared 允许来自 192.168.174.201 服务器上的所有用户(all_squash)的读写(rw)操作权限。且数据文件采用同步(sync)方式进行共享

  • 上面的文件也可以配置成一行 /data/shared192.168.174.*(rw,sync,all_squash) ,表示允许 192.168.174 这个网段的所有机器的访问

  • 配置文件中的内容格式如下,'()’ 中的选项列表之间没有空格

<输出目录> [客户端1 选项(访问权限,同步方式,用户映射)] [客户端2 选项(访问权限,同步方式,用户映射)]

  • 具体的配置详解不在此列出了,可以参考 CentOS 官网的解释 https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html

4、NFS Server 防火墙配置

root 用户执行如下命令编辑 iptables 文件

[root@hadoop1 shared]# vim /etc/sysconfig/iptables

添加如下内容,并保存退出

### rpcbind
-A INPUT -p udp -m multiport --dports 111,875,892,2049,10053,32769 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --dports 111,875,892,2049,10053,32803 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT  -p udp -m multiport --sports 111,875,892,2049,10053,32769 -m state --state ESTABLISHED -j ACCEPT
-A OUTPUT  -p tcp -m multiport --sports 111,875,892,2049,10053,32803 -m state --state ESTABLISHED -j ACCEPT

如下示例:

未分类

注:

  • 如果 NFS Server 没有开启防火墙服务,则可以跳过此步骤。
  • 由于 rpcbind 即映射了 tcp 端口,也映射了 udp 端口,因此需要配置 tcp/udp
  • 上面配置的这些端口都是 nfs server 服务默认监听的端口,默认的配置在 /etc/sysconfig/nfs 文件中可以查看到

5、启动 nfs

在启动 nfs 之前必须先启动 rpcbind,root 用户执行如下命令启动 rpcbind

[root@hadoop1 data]# service rpcbind start

Starting rpcbind:                                          [  OK  ]

root 用户执行如下命令启动 nfs

[root@hadoop1 data]# service nfs start

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

Starting RPC idmapd:                                       [  OK  ]

四、配置 NFS Client

使用 SSH 分别连接到 NFS Client 对应的两个节点 192.168.174.201/202

1、安装 nfs 包

使用 root 用户分别在两台客户端服务器上执行如下命令安装 nfs

[root@hadoop2 ~]# yum install -y nfs-utils

注:

  • NFS 客户端也要安装 nfs-utils 包,不然挂载不了

2、创建本地挂载目录

使用 root 用户分别在两台客户端服务器上执行如下命令创建两个本地目录,用于将 NFS Server 上的共享目录映射到本地目录。

[root@hadoop3 ~]# mkdir -p /data/shared

[root@hadoop3 ~]# cd /data

[root@hadoop3 data]# pwd

/data

[root@hadoop3 data]# chmod -R 777 shared

[root@hadoop3 data]# ll -d shared/

drwxrwxrwx. 2 root root 4096 Aug  6 06:43 shared/

注:

  • 上面命令我将 NFS 客户端的本地目录与 NFS Server 端的共享目录创建在相同的路径和相同的名称,但其实此处可以与 NFS Server 端不两只,此处我只是为了便于我好记忆。

3、挂载 NFS Server 共享目录到本地

[root@hadoop2 data] mount -t nfs 192.168.174.200:/data/shared /data/shared

查看挂载后的服务器文件系统

[root@hadoop2 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda2              97G  4.3G   87G   5% /

tmpfs                 1.9G   72K  1.9G   1% /dev/shm

/dev/sda1             283M   41M  227M  16% /boot

192.168.174.200:/data/shared

                       97G   16G   76G  18% /data/shared

可以看到多出了一个将 192.168.174.200:/data/shared 挂载到本地的 /data/shared 目录的记录

五、验证

1、在 NFS Client 节点创建文件

在 192.168.174.202 服务器上执行如下命令

[root@hadoop3 data]# cd shared

[root@hadoop3 shared]# vim test.text

输入如下内容,保存退出:

This is a test text!

查看 192.168.174.202 服务器上的 /data/shared 目录,有 test.text 文件

[root@hadoop3 shared]# pwd

/data/shared

[root@hadoop3 shared]# ll

total 4

-rw-r--r--. 1 nfsnobody nfsnobody 21 Aug  6 09:38 test.text

[root@hadoop3 shared]# cat test.text

This is a test text!

2、查看另外两个节点的目录

登录 192.168.174.200/201 服务器,查看 /data/shared 目录,可以看到两个节点上都能访问刚刚在 202 上创建的 test.text 文件,如下所示:

200:

[root@hadoop1 shared]# pwd

/data/shared

[root@hadoop1 shared]# ll

total 4

-rw-r--r--. 1 nfsnobody nfsnobody 21 Aug  6 09:38 test.text

201:

[root@hadoop2 shared]# pwd

/data/shared

[root@hadoop2 shared]# ll

total 4

-rw-r--r--. 1 nfsnobody nfsnobody 21 Aug  6 09:38 test.text

3、在 NFS Client 上修改文件内容

在 192.168.174.201 上修改文件,并在文件下方添加一行 Hello World 并保存退出

[root@hadoop2 shared]# vim test.text

This is a test text!

Hello World

4、查看另外两个节点的文件内容

查看 192.168.174.200/202 上的 /data/shared/test.text 文件内容:

200:

[root@hadoop1 shared]# pwd

/data/shared

[root@hadoop1 shared]# cat test.text

This is a test text!

Hello World

202:

[root@hadoop3 shared]# pwd

/data/shared

[root@hadoop3 shared]# cat test.text

This is a test text!

Hello World

可以看到更改后的内容也同时在另外两个节点上生效了。

至此,我们在 CentOS 6.X 上安装配置 NFS 共享文件目录就完成了。

centos升级glibc至2.18

官方的glibc源只更新到2.12版,很多业务需要升级到更高级版,这里介绍编译glibc升级的方式。

安装gcc与wget

sudo yum install gcc
sudo yum install wget

下载glibc-2.18.tar.gz

wget http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz

解压并进入到glibc-2.18

tar glibc-2.18.tar.gz
cd glibc-2.18

创建build文件夹

mkdir  ../glibc-build

cd  ../glibc-build

编译

../glibc-2.18/configure  --disable-sanity-checks
make&&make install

重启生效