Feb 232018
 

对于Php的程序,已经很久没搞过安装,这次安装,也遇到一些麻烦,这里就记录一下,主要是php版本的问题。

Testlink目前的版本是1.19.6,对php 7.1支持有bug,所以我就换成php 5.6. CentOS 7 带的mariadb版本是5.5,Testlink要求是5.6以上的版本。

Continue reading »

Jan 022018
 

blog已经有两年时间没动过。上次把内存改成2G后,使用了1年,又出现内存不足,无法连接数据库的问题。最终解决的办法就是升级php。

先升级系统,发现update,也是把系统升级到centos 7.4

yum update

查看升级结果

# uname -a
Linux chenshake.com 3.10.0-693.11.1.el7.x86_64
#1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
添加IUS的repo源,这是专门针对红帽系统提供rpm包更新的。应该是品质很高
yum install https://centos7.iuscommunity.org/ius-release.rpm

删除php

yum remove php-common mod_php php-cli

升级php7

yum install php70u php70u-pdo php70u-mysqlnd \
php70u-opcache php70u-xml php70u-gd \
php70u-devel php70u-mysql

重启httpd

systemctl restart httpd

查看结果

# php -v
PHP 7.0.26 (cli) (built: Nov 27 2017 11:26:34) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.26, Copyright
	 (c) 1999-2017, by Zend Technologies
Dec 272017
 

今天练习了一下使用github。当然肯定是用命令下来玩。

创建repo

我需要创建一个gittest的repo,需要使用github的api接口才行。

curl -u 'shake.chen@gmail.com' \
https://api.github.com/user/repos -d '{"name":"gittest"}'
这个时候,就提示输入密码,成功创建后,会看到一堆的输出。

删除Repo

删除gittest的repo,也是需要用api才行
curl -X DELETE -u "shake.chen@gmail.com" \
https://api.github.com/repos/shake/gittest

保存密码

由于github默认采用https,通过https的缺点就是不能使用密钥,每次push都是需要输入用户名和密码。那么可以用下面的办法,只需要第一次输入后,就会保存起来。

git config --global credential.helper cache

cache生效时间15分钟

git config --global credential.helper 'cache --timeout=3600'
当希望永久生效
git config --global credential.helper store

git config

整理一下我的git config
git config --global credential.helper store
git config --list
git config --global user.name "shake"
git config --global user.email "shake.chen@gmail.com"
git config --list

初始化repo

下面就是我的步骤

cd /home
mkdir test
cd test
echo "# ks" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/shake/gittest.git
git push origin master

Dec 122017
 

记录一下自己在CentOS下的一些调整。我笔记本虚拟机的初始化操作的记录。

Systemd

这是CentOS 7最大改动的地方,让大家需要时间去熟悉

所有的服务

systemctl list-units --type service

启动的服务

systemctl list-unit-files --type=service | grep enabled

一个服务

# systemctl status <name>
# systemctl stop <name>
# systemctl disable <name>
# systemctl start <name>
# systemctl restart <name>

https://www.rayheffer.com/essential-linux-skills-with-centos-7-managing-services-with-systemd/

Chrony服务

CentOS 7 其实是建议采用chrony服务来实现同步时间。我采用最小化安装CentOS 7的时候,Chrony服务是没安装

yum install chrony
systemctl start chronyd
systemctl enable chronyd

默认同步时间的服务器是CentOS,你可以修改成国内的时间服务器

编辑 /etc/chrony.conf

server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst

这个时候,重启chronyd服务

systemctl restart chronyd
chronyc sources

这个时候你就会发现有国内的时间服务器。需要注意,如果你机器时间和标准时间差异很大,你需要强制同步

当你强制同步时间前,先要把chrony服务停止
systemctl stop chronyd
chronyd -q 'pool pool.ntp.org iburst'
强制同步时间后,再启动chrony服务

红帽的文档,是世界上最好的,准确的文档

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-using_chrony

chronyc tracking
chronyc sources
chronyc sourcestats

Date and Time

查看当前时间和时区

# timedatectl status
      Local time: Tue 2017-12-12 18:02:46 CST
  Universal time: Tue 2017-12-12 10:02:46 UTC
        RTC time: Tue 2017-12-12 10:02:46
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

如果你希望手工修改时间,这个时候,你需要先停止同步时间

timedatectl set-ntp 0

这个时候,你就可以设置时间

timedatectl set-time 17:00:00

如果启用ntp 服务

timedatectl set-ntp 1

修改日期

timedatectl set-time ‘YYYY-MM-DD  HH:MM:SS’

查看硬件时间

hwclock

同步system时间到硬件

hwclock --hctosys

http://linuxtechlab.com/playing-date-time-rhelcentos/

搜索

我们经常需要搜索某个配置文件

find /etc -name "yum.*" -type f

很多技巧,-type f,搜索文件,-type d 搜索目录

还有一种简单办法,就是安装mlocate的包,可以直接搜索

yum install mlocate

更新数据库

updatedb
# locate yum.conf
/etc/yum.conf
/usr/share/man/man5/yum.conf.5

这种方式其实其实是不建议使用,还是使用find比较好。

查看一个文件是属于哪个rpm包

# rpm -qf /etc/yum.conf
yum-3.4.3-154.el7.centos.noarch

查看rpm包包含哪些文件,已经安装的rpm包

 rpm -ql chrony
/etc/NetworkManager/dispatcher.d/20-chrony
/etc/chrony.conf
/etc/chrony.keys

如果需要搜索关键字

grep -rlw "tecadmin" /var/log

加上 -i参数,就是不区分大小写

https://tecadmin.net/find-all-files-containing-specific-text-on-linux/

内核版本

查看操作系统版本

cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
查看内核版本,现在内核的版本是
# uname -a
Linux server01.chenshake.com 3.10.0-693.el7.x86_64

#1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
以前内核版本号很难记忆,现在其实已经加上时间。这个内核版本,是8月22日的版本。这是centos 7.4默认的内核版本号。
如果升级一下,你会发现最新的版本号是
]# uname -a
Linux server01.chenshake.com 3.10.0-693.11.1.el7.x86_64

#1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

升级

升级系统的包

yum update
可能会导致内核升级,需要重启机器才能生效。
升级操作系统版本,例如从7.3升级7.4
yum upgrade

vim

yum install vim

编辑  /etc/profile

# add at the last line
alias vi='vim'

让设置马上生效

source /etc/profile

CentOS7 的vim 默认已经已经支持恢复到上次光标位置的功能,基本不需要啥调整就可以使用。

如果需要做修改配置就编辑 /etc/vimrc 文件就可以。

set ignorecase

我增加搜索的时候忽略大小写。

Selinux

关闭selinux是一个惯例,包括检查selinux是否关闭。

# sestatus
SELinux status:                 enabled

关闭selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

我的习惯就是重启机器,确保生效。

# sestatus
SELinux status:                 disabled

设置Repo

为了方便,其实最好是把红帽的yum的工具包都装上。

查看repo

cd /etc/yum.repos.d/
mkdir backup
move CentOS* ./backup/

设置阿里源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

检查

yum clean all
yum makecache
yum list | wc -l

如果我们希望增加一个docker的repo,可以用这个方法

yum-config-manager \
--add-repo https://download.docker.com/linux/centos/docker-ce.repo

lrzsz

这个工具,其实非常方便xshell下非常方便,上传和下载文件。

yum install lrzsz

关闭防火墙

systemctl status firewalld
systemctl disable firewalld.service
systemctl stop firewalld.service

主机名

需要搞清楚hostname和FQDN Name的区别

设置hostname

# cat /etc/hostname
server01

如果希望修改,可以使用

hostnamectl –static set-hostname server01

让修改马上生效

hostname -F /etc/hostname

设置FQDN

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.10	server01.chenshake.com	server01
查看
# hostname
server01

hostname -f
server01.chenshake.com

-f,含义是FQDN,类似域名的名称。

通过hostnamectl 还能查看系统的整体状况,是vm还是物理机器。

# hostnamectl status
   Static hostname: server01
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 7c4bea6eadac4a1cae068a167a0c961b
           Boot ID: 173cfb58e1c948ce947bd8261b327f91
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.11.1.el7.x86_64
      Architecture: x86-64

网络工具

一些常用的网络工具需要安装

  1. netstat 需要安装 net-tools
  2. nmap,需要安装 nmap
  3. lsof,需要安装lsof
yum install net-tools lsof nmap

使用

netstat -nlptu

需要对参数有啥了解

  • -n 表示不解析ip到域名,这个参数必须
  • -l 表示显示打开的端口
  • -p 表示显示端口应用名字
  • -t 表示tcp协议
  • -u 表示 udp协议

查看22端口情况

lsof -i :22

lsof 功能很强, 包括查看某个文件是否给某个进程使用

lsof /usr/sbin/sshd

nmap其实是扫描工具,可以扫描自己,查看端口的情况

nmap localhost

https://www.cyberciti.biz/faq/howto-install-nmap-on-centos-rhel-redhat-enterprise-linux/

关闭IPv6

编辑  /etc/sysctl.conf.

net.ipv6.conf.all.disable_ipv6 = 1

马上生效

sysctl -p

对比一下

关闭前

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:9e:48:a3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.10/24 brd 192.168.100.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::7a67:a172:a8cd:635/64 scope link
       valid_lft forever preferred_lft forever

关闭后

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:9e:48:a3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.10/24 brd 192.168.100.255 scope global ens33
       valid_lft forever preferred_lft forever

http://aws-labs.com/disable-ipv6-centos-7-rhel-7/

最大打开文件数量

下面内容还没完全理解

在开发运维的时候我们常常会遇到类似“Socket/File: Can’t open so many files”,“无法打开更多进程”,这个时候,我们需要调整系统的默认参数。

file-max

内核可分配的最大文件数

# cat /proc/sys/fs/file-max
396334

系统最大打开文件描述符数

cat /proc/sys/fs/file-nr
960	0	396334
临时修改
 echo 1000000 > /proc/sys/fs/file-max

永久性修改 在/etc/sysctl.conf中设置

fs.file-max = 1000000

单个进程最大打开文件描述符数,nr_open是单个进程可分配的最大文件数

soft link

# ulimit -n
1024

hard link

# ulimit -Hn
4096

修改

http://blog.csdn.net/superchanon/article/details/13303705

http://blog.51cto.com/qujunorz/1703295

https://unix.stackexchange.com/questions/127777/how-to-configure-the-process-open-file-limit-of-a-user

Jul 072017
 

一直以来都希望解决一个问题,就是开机的情况下,对新增加的硬盘进行raid的设置。现在Ceph已经很流行,对于SATA磁盘来说,一般都是需要通过Raid卡设置成Raid0,这样可以利用Raid卡的Cache,性能更好。那么其实这个时候就带来一个问题,如果磁盘坏了,更换磁盘,那么就必须重启机器。

Continue reading »

Mar 152017
 

CentOS7,网卡名字,采用consistent network device naming,简单的说,网络的名字,已经不是以前的eth0,eth1,你装系统前,你根本就不知道他叫啥名字。

这样的命名,好处就是你机器重启,增加pci设备,不会导致原来的设备名称发生改变。如果我们通过grub,修改内核的方式,改变回到以前的网卡命名,这种方式在新的设备里,会出现很多问题,你会发现每次重启机器,网卡名字都是会改变,一直都是在不停的变化,让你疯掉。

Continue reading »