存档

文章标签 ‘Linux’

CentOS上,三步创建与root一样权限的用户

2018年1月3日 没有评论

三步创建一个用户,使他有与root一样的权限。
1. 上root下,创建一个用户“app”
[root@daddylinux~]#useradd app
[root@daddylinux~]#passwd app
2. 限定app使用root特权,如下所示,编辑visudo文件。
[root@daddylinux~]# visudo
3. 在最后一行,添加下列信息。
app ALL=(ALL) ALL
退出并保存。

分类: Linux, 解决方案 标签: , ,

Mysql INNODB存储引擎表损坏修复方法(转)

2017年12月10日 没有评论

设你正在运行使用InnoDB表格的MySQL,糟糕的硬件设备,驱动程序错误,内核错误,不幸的电源故障或某些罕见的MySQL错误使你的InnoDB表空间被损坏了。
在这种情况下,InnoDB的一般会出现这样的输出:

InnoDB: Database page corruption on disk ora failed
InnoDB: file read of page 7.
InnoDB: You may have to recover from a backup.
080703 23:46:16 InnoDB: Page dump in ascii and hex (16384bytes):
… 这里省略很多二进制和十六进制编码…
080703 23:46:16 InnoDB: Page checksum 587461377,prior-to-4.0.14-form checksum 772331632
InnoDB: stored checksum 2287785129, prior-to-4.0.14-form storedchecksum 772331632
InnoDB: Page lsn 24 1487506025, low 4 bytes of lsn at page end1487506025
InnoDB: Page number (if stored to page already) 7,
InnoDB: Database page corruption on disk or a failed

mysqldump导出库时报错如下:
“mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `; at row:6880″
或是操作对应表时,也会报错。这时数据库会重启。
当时想到的是在修复之前保证数据库正常,不是这么异常的无休止的重启。

使用innodb_force_recovery =1,正如你所看到的,即使日志文件中有校验失败的记录,但CHECK TABLE还是说表格是正确的。
这意味着你不能太依赖CHECKTABLE在InnoDB上执行的结果。
所以就修改了配置文件的一个参数:innodb_force_recovery
innodb_force_recovery影响整个InnoDB存储引擎的恢复状况。默认为0,表示当需要恢复时执行所有的,
innodb_force_recovery可以设置为1-6,大的数字包含前面所有数字的影响。
当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作是不允许的。
1(SRV_FORCE_IGNORE_CORRUPT):忽略检查到的corrupt页。
2(SRV_FORCE_NO_BACKGROUND):阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。
3(SRV_FORCE_NO_TRX_UNDO):不执行事务回滚操作。
4(SRV_FORCE_NO_IBUF_MERGE):不执行插入缓冲的合并操作。
5(SRV_FORCE_NO_UNDO_LOG_SCAN):不查看重做日志,InnoDB存储引擎会将未提交的事务视为已提交。
6(SRV_FORCE_NO_LOG_REDO):不执行前滚的操作。
因为错误日志里面提示出现了坏页,导致数据库崩溃,所以这里把innodb_force_recovery 设置为1,忽略检查到的坏页。
重启数据库之后,找到错误信息出现的表

因为后者可以通过使用OPTIMIZE TABLE命令来修复,但这和更难以恢复的表格目录(table dictionary)被破坏的情况来说要好一些。

操作步骤:

修改my.cnf 配置文件,添加innodb_force_recovery = 1运行InnoDB,然后重启mysql 。

1,建议一个备份表,T_MinuteStore_BAK,使用MYISAM存储引擎,建表语句如下:

CREATE TABLE `T_MinuteStore_BAK` (
`T_MinuteStore_ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ‘行标识’,
`siteID` int(11) DEFAULT NULL COMMENT ‘站点标识’,
`genTime` datetime DEFAULT NULL COMMENT ‘监测时间’,
`itemID` int(11) DEFAULT NULL COMMENT ‘监测项目’,
`value` varchar(255) DEFAULT NULL COMMENT ‘监测值’,
`flag` varchar(255) DEFAULT NULL COMMENT ‘异常标志’,
`filterFlag` bit(1) DEFAULT NULL COMMENT ‘过滤标志’,
PRIMARY KEY (`T_MinuteStore_ID`)
) ENGINE=MYISAM AUTO_INCREMENT=188995 DEFAULT CHARSET=utf8 COMMENT=’监测分钟数据–5分钟一组数据’;

2,把T_MinuteStore表中的数据导入到新表T_MinuteStore_BAK.

insert into T_MinuteStore_BAK select * from T_MinuteStore;

提示报错: 2013 (HY000): Lost connection TO MySQL server during query
你可能想对数据表进行扫描直到第一个被损坏的行,然后从MyISAM表中得到结果?
不幸的是,运行之后的T_MinuteStore_BAK表格是只有一部份数据。
这里查看T_MinuteStore_BAK表中,主键 T_MinuteStore_ID 从最小值到160861,可以看出是被顺序插入的数据。
那么现在就好办了,说明从16081之后,有损坏的数据行。
下面作下插入数据测试,看看大约有多少行数据损坏。
insert into T_MinuteStore_BAK select * from T_MinuteStore where T_MinuteStore_ID>161000;
执行命令后,还是报错。
最后测试;
161500160861
此主键之间的数据,有损坏,其它数据恢复正常。总计100万行数据,只丢了几百行数据,完全可以承受。
3, 删除掉原表: drop table T_MinuteStore;注释掉innodb_force_recovery 之后,重启Mysql。
4,重命名 T_MinuteStore_BAK:

rename table T_MinuteStore_BAK to T_MinuteStore;
5,最后将表T_MinuteStore修改回存储引擎:

alter table T_MinuteStore engine = innodb;

最后将数据库数据导出,测试导出成功,未发现问题。备份好数据,然后更换好硬盘,重装好Mysql ,将数据导入。
测试程序,一切正常。

分类: 解决方案 标签: , ,

CentOS下lv调整空间大小

2017年10月20日 没有评论

一、目的

在使用CentOS6.3版本linux系统的时候,发现根目录(/)的空间不是很充足,而其他目录空间有很大的空闲,所以本文主要是针对现在已有的空间进行调整。首先,先来查看一下系统的空间分配情况:

1
2
3
4
5
6
7
8
[root@CentOS-78 /]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_centos-lv_root  
                       50G   14G   34G  30% /  
tmpfs                 1.9G     0  1.9G   0% /dev/shm  
/dev/sda1             485M   37M  423M   8% /boot  
/dev/mapper/vg_centos-lv_home  
                      404G  670M  382G   1% /home

下面的详细步骤部分将从vg_centos-lv_home分区下取出100G的空间添加到/vg_centos-lv_root分区上去。
二、详细步骤
1、卸载vg_centos-lv_home分区

1
2
3
4
5
6
7
8
9
10
11
12
[root@CentOS-78 /]# umount /home  
 
[root@CentOS-78 /]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_centos-lv_root  
                       50G   14G   34G  30% /  
tmpfs                 1.9G     0  1.9G   0% /dev/shm  
/dev/sda1             485M   37M  423M   8% /boot  
 
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G  
resize2fs 1.41.12 (17-May-2010)  
Please run 'e2fsck -f /dev/mapper/vg_centos-lv_home' first.

这一步设定vg_home-lv_home大小没有成功,系统提示我们先运行下面的命令,操作如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@CentOS-78 /]# e2fsck -f /dev/mapper/vg_centos-lv_home  
e2fsck 1.41.12 (17-May-2010)  
Pass 1: Checking inodes, blocks, and sizes  
Pass 2: Checking directory structure  
Pass 3: Checking directory connectivity  
Pass 4: Checking reference counts  
Pass 5: Checking group summary information  
/dev/mapper/vg_centos-lv_home: 1386/26836992 files (0.9% non-contiguous), 1855856/107344896 blocks  
 
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_home 282G  
resize2fs 1.41.12 (17-May-2010)  
Resizing the filesystem on /dev/mapper/vg_centos-lv_home to 73924608 (4k) blocks.  
Begin pass 2 (max = 43)  
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  
Begin pass 3 (max = 3276)  
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  
Begin pass 4 (max = 266)  
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  
The filesystem on /dev/mapper/vg_centos-lv_home is now 73924608 blocks long. 
 
[root@CentOS-78 /]# mount /home  
[root@CentOS-78 /]#  
[root@CentOS-78 /]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_centos-lv_root  
                       50G   14G   34G  30% /  
tmpfs                 1.9G     0  1.9G   0% /dev/shm  
/dev/sda1             485M   37M  423M   8% /boot  
/dev/mapper/vg_centos-lv_home  
                      278G  663M  263G   1% /home  
[root@CentOS-78 /]#  
 
[root@CentOS-78 /]# lvreduce -L 282G /dev/mapper/vg_centos-lv_home  
  WARNING: Reducing active and open logical volume to 282.00 GiB  
  THIS MAY DESTROY YOUR DATA (filesystem etc.)  
Do you really want to reduce lv_home? [y/n]: y  
  Reducing logical volume lv_home to 282.00 GiB  
  Logical volume lv_home successfully resized  
[root@CentOS-78 /]#

查看一下lv目前的情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@CentOS-78 /]# vgdisplay  
  --- Volume group ---  
  VG Name               vg_centos  
  System ID  
  Format                lvm2  
  Metadata Areas        1  
  Metadata Sequence No  5  
  VG Access             read/write  
  VG Status             resizable  
  MAX LV                0  
  Cur LV                3  
  Open LV               3  
  Max PV                0  
  Cur PV                1  
  Act PV                1  
  VG Size               465.27 GiB  
  PE Size               4.00 MiB  
  Total PE              119109  
  Alloc PE / Size       86472 / 337.78 GiB  
  Free  PE / Size       32637 / 127.49 GiB  
  VG UUID               1k4ooN-RFV9-uyf1-uMYf-aERG-YaGs-ZNoSD6

Free PE / Size指定的应该是现在可在分配的空间。
4、增加vg_centos-lv_root分区的大小
将可用的空间添加到vg_centos-lv_root分区上面:

1
2
3
4
5
6
7
8
9
10
11
12
[root@CentOS-78 /]# lvextend -L +127.40G /dev/mapper/vg_centos-lv_root  
  Rounding up size to full physical extent 127.40 GiB  
  Extending logical volume lv_root to 177.40 GiB  
  Logical volume lv_root successfully resized  
[root@CentOS-78 /]#  
 
[root@CentOS-78 /]# resize2fs -p /dev/mapper/vg_centos-lv_root  
resize2fs 1.41.12 (17-May-2010)  
Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required  
old desc_blocks = 4, new_desc_blocks = 12  
Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 46504960 (4k) blocks.  
The filesystem on /dev/mapper/vg_centos-lv_root is now 46504960 blocks long.

5、再次查看分区大小

1
2
3
4
5
6
7
8
[root@CentOS-78 /]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/mapper/vg_centos-lv_root  
                      175G   14G  153G   9% /  
tmpfs                 1.9G     0  1.9G   0% /dev/shm  
/dev/sda1             485M   37M  423M   8% /boot  
/dev/mapper/vg_centos-lv_home  
                      278G  663M  263G   1% /home

我们发现vg_centos-lv_root分区的空间已经增加了125G,之所以比lv_home减少的空间要多25G主要是由于我们把系统所有的可用的空间都加在了lv_root分区。
三、所遇到的问题
1、在卸载/home目录的时候失败
可先执行如下fuser命令,然后再umount即可:

1
2
[root@CentOS-78 /]# fuser -m /home  
[root@CentOS-78 /]#

2、设定完lv_home的大小,再次mount该分区时,发现用df命令无法看到给分区,此时只要在mount一次即可
3、在设定lv_root的大小时,不要把Free PE / Size的空间全部都用上,这很可能会出现Free PE空间不足的现象,建议保留一点Free PE的空间。

Ubuntu14.04找回管理员权限或root密码

2017年6月12日 没有评论

Ubuntu14.04系统中,因为误操作导致管理员密码丢失或无效,并且忘记root密码,此时无法进行任何root/sudo权限操作。可以通过GRUB重新设置root密码,并恢复管理员账户到正常状态。

启动系统,显示GRUB选择菜单(如果默认系统启动过程不显示GRUB菜单,则在系统启动时需要长按[Shift]键,显示GRUB界面),选择Advanced options for Ubuntu,按下[Enter]进入,选择recovery mode,不要按下回车键。

按下[e]键进入命令编辑状态,到 linux /boot/vmlinuz-……. ro recovery nomodeset 所在行,将“ro recovery nomodeset”替换为“quiet splash rw init=/bin/bash”,按下[F10]或者[Ctrl+x]重启系统。

此时以root身份启动一个可读写的bash,直接使用命令passwd更改root密码,然后按下[Ctrl+Alt+Delete]重启系统。

系统启动后进入字符终端[Ctrl+Alt+F<1...6>],使用root账户和密码登录系统,然后进行恢复管理账户状态操作。(图形界面终端为[Ctrl+Alt+F<7>])

分类: Linux, 解决方案 标签: , ,

限制ip访问ssh

2017年5月6日 没有评论

由于ssh的安全性问题。最安全的办法就是限制指定ip能访问。允许指定的ip访问ssh服务最为有效。
操作如下:
第一步:
vim /etc/hosts.allow
加入以下:
sshd:10.2.2.2:allow
sshd:192.168.1.0/255.255.255.0:allow

ps:10.2.2.2是指定单个ip访问,192.168.1.1-255是指定这个段访问。同理,自己改一下ip即可套用。

第二步:
vim /etc/hosts.deny
加入以下:
sshd:ALL

第三步:
/etc/init.d/networking restart
重启网络服务生效。

linux 网站目录文件权限的简单安全设置(转)

2017年5月1日 没有评论

网站目录文件权限的设置对网站的安全至关重要,下面简单介绍网站目录文件权限的基本设定。
我们假设http服务器运行的用户和用户组是www,网站用户为centos,网站根目录是/home/centos/web。
1、我们首先设定网站目录和文件的所有者和所有组为centos,www,如下命令:

chown -R centos:www /home/centos/web
2、设置网站目录权限为750,750是centos用户对目录拥有读写执行的权限,这样centos用户可以在任何目录下创建文件,用户组有有读执行权限,这样才能进入目录,其它用户没有任何权限。

find -type d -exec chmod 750 {} \;
3、设置网站文件权限为640,640指只有centos用户对网站文件有更改的权限,http服务器只有读取文件的权限,无法更改文件,其它用户无任何权限。

find -not -type d -exec chmod 640 {} \;
4、针对个别目录设置可写权限。比如网站的一些缓存目录就需要给http服务有写入权限。例如discuz x2的/data/目录就必须要写入权限。

find data -type d -exec chmod 770 {} \;

关于yum Error: Cannot retrieve repository metadata (repomd.xml) for repository:xxxxxx.

2017年4月28日 没有评论

这个错误其实很简单,错误信息已经提示你,就是xxxxxx.repo这个文件有问题。
(1)打开/etc/yum.repos.d/xxxxxx.repo文件
(2)enabled=1改成enabled=0
搞定。试试吧

分类: Linux, 解决方案 标签: ,

Linux下脚本上传文件到dropbox

2017年2月3日 没有评论

这里介绍一个可以上传文件到dropbox的脚本。不用安装,直接运行即可把文件上传到dropbox。
脚本地址:https://github.com/andreafabrizi/Dropbox-Uploader
也可以在本站直接下载:dropbox_uploader.sh
脚本使用方法:
语法:./dropbox_uploader.sh [OPTIONS]…
选项:-u [USERNAME] dropbox用户
-p [PASSWORD] dropbox密码
-f [FILE/FOLDER] 待上传的文件
-d [REMOTE_FOLDER] dropbox的目录,默认是 “/”
-v 返回详细进程模式
例子:
./dropbox_uploader.sh -u andrea.fabrizi@gmail.com -f /etc/passwd -v
./dropbox_uploader.sh -u andrea.fabrizi@gmail.com -f /var/backup/ -v
也可以在dropbox_uploader.sh文件填写好用户和密码,之后运行脚本时就不用再定义用户和密码。

ps:更新一下,最新的版本已经改变为需要设置一个密钥已经不需要用户密码了更为安全:

第一次先运行先进行下载程序:

curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
chmod 777 dropbox_uploader.sh
./dropbox_uploader.sh
会要求你输入
# Access token:
这个你需要登陆https://www.dropbox.com/developers/apps进行创建一个app的api支持,名字随便起。
在找到点击Generated access token后会有一大串的密钥复制到# Access token:后再运行以下示例命令就可以上传文件了。
注意:如果这地方输入错误的话,需要把这个脚本文件目录下.dropbox_uploader的文件删除,然后再运行文件输入正确的密钥才可以不然上传肯定是失败的。

上传命令示例:

Examples:

    ./dropbox_uploader.sh upload /etc/passwd /myfiles/passwd.old
    ./dropbox_uploader.sh upload *.zip /
    ./dropbox_uploader.sh download /backup.zip
    ./dropbox_uploader.sh delete /backup.zip
    ./dropbox_uploader.sh mkdir /myDir/
    ./dropbox_uploader.sh upload "My File.txt" "My File 2.txt"
    ./dropbox_uploader.sh share "My File.txt"
    ./dropbox_uploader.sh list

 

linux之sed用法

2017年1月4日 没有评论

sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换、删除、新增、选取等特定工作,下面先了解一下sed的用法
sed命令行格式为:
sed [-nefri] ‘command’ 输入文本

常用选项:
-n∶使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN的资料一般都会被列出到萤幕上。但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。
-e∶直接在指令列模式上进行 sed 的动作编辑;
-f∶直接将 sed 的动作写在一个档案内, -f filename 则可以执行 filename 内的sed 动作;
-r∶sed 的动作支援的是延伸型正规表示法的语法。(预设是基础正规表示法语法)
-i∶直接修改读取的档案内容,而不是由萤幕输出。

常用命令:
a ∶新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~
c ∶取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!
d ∶删除,因为是删除啊,所以 d 后面通常不接任何咚咚;
i ∶插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);
p ∶列印,亦即将某个选择的资料印出。通常 p 会与参数 sed -n 一起运作~
s ∶取代,可以直接进行取代的工作哩!通常这个 s 的动作可以搭配正规表示法!例如 1,20s/old/new/g 就是啦!

举例:(假设我们有一文件名为ab)
删除某行
[root@localhost ruby] # sed ’1d’ ab #删除第一行
[root@localhost ruby] # sed ‘$d’ ab #删除最后一行
[root@localhost ruby] # sed ’1,2d’ ab #删除第一行到第二行
[root@localhost ruby] # sed ’2,$d’ ab #删除第二行到最后一行

  显示某行
. [root@localhost ruby] # sed -n ’1p’ ab #显示第一行
[root@localhost ruby] # sed -n ‘$p’ ab #显示最后一行
[root@localhost ruby] # sed -n ’1,2p’ ab #显示第一行到第二行
[root@localhost ruby] # sed -n ’2,$p’ ab #显示第二行到最后一行

  使用模式进行查询
[root@localhost ruby] # sed -n ‘/ruby/p’ ab #查询包括关键字ruby所在所有行
[root@localhost ruby] # sed -n ‘/\$/p’ ab #查询包括关键字$所在所有行,使用反斜线\屏蔽特殊含义

  增加一行或多行字符串
[root@localhost ruby]# cat ab
Hello!
ruby is me,welcome to my blog.
end
[root@localhost ruby] # sed ’1a drink tea’ ab #第一行后增加字符串”drink tea”
Hello!
drink tea
ruby is me,welcome to my blog.
end
[root@localhost ruby] # sed ’1,3a drink tea’ ab #第一行到第三行后增加字符串”drink tea”
Hello!
drink tea
ruby is me,welcome to my blog.
drink tea
end
drink tea
[root@localhost ruby] # sed ’1a drink tea\nor coffee’ ab #第一行后增加多行,使用换行符\n
Hello!
drink tea
or coffee
ruby is me,welcome to my blog.
end

  代替一行或多行
[root@localhost ruby] # sed ’1c Hi’ ab #第一行代替为Hi
Hi
ruby is me,welcome to my blog.
end
[root@localhost ruby] # sed ’1,2c Hi’ ab #第一行到第二行代替为Hi
Hi
end

  替换一行中的某部分
  格式:sed ‘s/要替换的字符串/新的字符串/g’ (要替换的字符串可以用正则表达式)
[root@localhost ruby] # sed -n ‘/ruby/p’ ab | sed ‘s/ruby/bird/g’ #替换ruby为bird
  [root@localhost ruby] # sed -n ‘/ruby/p’ ab | sed ‘s/ruby//g’ #删除ruby

插入
[root@localhost ruby] # sed -i ‘$a bye’ ab #在文件ab中最后一行直接输入”bye”
[root@localhost ruby]# cat ab
Hello!
ruby is me,welcome to my blog.
end
bye

删除匹配行

sed -i ‘/匹配字符串/d’ filename (注:若匹配字符串是变量,则需要“”,而不是‘’。记得好像是)

替换匹配行中的某个字符串

sed -i ‘/匹配字符串/s/替换源字符串/替换目标字符串/g’ filename

CentOS openssh升级到openssh-7.4版本

2017年1月2日 没有评论

最近又暴出最新的漏洞。太可怕了。只能升级了。查了下大神们的升级操作。发出来给大家共享一下吧。

环境:
cat /etc/issue
CentOS release 6.5 (Final)

ssh -V
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013

openssl version -a
OpenSSL 1.0.1e-fips 11 Feb 2013

一、准备
备份ssh目录(重要)
cp -rf /etc/ssh /etc/ssh.bak

【 可以现场处理的,不用设置
安装telnet,避免ssh升级出现问题,导致无法远程管理(此步其实可以不用,测试过没必要因为ssh不会中断)
yum install telnet-server

vi /etc/xinetd.d/telnet
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}

默认不允许root登录

vi /etc/securetty
增加
pts/0
pts/1
pts/2
如果登录用户较多,需要更多的pts/*

/etc/init.d/xinetd restart
这样root可以telnet登录了

ssh升级后建议再修改回还原设置

二、安装
升级需要几个组件
yum install -y gcc openssl-devel pam-devel rpm-build

现在新版本,目前是openssh-7.4最新
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz

解压升级包,并安装
tar -zxvf openssh-7.4p1.tar.gz
cd openssh-7.4p1
./configure –prefix=/usr –sysconfdir=/etc/ssh –with-pam –with-zlib –with-md5-passwords –with-tcp-wrappers
make && make install

安装后提示:
/etc/ssh/ssh_config already exists, install will not overwrite
/etc/ssh/sshd_config already exists, install will not overwrite
/etc/ssh/moduli already exists, install will not overwrite
ssh-keygen: generating new host keys: ECDSA ED25519
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
/etc/ssh/sshd_config line 81: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 83: Unsupported option GSSAPICleanupCredentials

修改配置文件,允许root登录

vi /etc/ssh/sshd_config
#PermitRootLogin yes
修改为
PermitRootLogin yes

命令:
sed -i ‘/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin yes/’ /etc/ssh/sshd_config

重启openSSH
service sshd restart

升级后版本
ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.1e-fips 11 Feb 2013

如果之前你将原ssh目录修改名字
mv /etc/ssh /etc/ssh_bak

需要修改下配置:
修改配置文件,禁止root登录
sed -i ‘/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin no/’ /etc/ssh/sshd_config

可以不操作,禁止dns解析
sed -i ‘/^#UseDNS yes/s/#UseDNS yes/UseDNS no/’ /etc/ssh/sshd_config

可以不操作默认是22,修改ssh端口至6022
echo “Port 6022″ >> /etc/ssh/sshd_config

注:在升级SSH时你的SSH是不会因为升级或重启服务而断掉的.

问题1:
[root@testserver2 tmp]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: /etc/ssh/sshd_config line 81: Unsupported option GSSAPIAuthentication
/etc/ssh/sshd_config line 83: Unsupported option GSSAPICleanupCredentials [ OK ]

解决:
将/etc/ssh/sshd_config文件中以上行数内容注释下即可
sed -i ‘/^GSSAPICleanupCredentials/s/GSSAPICleanupCredentials yes/#GSSAPICleanupCredentials yes/’ /etc/ssh/sshd_config
sed -i ‘/^GSSAPIAuthentication/s/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/’ /etc/ssh/sshd_config
sed -i ‘/^GSSAPIAuthentication/s/GSSAPIAuthentication no/#GSSAPIAuthentication no/’ /etc/ssh/sshd_config

问题2:
更新后ssh有如下提示,但不影响使用:
[root@testserver2 tmp]# ssh 10.111.32.51
/etc/ssh/ssh_config line 50: Unsupported option “gssapiauthentication”

解决:
可以注释/etc/ssh/ssh_config的gssapiauthentication内容

——————————————————————————————
CentOS7升级openssh参考这里的内容
本次使用源码安装(系统需要gcc),各软件版本如下(例):

zlib-1.2.8
openssl-1.0.2h
openssh-7.3p1

安装步骤如下:

1、安装zlib
[root@CentOS7test ~]# cd zlib-1.2.8/
[root@CentOS7test zlib-1.2.8]# ./configure
[root@CentOS7test zlib-1.2.8]# make
[root@CentOS7test zlib-1.2.8]# make install

2、安装openssl
[root@CentOS7test ~]# cd openssl-1.0.2h/
[root@CentOS7test openssl-1.0.2h]# ./config –prefix=/usr/ –shared
[root@CentOS7test openssl-1.0.2h]# make
[root@CentOS7test openssl-1.0.2h]# make install

3、安装openssh
[root@CentOS7test ~]# cd openssh-7.3p1/
[root@CentOS7test openssh-7.3p1]# ./configure –prefix=/usr/local –sysconfdir=/etc/ssh –with-pam –with-zlib –with-md5-passwords –with-tcp-wrappers
[root@CentOS7test openssh-7.3p1]# make
[root@CentOS7test openssh-7.3p1]# make install

4、查看版本是否已更新
[root@CentOS7test openssh-7.3p1]# ssh -V
OpenSSH_7.3p1, OpenSSL 1.0.2h 3 May 2016

5、新介质替换原有内容
[root@CentOS7test openssh-7.3p1]# mv /usr/bin/ssh /usr/bin/ssh_bak
[root@CentOS7test openssh-7.3p1]# cp /usr/local/bin/ssh /usr/bin/ssh
[root@CentOS7test openssh-7.3p1]# mv /usr/sbin/sshd /usr/sbin/sshd_bak
[root@CentOS7test openssh-7.3p1]# cp /usr/local/sbin/sshd /usr/sbin/sshd

6-加载ssh配置重启ssh服务
[root@CentOS7test ~]# systemctl daemon-reload
[root@CentOS7test ~]# systemctl restart sshd.service

7、遇到的问题解决

问题1:
安装完成后,telnet 22端口不通,通过systemctl status sshd.service查看发现有警告信息
部分信息如Permissions 0640 for ‘/etc/ssh/ssh_host_ecdsa_key’ are too open

修正:
修改相关提示文件的权限为600,并重启sshd服务(systemctl restart sshd.service)
查看服务状态(systemctl status sshd.service)
例:chmod 600 /etc/ssh/ssh_host_ecdsa_key

问题2:
安装完成后,如需root直接登录

修正:
修改/etc/ssh/sshd_config文件,将文件中#PermitRootLogin yes改为PermitRootLogin yes
并重启sshd服务
升级后验证

问题3:
如果你使用了jenkins进行部署,升级后会影响jenkins部署,测试连接web端会报错 Algorithm negotiation fail
修正:
在web端修改sshd_config文件最后一行增加以下内容
KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
参考:http://stackoverflow.com/questions/32627998/algorithm-negotiation-fail-in-jenkins
————————————————————–

【临时修改版本号,运行很久的线上环境升级存在风险,如果可以的话只修改版本号吧(后期经过验证,这种修改版本号的方法无效,ssh -v IP可以查看版本)
查询
ssh -V
sshd -V
备份
cp /usr/bin/ssh /usr/bin/ssh.bak.version_edit
cp /usr/sbin/sshd /usr/sbin/sshd.bak.version_edit
修改
sed -i ‘s#OpenSSH_5.3p1#OpenSSH_7.2p1#g’ /usr/bin/ssh
sed -i ‘s#OpenSSH_5.3p1#OpenSSH_7.2p1#g’ /usr/sbin/sshd

补充汇总下:
centos7.X主机升级ssh
cp /usr/bin/ssh /usr/bin/ssh.bak.20161124
cp /usr/sbin/sshd /usr/bin/sshd.bak.20161124
mv /etc/ssh /etc/ssh.bak
—下载包、安装gcc 、编译等中间步骤参上边内容—
make && make install
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
echo ‘PermitRootLogin yes’ >> /etc/ssh/sshd_config
cp /etc/ssh.bak/sshd_config /etc/ssh/sshd_config 将原来的文件覆盖下这个新生成的内容
/bin/systemctl restart sshd.service

centos6.X升级ssh
cp /usr/bin/ssh /usr/bin/ssh.bak.20161124
cp /usr/sbin/sshd /usr/bin/sshd.bak.20161124
cp -rf /etc/ssh /etc/ssh.bak
—下载包、安装gcc 、编译等中间步骤参上边内容—
make && make install
sed -i ‘/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin yes/’ /etc/ssh/sshd_config
sed -i ‘/^GSSAPICleanupCredentials/s/GSSAPICleanupCredentials yes/#GSSAPICleanupCredentials yes/’ /etc/ssh/sshd_config
sed -i ‘/^UsePAM/s/UsePAM yes/#UsePAM yes/’ /etc/ssh/sshd_config
sed -i ‘/^GSSAPIAuthentication/s/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/’ /etc/ssh/sshd_config
sed -i ‘/^GSSAPIAuthentication/s/GSSAPIAuthentication no/#GSSAPIAuthentication no/’ /etc/ssh/sshd_config
service sshd restart

附录:
CentOS7 sshd_config配置内容
[python] view plain copy 在CODE上查看代码片派生到我的代码片
# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires explicit activation of protocol 1
#Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Ciphers and keying
#RekeyLimit default none

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don’t trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don’t read the user’s ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to ‘yes’ to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of “PermitRootLogin without-password”.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to ‘no’.
# WARNING: ‘UsePAM no’ is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server

CentOS6 sshd_config配置内容
[python] view plain copy 在CODE上查看代码片派生到我的代码片
# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don’t trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don’t read the user’s ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPICleanupCredentials yes
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to ‘yes’ to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of “PermitRootLogin without-password”.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to ‘no’.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server
UseDNS no
#GSSAPIAuthentication no
#GSSAPIAuthentication yes

20161205补充:
实际使用中发现ansible和jenkins使用时有些问题,网上查询了下,需要在/etc/ssh/sshd_config文件中最后增加两行:
[python] view plain copy 在CODE上查看代码片派生到我的代码片
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc

KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
因为升级了openssh太新导致通信时加密算法出现问题,加上后重启就可以了。