/**
* 获取图片的Base64编码(不支持url)
* @date 2017-02-20 19:41:22
*
* @param $img_file 传入本地图片地址
*
* @return string
*/
function imgToBase64($img_file) {

$img_base64 = ”;
if (file_exists($img_file)) {
$app_img_file = $img_file; // 图片路径
$img_info = getimagesize($app_img_file); // 取得图片的大小,类型等

//echo ‘<pre>’ . print_r($img_info, true) . ‘</pre><br>’;
$fp = fopen($app_img_file, “r”); // 图片是否可读权限

if ($fp) {
$filesize = filesize($app_img_file);
$content = fread($fp, $filesize);
$file_content = chunk_split(base64_encode($content)); // base64编码
switch ($img_info[2]) { //判读图片类型
case 1: $img_type = “gif”;
break;
case 2: $img_type = “jpg”;
break;
case 3: $img_type = “png”;
break;
}

$img_base64 = ‘data:image/’ . $img_type . ‘;base64,’ . $file_content;//合成图片的base64编码

}
fclose($fp);
}

return $img_base64; //返回图片的base64
}
//调用使用的方法
$img_dir = dirname(__FILE__) . ‘/uploads/img/11213223.jpg’;
$img_base64 = imgToBase64($img_dir);
echo ‘<img src=”‘ . $img_base64 . ‘”>’; //图片形式展示
echo ‘<hr>’;
echo $img_base64; //输出Base64编码
文章来源:https://www.cnblogs.com/cloudshadow/p/php_img_to_base64.html

php 将图片转成base64

在工作当中经常会登录远程服务器安装软件、部署应用或者拷贝文件到远程服务器上,都会提示输入密码才能完成相关的操作。工作中如果要频繁登录服务器和拷贝文件的情况下,经常输入密码难免会觉得麻烦,且效率低下。而且在持续集成的场景下,自动部署应用时是没有人工干预的,这种情况如果要输入密码才能拷贝文件至远程服务器,就不能实现自动部署的功能了。下面以A服务器与B服务器双向实现免密码登录和拷贝文件为例,介绍相关的配置。
A服务器地址:192.168.1.200,下面简称A
B服务器地址:192.168.1.201,下面简称B

1、在A生成密钥对
ssh-keygen -t rsa -P “”

执行上述命令,一路回车,会在当前登录用户的home目录下的.ssh目录下生成id_rsa和id_rsa.pub两个文件,分别代表密钥对的私钥和公钥,如下图所示:
rsa密钥对

2、拷贝A的公钥(id_rsa.pub)到B
这里拷贝到B的root用户home目录下为例:

scp /root/.ssh/id_rsa.pub root@192.168.1.200:/root

3、登录B
拷贝A的id_rsa.pub内容到.ssh目录下的authorized_keys文件中

cd /root
cat id_rsa.pub >> .ssh/authorized_keys

4、此时在A中用SSH登录B或向B拷贝文件,将不需要密码
ssh root@192.168.1.201
scp abc.txt root@192.168.1.201:/root
实现B免密码登录A,操作方式是一样的,在B中用ssh-keygen生成ssh密钥对,将公钥拷贝到A中,A将B的公钥拷贝到.ssh目录下的authorized_keys文件中即可。

快捷方式
ssh-copy-id -i ~/.ssh/id_rsa.pub root@服务器地址

来源 https://blog.csdn.net/xyang81/article/details/51477925

1 、临时生效(使用centos5,6,7版本)

hostname 修改的计算机名称

[root@localhost ~]# hostname centos
[root@localhost ~]# hostname
centos

[root@centos ~]# hostname
centos

2 永久修改

centos 7.x

[root@localhost ~]# vi /etc/hostname
centos

centos 6.x

[root@centos ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos
[root@centos ~]# hostname
centos

1,配置DNS

vi /etc/resolv.conf

nameserver 192.168.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

2,配置网关:

vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.0.1
3,配置ip地址: (找到自己的ifcfg)
vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=”eth0″
HWADDR=”00:0C:29:6C:BB:E6″
NM_CONTROLLED=”yes”
ONBOOT=”no”
NETMASK=255.255.255.0
IPADDR=192.168.0.8
GATEWAY=192.168.0.1
BOOTPROTO=static
ONBOOT=yes
PEERDNS=yes

4,重新启动服务:

/etc/init.d/network restart
或使用命令:
service network restart

centos配置网络