<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; Linux</title>
	<atom:link href="https://www.yunda51.com/?cat=18&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>MacOs下本地docker部署Nginx+Php详细流程</title>
		<link>https://www.yunda51.com/?p=1989</link>
		<comments>https://www.yunda51.com/?p=1989#comments</comments>
		<pubDate>Wed, 17 Jan 2024 08:12:30 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[docker]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[MacOs]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1989</guid>
		<description><![CDATA[大家好，今天实操一下本地docker如何部署Nginx+Php详细步骤，随着 Docker 容器化技术的不断发<a href="https://www.yunda51.com/?p=1989" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>大家好，今天实操一下本地docker如何部署Nginx+Php详细步骤，随着 Docker 容器化技术的不断发展，它已经成为了现代软件开发和部署中不可或缺的一部分。Docker 提供了一种轻量级、可移植的方式来打包和运行应用程序，使开发人员能够在不同的环境中轻松地部署和管理应用程序，废话不多说。<br />
<strong>1、docker下载：</strong><br />
进入Docker官网（<a href="https://www.docker.com/get-started/" title="docker官网">https://www.docker.com/get-started/</a>），如图位置，点击mac版本的docker下载：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/docker.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/docker.jpg" alt="docker" width="2726" height="1270" class="alignnone size-full wp-image-1990" /></a><br />
安装后，点击图标：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/1.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/1.jpg" alt="1" width="374" height="276" class="alignnone size-full wp-image-1993" /></a><br />
<strong>1.1、配置docker下载镜像:</strong><br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/1.2.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/1.2.jpg" alt="1.2" width="2540" height="1430" class="alignnone size-full wp-image-1996" /></a><br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/1.3.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/1.3.jpg" alt="1.3" width="2540" height="1430" class="alignnone size-full wp-image-1997" /></a></p>
<pre class="wp-code-highlight prettyprint">
&quot;registry-mirrors&quot;: [
    &quot;https://docker.mirrors.ustc.edu.cn/&quot;,
    &quot;https://hub-mirror.c.163.com/&quot;,
    &quot;https://reg-mirror.qiniu.com&quot;
  ]
</pre>
<p><strong>1.2、在本地建好对应映射关系的文件夹</strong><br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/1.4.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/1.4.jpg" alt="1.4" width="1526" height="862" class="alignnone size-full wp-image-1998" /></a><br />
我的本地映射文件目录~/docker-nmp/nginx<br />
<strong>1.3、打开你的终端：</strong><br />
执行：docker -v会显示你当前docker版本好，表示docker安装成功。<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/1.5.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/1.5.jpg" alt="1.5" width="686" height="64" class="alignnone size-full wp-image-2000" /></a><br />
<strong>2、安装Nginx：</strong><br />
使用docker pull命令，在线拉取nginx镜像，如果没有特殊版本需求，可直接输入nginx:latest</p>
<pre class="wp-code-highlight prettyprint">
执行命令：docker pull nginx:latest
</pre>
<p>执行完成之后，你可以在docker desktop上，可以点击images选项进行查看，镜像是否拉取成功。<br />
如图所示：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/2.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/2.jpg" alt="2" width="2538" height="1428" class="alignnone size-full wp-image-2001" /></a><br />
或者你可以在终端输入：docker images 查看，如图：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/2.1.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/2.1.jpg" alt="2.1" width="940" height="658" class="alignnone size-full wp-image-2002" /></a><br />
<strong>3、安装PHP：</strong><br />
我安装的是PHP7.4版本，大家可以根据自己情况去安装不同版本,如果没有版本需求，也可以输入php:latest</p>
<pre class="wp-code-highlight prettyprint">
执行命令：docker pull php:7.4-fpm
</pre>
<p><strong>4、启动PHP容器：</strong></p>
<pre class="wp-code-highlight prettyprint">
执行：docker run --name myphp-fpm -v ~/docker-nmp/nginx/www:/www -d 38f2b691dcb8
</pre>
<pre class="wp-code-highlight prettyprint">
下面我来解释一下：
--name  myphp-fpm : 将容器命名为 myphp-fpm。
-v ~/docker-nmp/nginx/www:/www：是我在本地创建的一个文件目录，用来将主机中项目的目录 www 挂载到容器的 /www
38f2b691dcb8：是php的镜像ID。
</pre>
<p><a href="http://www.yunda51.com/wp-content/uploads/2024/01/3.1.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/3.1.jpg" alt="3.1" width="1130" height="598" class="alignnone size-full wp-image-2004" /></a><br />
容器启动正常，可以使用命令行来查看：</p>
<pre class="wp-code-highlight prettyprint">
执行：docker ps
</pre>
<p><a href="http://www.yunda51.com/wp-content/uploads/2024/01/3.2.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/3.2.jpg" alt="3.2" width="1798" height="124" class="alignnone size-full wp-image-2007" /></a><br />
创建:  ~/docker-nmp/nginx/conf/conf.d 目录：</p>
<pre class="wp-code-highlight prettyprint">
mkdir ~/docker-nmp/nginx/conf/conf.d
</pre>
<p>在该目录下添加 ~/docker-nmp/nginx/conf/conf.d/coonote-test-php.conf 文件，内容如下：</p>
<pre class="wp-code-highlight prettyprint">
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }
}
</pre>
<p>配置文件说明：<br />
php:9000: 表示 php-fpm 服务的 URL，下面我们会具体说明。<br />
/www/: 是 myphp-fpm 中 php 文件的存储路径，映射到本地的 ~/docker-nmp/nginx/www 目录。<br />
<strong>5、启动Nginx容器并关联PHP，这一步很重要</strong></p>
<pre class="wp-code-highlight prettyprint">
docker run --name coonote-php-nginx -p 8083:80 -d \
-v ~/docker-nmp/nginx/www:/usr/share/nginx/html:ro \
-v ~/docker-nmp/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
--link myphp-fpm:php \
nginx
</pre>
<p>命令说明：<br />
-p 8083:80: 端口映射，把 nginx 中的 80 映射到本地的 8083 端口。<br />
~/docker-nmp/nginx/www: 是本地 html 文件的存储目录，/usr/share/nginx/html 是容器内 html 文件的存储目录。<br />
~/docker-nmp/nginx/conf/conf.d: 是本地 nginx 配置文件的存储目录，/etc/nginx/conf.d 是容器内 nginx 配置文件的存储目录。<br />
--link myphp-fpm:php: 把 myphp-fpm 的网络并入 nginx，并通过修改 nginx 的 /etc/hosts，把域名 php 映射成 127.0.0.1，让 nginx 通过 php:9000 访问 php-fpm。<br />
接下来我们在 ~/docker-nmp/nginx/www 目录下创建 index.php，代码如下：</p>
<pre class="wp-code-highlight prettyprint">
&lt;?php
    echo phpinfo();
?&gt;
</pre>
<p>打开浏览器输入：http://localhost:8083/index.php显示如下：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2024/01/4.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2024/01/4.jpg" alt="4" width="2320" height="1424" class="alignnone size-full wp-image-2008" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1989</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP操作redis(list)队列操作</title>
		<link>https://www.yunda51.com/?p=1976</link>
		<comments>https://www.yunda51.com/?p=1976#comments</comments>
		<pubDate>Sun, 24 Dec 2023 13:13:32 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[抢购]]></category>
		<category><![CDATA[队列]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1976</guid>
		<description><![CDATA[好久没有更新文章了。 list使用场景如下： 消息队列 list类型的lpop和rpush（或者反过来，lpu<a href="https://www.yunda51.com/?p=1976" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>好久没有更新文章了。</strong><br />
list使用场景如下：<br />
<strong>消息队列</strong><br />
list类型的lpop和rpush（或者反过来，lpush和rpop）能实现队列的功能，故而可以用Redis的list类型实现简单的点对点的消息队列。<br />
<strong>最新列表</strong><br />
list类型的lpush命令和lrange命令能实现最新列表的功能，每次通过lpush命令往列表里插入新的元素，<br />
然后通过lrange命令读取最新的元素列表，比如评论列表、朋友圈的点赞列表。</p>
<p><strong>######消息队列demo,简单模拟抢购商品#####</strong></p>
<pre class="wp-code-highlight prettyprint">
$redis = new redis();
$redis-&gt;connect(&#039;127.0.0.1&#039;, 6379);
$redis-&gt;auth(&#039;123456&#039;);
$redis-&gt;flushAll(); //清空所有数据
/***入列***/
//用户点击抢购的时候，把商品信息存入消息队列
$key = &#039;product1&#039;;#商品1
for ($i = 0; $i &lt; 100; $i++) {
    $uid = rand(1000, 9999);
    $number = 10; //次数，假设这件商品只能10个人抢购
    if ($number &gt; $redis-&gt;lLen($key)) {
        $redis-&gt;rpush($key, $uid); //不够10个就入列
    } else {
        continue;
    }
}
/***出列***/
while (true){
    $flag = $redis-&gt;exists($key);
    if($flag){
        $uid = $redis-&gt;rpop($key);
        echo $uid .&quot;抢购成功！，进行订单处理操作&lt;br/&gt;&quot;;
    } else {
        echo &quot;出列完毕！&quot;;
        exit;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1976</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git基本常用命令</title>
		<link>https://www.yunda51.com/?p=1862</link>
		<comments>https://www.yunda51.com/?p=1862#comments</comments>
		<pubDate>Mon, 18 Dec 2017 07:13:52 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1862</guid>
		<description><![CDATA[1、创建分支,并跳转到该分支。 git checkout -b xxxx 2、跳转到已有分支 git chec<a href="https://www.yunda51.com/?p=1862" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<pre class="wp-code-highlight prettyprint">
1、创建分支,并跳转到该分支。
	git checkout -b xxxx

2、跳转到已有分支
	git checkout xxxx

3、提交文件的必要步骤：
	说明：现在你要提交你本地的dev分支到远端dev分支上。
	git pull origin dev   (##拉取远端的dev分支文件。此步骤为必备步骤)
	git add xxx   (##将文件添加到提交的目录里面)
	git commit -m &quot;标注你此次提价的文件说明&quot;  (##提交文件)
	git push origin/dev dev
	
4、合并分支：
	说明：现在你需要把“dali”分支合并到“dev”分支上
	git checkout dev     (##首先切换到dev分支上)
	git merge dali      (##将dali分支合并到当前分支的命令)

5、查看历史提交版本：
	git reflog  (##查看当前分支的提交历史)
	git log --graph     (##查看具体的分支及提交信息)
	git log --graph --pretty=oneline --abbrev-commit    (##具体查看的简化版，强烈推荐使用。不谢)
以下是推荐使用命令的使用效果：
* f320f1a hehe
*   a7cd34b hehe
|\
| * d20802a test
| * cd18f41 youyou
* | 8b7c51d eeh
|/
* a3dbb86 测试代码

6、版本回撤：
	git reset --hard xxxxxx    (##为历史提交版本的前7位字符串)

7、当你只想更新远端分支的某一个文件时：
	git fetch
	git checkout origin/dev -- xxxx(文件名)
	
8、撤下某个提交的文件
	git reset -head xxxxx 

</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1862.html">http://www.yunda51.com/1862.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1862</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MQTT协议－MQTT协议简介及协议原理</title>
		<link>https://www.yunda51.com/?p=1834</link>
		<comments>https://www.yunda51.com/?p=1834#comments</comments>
		<pubDate>Wed, 27 Sep 2017 03:53:47 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mqtt]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1834</guid>
		<description><![CDATA[MQTT（Message Queuing Telemetry Transport，消息队列遥测传输协议），是一<a href="https://www.yunda51.com/?p=1834" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>MQTT</strong>（Message Queuing Telemetry Transport，消息队列遥测传输协议），是一种基于发布/订阅（publish/subscribe）模式的“轻量级”通讯协议，该协议构建于TCP/IP协议上，由IBM在1999年发布。MQTT最大优点在于，可以以极少的代码和有限的带宽，为连接远程设备提供实时可靠的消息服务。做为一种低开销、低带宽占用的即时通讯协议，使其在物联网、小型设备、移动应用等方面有较广泛的应用。</p>
<p><strong>MQTT协议特点</strong><br />
<strong> MQTT协议原理</strong></p>
<p>——2.1 MQTT协议实现方式<br />
——2.2 网络传输与应用消息<br />
——2.3 MQTT客户端<br />
——2.4 MQTT服务器<br />
——2.5 MQTT协议中的订阅、主题、会话<br />
——2.6 MQTT协议中的方法</p>
<p><strong>1. MQTT协议特点</strong></p>
<p>MQTT是一个基于客户端-服务器的消息发布/订阅传输协议。MQTT协议是轻量、简单、开放和易于实现的，这些特点使它适用范围非常广泛。在很多情况下，包括受限的环境中，如：机器与机器（M2M）通信和物联网（IoT）。其在，通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用。</p>
<p>MQTT协议当前版本为，2014年发布的MQTT v3.1.1。除标准版外，还有一个简化版MQTT-SN，该协议主要针对嵌入式设备，这些设备一般工作于百TCP/IP网络，如：ZigBee。</p>
<p>MQTT协议运行在TCP/IP或其他网络协议，提供有序、无损、双向连接。其特点包括：</p>
<p>使用的发布/订阅消息模式，它提供了一对多消息分发，以实现与应用程序的解耦。<br />
对负载内容屏蔽的消息传输机制。<br />
对传输消息有三种服务质量（QoS）：<br />
最多一次，这一级别会发生消息丢失或重复，消息发布依赖于底层TCP/IP网络。即：&lt;=1 至多一次，这一级别会确保消息到达，但消息可能会重复。即：&gt;=1<br />
只有一次，确保消息只有一次到达。即：＝1。在一些要求比较严格的计费系统中，可以使用此级别<br />
数据传输和协议交换的最小化（协议头部只有2字节），以减少网络流量<br />
通知机制，异常中断时通知传输双方</p>
<p><strong>2. MQTT协议原理</strong><br />
<strong>2.1 MQTT协议实现方式</strong><br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/09/14523188625918865.png"><img class="alignnone size-full wp-image-1835" src="http://www.yunda51.com/wp-content/uploads/2017/09/14523188625918865.png" alt="14523188625918865" width="826" height="146" /></a></p>
<p>实现MQTT协议需要：客户端和服务器端<br />
MQTT协议中有三种身份：发布者（Publish）、代理（Broker）（服务器）、订阅者（Subscribe）。其中，消息的发布者和订阅者都是客户端，消息代理是服务器，消息发布者可以同时是订阅者。<br />
MQTT传输的消息分为：主题（Topic）和负载（payload）两部分<br />
Topic，可以理解为消息的类型，订阅者订阅（Subscribe）后，就会收到该主题的消息内容（payload）<br />
payload，可以理解为消息的内容，是指订阅者具体要使用的内容</p>
<p><strong>2.2 网络传输与应用消息</strong></p>
<p>MQTT会构建底层网络传输：它将建立客户端到服务器的连接，提供两者之间的一个有序的、无损的、基于字节流的双向传输。</p>
<p>当应用数据通过MQTT网络发送时，MQTT会把与之相关的服务质量（QoS）和主题名（Topic）相关连。</p>
<p><strong>2.3 MQTT客户端</strong><br />
一个使用MQTT协议的应用程序或者设备，它总是建立到服务器的网络连接。客户端可以：</p>
<p>发布其他客户端可能会订阅的信息<br />
订阅其它客户端发布的消息<br />
退订或删除应用程序的消息<br />
断开与服务器连接</p>
<p><strong>2.4 MQTT服务器</strong></p>
<p>MQTT服务器以称为“消息代理”（Broker），可以是一个应用程序或一台设备。它是位于消息发布者和订阅者之间，它可以：</p>
<p>接受来自客户的网络连接<br />
接受客户发布的应用信息<br />
处理来自客户端的订阅和退订请求<br />
向订阅的客户转发应用程序消息</p>
<p><strong>2.5 MQTT协议中的订阅、主题、会话</strong></p>
<p>订阅（Subscription）</p>
<p>订阅包含主题筛选器（Topic Filter）和最大服务质量（QoS）。订阅会与一个会话（Session）关联。一个会话可以包含多个订阅。每一个会话中的每个订阅都有一个不同的主题筛选器。</p>
<p>会话（Session）</p>
<p>每个客户端与服务器建立连接后就是一个会话，客户端和服务器之间有状态交互。会话存在于一个网络之间，也可能在客户端和服务器之间跨越多个连续的网络连接。</p>
<p>主题名（Topic Name）</p>
<p>连接到一个应用程序消息的标签，该标签与服务器的订阅相匹配。服务器会将消息发送给订阅所匹配标签的每个客户端。</p>
<p>主题筛选器（Topic Filter）</p>
<p>一个对主题名通配符筛选器，在订阅表达式中使用，表示订阅所匹配到的多个主题。</p>
<p>负载（Payload）</p>
<p>消息订阅者所具体接收的内容</p>
<p><strong>2.6 MQTT协议中的方法</strong></p>
<p>MQTT协议中定义了一些方法（也被称为动作）， 来于表示对确定资源所进行操作。 这个资源可以代表预先存在的数据或动态生成数据，这取决于服务器的实现。通常来说，资源指服务器上的文件或输出。</p>
<p>Connect，等待与服务器建立连接</p>
<p>Disconnect，等待MQTT客户端完成所做的工作，并与服务器断开TCP/IP会话</p>
<p>Subscribe，等待完成订阅</p>
<p>UnSubscribe，等待服务器取消客户端的一个或多个topics订阅</p>
<p>Publish，MQTT客户端发送消息请求，发送完成后返回应用程序线程</p>
<p>本文转自：<a href="http://www.yunda51.com/1821.html">http://itbilu.com/other/relate/4kHBsx_Pg.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1834</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mongodb安装及常用命令</title>
		<link>https://www.yunda51.com/?p=1821</link>
		<comments>https://www.yunda51.com/?p=1821#comments</comments>
		<pubDate>Tue, 26 Sep 2017 06:14:39 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mongodb]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1821</guid>
		<description><![CDATA[mongodb的安装： 1、安装包存放目录： /app/tool/ 2、软件安装目录：/app/soft/ 1<a href="https://www.yunda51.com/?p=1821" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>mongodb的安装：</strong><br />
1、安装包存放目录： /app/tool/<br />
2、软件安装目录：/app/soft/</p>
<pre class="wp-code-highlight prettyprint">
1: 下载mongodb www.mongodb.org  下载最新的stable版
2: 解压文件:tar zxvf mongodb-linux-x86_64-rhel70-3.4.9.tgz
3: 不用编译,本身就是编译后的二进制可执行文件.
4: 启动mongod服务
./bin/mongod --dbpath /mongodata/mdata/ --logpath /mongodata/mlog --fork --port 27017
参数解释:
--dbpath 数据存储目录
--logpath 日志存储目录
--port 运行端口(默认27017)
--fork 后台进程运行

5：开启你的mongodb：
/app/soft/mongodb3.4.9/bin/mongo 
或者进入到mongodb3.4.9 执行：./bin/mongo 也是可以的
</pre>
<p><strong>1: mongo入门命令</strong></p>
<pre class="wp-code-highlight prettyprint">
1.1: show dbs  查看当前的数据库
1.2 use databaseName 选库
1.2 show tables/collections 查看当前库下的collection

1.3 如何创建库?
Mongodb的库是隐式创建,你可以use 一个不存在的库
然后在该库下创建collection,即可创建库

1.4 db.createCollection(‘collectionName’)  
创建collection

1.5 collection允许隐式创建
Db.collectionName.insert(document);

1.6 db.collectionName.drop() ,
删除collection

1.7 db.dropDatabase();
删除database
</pre>
<p><strong>基本操作增删改查</strong><br />
增: insert</p>
<pre class="wp-code-highlight prettyprint">
介绍: mongodb存储的是文档,. 文档是json格式的对象.

语法: db.collectionName.isnert(document);

1: 增加单篇文档
Db.collectionName.insert({title:’nice day’});

2: 增加单个文档,并指定_id
Db.collectionName.insert({_id:8,age:78,name:’lisi’});

3.增加多个文档
db.collectionName.insert(
[
{time:&#039;friday&#039;,study:&#039;mongodb&#039;},
{_id:9,gender:&#039;male&#039;,name:&#039;QQ&#039;}
]
)
</pre>
<p>删:remove</p>
<pre class="wp-code-highlight prettyprint">
语法: db.collection.remove(查询表达式, 选项);
选项是指  {justOne:true/false},是否只删一行, 默认为false

注意
1: 查询表达式依然是个json对象
2: 查询表达式匹配的行,将被删掉.
3: 如果不写查询表达式,collections中的所有文档将被删掉.

例1: db.stu.remove({sn:’001’});
删除stu表中 sn属性值为’001’的文档 

例2: db.stu.remove({gender:’m’,true});
删除stu表中gender属性为m的文档,只删除1行.
</pre>
<p>改  update操作<br />
改谁? --- 查询表达式<br />
改成什么样? -- 新值 或 赋值表达式<br />
操作选项 ----- 可选参数</p>
<pre class="wp-code-highlight prettyprint">
语法: db.collection.update(查询表达式,新值,选项);
例:
db.news.update({name:&#039;QQ&#039;},{name:&#039;MSN&#039;});
是指选中news表中,name值为QQ的文档,并把其文档值改为{name:’MSN’},
结果: 文档中的其他列也不见了,改后只有_id和name列了.
即--新文档直接替换了旧文档,而不是修改

如果是想修改文档的某列,可以用$set关键字
db.collectionName.update(query,{$set:{name:’QQ’}})

修改时的赋值表达式
$set  修改某列的值
$unset 删除某个列
$rename 重命名某个列
$inc 增长某个列
$setOnInsert 当upsert为true时,并且发生了insert操作时,可以补充的字段.


Option的作用:
{upsert:true/false,multi:true/false}
Upsert---是指没有匹配的行,则直接插入该行.(和mysql中的replace一样)

例:db.stu.update({name:&#039;wuyong&#039;},{$set:{name:&#039;junshiwuyong&#039;}},{upsert:true});
如果有name=’wuyong’的文档,将被修改
如果没有,将添加此新文档



例:
db.news.update({_id:99},{x:123,y:234},{upsert:true});
没有_id=99的文档被修改,因此直接插入该文档

multi: 是指修改多行(即使查询表达式命中多行,默认也只改1行,如果想改多行,可以用此选项)
例:
db.news.update({age:21},{$set:{age:22}},{multi:true});
则把news中所有age=21的文档,都修改


查: find, findOne
语法: db.collection.find(查询表达式,查询的列);
Db.collections.find(表达式,{列1:1,列2:1});


例1:db.stu.find()
查询所有文档 所有内容

例2: db.stu.find({},{gendre:1})
查询所有文档,的gender属性 (_id属性默认总是查出来)

例3: db.stu.find({},{gender:1, _id:0})
查询所有文档的gender属性,且不查询_id属性

例3: db.stu.find({gender:’male’},{name:1,_id:0});
查询所有gender属性值为male的文档中的name属性
</pre>
<p><strong>查询表达式:</strong></p>
<pre class="wp-code-highlight prettyprint">
1: 最简单的查询表达式
{filed:value} ,是指查询field列的值为value的文档

2: $ne --- != 查询表达式
{field:{$nq:value}}
作用--查filed列的值 不等于 value 的文档

3: $nin --&gt; not in

4: $all
语法: {field:{$all:[v1,v2..]}} 
是指取出 field列是一个数组,且至少包含 v1,v2值

5: $exists 
语法: {field:{$exists:1}}
作用: 查询出含有field字段的文档

6: $nor,
{$nor,[条件1,条件2]}
是指  所有条件都不满足的文档为真返回


7:用正则表达式查询 以”诺基亚”开头的商品
例:db.goods.find({goods_name:/诺基亚.*/},{goods_name:1});

8: 用$where表达式来查询
例: db.goods.find({$where:&#039;this.cat_id != 3 &amp;&amp; this.cat_id != 11&#039;});

注意: 用$where查询时, mongodb是把bson结构的二进制数据转换为json结构的对象,
然后比较对象的属性是否满足表达式.

</pre>
<p>Update时可用的操作符<br />
例:</p>
<pre class="wp-code-highlight prettyprint">
-&gt;db.user.insert({name:&#039;lisi&#039;,age:12,sex:&#039;male&#039;,height:123,area:&#039;haidian&#039;});
-&gt;db.user.update({name:&#039;lisi&#039;},{$set:{area:&#039;chaoyang&#039;},$unset:{height:1},$inc:{age:1},$rename:{sex:&#039;gender&#039;}});
&gt; db.user.find();
{ &quot;_id&quot; : ObjectId(&quot;51fc01c4f5de93e1f2856e33&quot;), &quot;age&quot; : 13, &quot;area&quot; : &quot;chaoyang&quot;, &quot;gender&quot; : &quot;male&quot;, &quot;name&quot; : &quot;lisi&quot; }

$setOnInsert -&gt;相当于mysql中的列的默认值
</pre>
<p><strong>游标操作cursor</strong></p>
<p>游标是什么\?<br />
通俗的说,游标不是查询结果,而是查询的返回资源,或者接口.<br />
通过这个接口,你可以逐条读取.<br />
就像php中的fopen打开文件,得到一个资源一样, 通过资源,可以一行一行的读文件.</p>
<p>声明游标:</p>
<pre class="wp-code-highlight prettyprint">
var cursor =  db.collectioName.find(query,projection);
Cursor.hasNext() ,判断游标是否已经取到尽头
Cursor. Next() , 取出游标的下1个单元

用while来循环游标
&gt; var mycursor = db.bar.find({_id:{$lte:5}})
&gt; while(mycursor.hasNext()) {
... printjson(mycursor.next());
... }
</pre>
<p>例:</p>
<pre class="wp-code-highlight prettyprint">
// 声明游标
var cursor = db.goods.find();
// 循环游标
for(var doc=true;cursor.hasNext();) { printjson(cursor.next());}

也可以简写:
for(var  cursor=db.goods.find(), doc=true;cursor.hasNext();) { printjson(cursor.next());}


游标还有一个迭代函数,允许我们自定义回调函数来逐个处理每个单元.
cursor.forEach(回调函数);
例:
&gt; var gettitle = function(obj) {print(obj.goods_name)}
&gt; var cursor = db.goods.find();
&gt; cursor.forEach(gettitle);


游标在分页中的应用
比如查到10000行,跳过100页,取10行.
一般地,我们假设每页N行, 当前是page页
就需要跳过前 (page-1)*N 行, 再取N行, 在mysql中, limit offset,N来实现
在mongo中,用skip(), limit()函数来实现的

如 var mycursor = db.bar.find().skip(9995);
则是查询结果中,跳过前9995行

查询第901页,每页10条
则是 var mytcursor = db.bar.find().skip(9000).limit(10);


通过cursor一次性得到所有数据, 并返回数组.
例:
&gt;var cursor = db.goods.find();
&gt; printjson(cursor.toArray());  //看到所有行
&gt; printjson(cursor.toArray()[2]);  //看到第2行

注意: 不要随意使用toArray()
原因: 会把所有的行立即以对象形式组织在内存里.
可以在取出少数几行时,用此功能.
</pre>
<p><strong>索引创建</strong></p>
<p>1:索引提高查询速度,降低写入速度,权衡常用的查询字段,不必在太多列上建索引<br />
2.在mongodb中,索引可以按字段升序/降序来创建,便于排序<br />
3.默认是用btree来组织索引文件,2.4版本以后,也允许建立hash索引.</p>
<p>查看查询计划</p>
<pre class="wp-code-highlight prettyprint">
db.find(query).explain();
&quot;cursor&quot; : &quot;BasicCursor&quot;, ----说明没有索引发挥作用
&quot;nscannedObjects&quot; : 1000 ---理论上要扫描多少行
cursor&quot; : &quot;BtreeCursor sn_1&quot;, 用到的btree索引
</pre>
<p>常用命令:</p>
<pre class="wp-code-highlight prettyprint">
查看当前索引状态: db.collection.getIndexes();

创建普通的单列索引:db.collection.ensureIndex({field:1/-1});  1是升续 2是降续

删除单个索引
db.collection.dropIndex({filed:1/-1});

一下删除所有索引
db.collection.dropIndexes();

创建多列索引  db.collection.ensureIndex({field1:1/-1, field2:1/-1});

创建子文档索引
db.collection.ensureIndex({filed.subfield:1/-1});


创建唯一索引:
db.collection.ensureIndex({filed.subfield:1/-1}, {unique:true});
</pre>
<p>创建稀疏索引:<br />
稀疏索引的特点------如果针对field做索引,针对不含field列的文档,将不建立索引.<br />
与之相对,普通索引,会把该文档的field列的值认为NULL,并建索引.<br />
适宜于: 小部分文档含有某列时.</p>
<pre class="wp-code-highlight prettyprint">
db.collection.ensureIndex({field:1/-1},{sparse:true});

&gt; db.tea.find();
{ &quot;_id&quot; : ObjectId(&quot;5275f99b87437c610023597b&quot;), &quot;email&quot; : &quot;a@163.com&quot; }
{ &quot;_id&quot; : ObjectId(&quot;5275f99e87437c610023597c&quot;), &quot;email&quot; : &quot;b@163.com&quot; }
{ &quot;_id&quot; : ObjectId(&quot;5275f9e887437c610023597e&quot;), &quot;email&quot; : &quot;c@163.com&quot; }
{ &quot;_id&quot; : ObjectId(&quot;5275fa3887437c6100235980&quot;) }
</pre>
<p>如上内容,最后一行没有email列,<br />
如果分别加普通索引,和稀疏索引,<br />
对于最后一行的email分别当成null 和 忽略最后一行来处理.<br />
根据{email:null}来查询,前者能查到,而稀疏索引查不到最后一行.</p>
<p>创建哈希索引(2.4新增的)<br />
哈希索引速度比普通索引快,但是,无能对范围查询进行优化.<br />
适宜于---随机性强的散列<br />
db.collection.ensureIndex({file:’hashed’});</p>
<p>重建索引<br />
一个表经过很多次修改后,导致表的文件产生空洞,索引文件也如此.<br />
可以通过索引的重建,减少索引文件碎片,并提高索引的效率.<br />
类似mysql中的optimize table</p>
<p>db.collection.reIndex()</p>
<p><strong>Mongodb导出与导入</strong></p>
<p>1: 导入/导出可以操作的是本地的mongodb服务器,也可以是远程的.<br />
所以,都有如下通用选项:</p>
<pre class="wp-code-highlight prettyprint">
-h host   主机
--port port    端口
-u username 用户名
-p passwd   密码

</pre>
<p>2: mongoexport 导出json格式的文件<br />
问: 导出哪个库,哪张表,哪几列,哪几行?</p>
<pre class="wp-code-highlight prettyprint">
-d  库名
-c  表名
-f  field1,field2...列名
-q  查询条件
-o  导出的文件名
-- csv  导出csv格式(便于和传统数据库交换数据)
</pre>
<p>例:</p>
<pre class="wp-code-highlight prettyprint">
[root@localhost mongodb]# ./bin/mongoexport -d test -c news -o test.json
connected to: 127.0.0.1
exported 3 records
[root@localhost mongodb]# ls
bin  dump  GNU-AGPL-3.0  README  test.json  THIRD-PARTY-NOTICES
[root@localhost mongodb]# more test.json 
{ &quot;_id&quot; : { &quot;$oid&quot; : &quot;51fc59c9fecc28d8316cfc03&quot; }, &quot;title&quot; : &quot;aaaa&quot; }
{ &quot;_id&quot; : { &quot;$oid&quot; : &quot;51fcaa3c5eed52c903a91837&quot; }, &quot;title&quot; : &quot;today is sataday&quot; }
{ &quot;_id&quot; : { &quot;$oid&quot; : &quot;51fcaa445eed52c903a91838&quot; }, &quot;title&quot; : &quot;ok now&quot; }
</pre>
<p>例2: 只导出goods_id,goods_name列</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongoexport -d test -c goods -f goods_id,goods_name -o goods.json
</pre>
<p>例3: 只导出价格低于1000元的行</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongoexport -d test -c goods -f goods_id,goods_name,shop_price -q ‘{shop_price:{$lt:200}}’ -o goods.json
</pre>
<p>注: _id列总是导出</p>
<p><strong>Mongoimport 导入</strong></p>
<pre class="wp-code-highlight prettyprint">
-d 待导入的数据库
-c 待导入的表(不存在会自己创建)
--type  csv/json(默认)
--file 备份文件路径
</pre>
<pre class="wp-code-highlight prettyprint">
例1: 导入json
./bin/mongoimport -d test -c goods --file ./goodsall.json

例2: 导入csv
./bin/mongoimport -d test -c goods --type csv -f goods_id,goods_name --file ./goodsall.csv 

./bin/mongoimport -d test -c goods --type csv --headline -f goods_id,goods_name --file ./goodsall.csv 

</pre>
<p>mongodump 导出二进制bson结构的数据及其索引信息</p>
<pre class="wp-code-highlight prettyprint">
-d  库名
-c  表名
-f  field1,field2...列名
</pre>
<p>例: </p>
<pre class="wp-code-highlight prettyprint">
mongodum -d test  [-c 表名]  默认是导出到mongo下的dump目录
</pre>
<p>规律:<br />
1:导出的文件放在以database命名的目录下<br />
2: 每个表导出2个文件,分别是bson结构的数据文件, json的索引信息<br />
3: 如果不声明表名, 导出所有的表</p>
<p>mongorestore 导入二进制文件<br />
例:</p>
<pre class="wp-code-highlight prettyprint">
 ./bin/mongorestore -d test --directoryperdb dump/test/ (mongodump时的备份目录)
</pre>
<p>二进制备份,不仅可以备份数据,还可以备份索引,<br />
备份数据比较小.</p>
<p>mongodb的用户管理</p>
<p>注意:<br />
A)在mongodb中,有一个admin数据库, 牵涉到服务器配置层面的操作,需要先切换到admin数据.<br />
即 use admin , -->相当于进入超级用户管理模式.</p>
<p>B)mongo的用户是以数据库为单位来建立的, 每个数据库有自己的管理员.</p>
<p>C) 我们在设置用户时,需要先在admin数据库下建立管理员---这个管理员登陆后,相当于超级管理员.</p>
<p>0: 查看用户</p>
<p>1: 添加用户<br />
命令:db.addUser();<br />
简单参数: db.addUser(用户名,密码,是否只读)</p>
<p>注意: 添加用户后,我们再次退出并登陆,发现依然可以直接读数据库?<br />
原因: mongodb服务器启动时, 默认不是需要认证的.<br />
要让用户生效, 需要启动服务器时,就指定 --auth 选项.<br />
这样, 操作时,就需要认证了.</p>
<p>例: </p>
<pre class="wp-code-highlight prettyprint">
1: 添加用户
&gt; use admin
&gt; db.addUser(‘sa’,’sa’,false);

2: 认证
&gt; use test
&gt; db.auth(用户名,密码);

3: 修改用户密码
&gt; use test
&gt; db.changeUserPassword(用户名, 新密码);

3:删除用户
&gt; use test
&gt; db.removeUser(用户名);
</pre>
<p>注: 如果需要给用户添加更多的权限,可以用json结构来传递用户参数<br />
例:</p>
<pre class="wp-code-highlight prettyprint">
&gt; use test
&gt;db.addUser({user:&#039;guan&#039;,pwd:&#039;111111&#039;,roles:[&#039;readWrite,dbAdmin&#039;]});

replication set复制集
replicattion set 多台服务器维护相同的数据副本,提高服务器的可用性.
</pre>
<p><strong>Replication set 设置全过程</strong><br />
0:创建目录
<pre class="wp-code-highlight prettyprint">

mkdir -p /data/r0 /data/r1 /data/r2
</pre>
<p>1:启动3个实例,且声明实例属于某复制集</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongod --port 27017 --dbpath /data/r0 --smallfiles --replSet rsa --fork --logpath /var/log/mongo17.log
./bin/mongod --port 27018 --dbpath /data/r1 --smallfiles --replSet rsa --fork --logpath /var/log/mongo18.log
./bin/mongod --port 27019 --dbpath /data/r2 --smallfiles --replSet rsa --fork --logpath /var/log/mongo19.log

</pre>
<p>2:配置</p>
<pre class="wp-code-highlight prettyprint">
rsconf = {
    _id:&#039;rsa&#039;,
    members:
    [
        {_id:0,
        host:&#039;192.168.1.201:27017&#039;
        }
    ]
}

</pre>
<p>3: 根据配置做初始化</p>
<pre class="wp-code-highlight prettyprint">
rs.initiate(rsconf);
</pre>
<p>4: 添加节点</p>
<pre class="wp-code-highlight prettyprint">
rs.add(&#039;192.168.1.201:27018&#039;);
rs.add(&#039;192.168.1.201:27019&#039;);
</pre>
<p>5:查看状态</p>
<pre class="wp-code-highlight prettyprint">
rs.status();
</pre>
<p>6:删除节点</p>
<pre class="wp-code-highlight prettyprint">
rs.remove(&#039;192.168.1.201:27019&#039;);
</pre>
<p>7:主节点插入数据</p>
<pre class="wp-code-highlight prettyprint">
&gt;use test
&gt;db.user.insert({uid:1,name:&#039;lily&#039;});
</pre>
<p>8:连接secondary查询同步情况</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongo --port 27019
&gt;use test
&gt;show tables

rsa:SECONDARY&gt; show tables;
Sat Aug 17 16:03:55.786 JavaScript execution failed: error: { &quot;$err&quot; : &quot;not master and slaveOk=false&quot;, &quot;code&quot; : 13435 } 
</pre>
<p>8.1 出现上述错误,是因为slave默认不许读写</p>
<pre class="wp-code-highlight prettyprint">
&gt;rs.slaveOk();
&gt;show tables
</pre>
<p>#看到与primary 一致的数据</p>
<p><strong>分片：</strong></p>
<p>1:在3台独立服务器上,分别运行 27017,27018,27019实例, 互为副本集,形成3套repl set<br />
2: 在3台服务器上,各配置config server, 运行27020端口上</p>
<p>3: 配置mongos</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongos --port 30000 \
 --dbconfig 192.168.1.201:27020,192.168.1.202:27020,192.168.1.203:27020
</pre>
<p>4:连接路由器</p>
<pre class="wp-code-highlight prettyprint">
./bin/mongo --port 30000
</pre>
<p>5: 添加repl set为片</p>
<pre class="wp-code-highlight prettyprint">
&gt;sh.addShard(‘192.168.1.201:27017’);
&gt;sh.addShard(‘192.168.1.203:27017’);
&gt;sh.addShard(‘192.168.1.203:27017’);
</pre>
<p>6: 添加待分片的库</p>
<pre class="wp-code-highlight prettyprint">
&gt;sh.enableSharding(databaseName);
</pre>
<p>7: 添加待分片的表</p>
<pre class="wp-code-highlight prettyprint">
&gt;sh.shardCollection(‘dbName.collectionName’,{field:1});
</pre>
<p>Field是collection的一个字段,系统将会利用filed的值,来计算应该分到哪一个片上.<br />
这个filed叫”片键”, shard key</p>
<p>mongodb不是从单篇文档的级别,绝对平均的散落在各个片上, </p>
<p>而是N篇文档,形成一个块"chunk",<br />
优先放在某个片上,<br />
当这片上的chunk,比另一个片的chunk,区别比较大时, (>=3) ,会把本片上的chunk,移到另一个片上, 以chunk为单位,<br />
维护片之间的数据均衡</p>
<p>问: 为什么插入了10万条数据,才2个chunk?<br />
答: 说明chunk比较大(默认是64M)<br />
在config数据库中,修改chunksize的值.</p>
<p>问: 既然优先往某个片上插入,当chunk失衡时,再移动chunk,<br />
自然,随着数据的增多,shard的实例之间,有chunk来回移动的现象,这将带来什么问题?<br />
答: 服务器之间IO的增加, </p>
<p>接上问: 能否我定义一个规则, 某N条数据形成1个块,预告分配M个chunk,<br />
M个chunk预告分配在不同片上.<br />
以后的数据直接入各自预分配好的chunk,不再来回移动?</p>
<p>答: 能, 手动预先分片!</p>
<p>以shop.user表为例</p>
<pre class="wp-code-highlight prettyprint">
1: sh.shardCollection(‘shop.user’,{userid:1}); //user表用userid做shard key
2: for(var i=1;i&lt;=40;i++) { sh.splitAt(&#039;shop.user&#039;,{userid:i*1000}) } // 预先在1K 2K...40K这样的界限切好chunk(虽然chunk是空的), 这些chunk将会均匀移动到各片上.
3: 通过mongos添加user数据. 数据会添加到预先分配好的chunk上, chunk就不会来回移动了.
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1821.html">http://www.yunda51.com/1821.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1821</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CentOs7编译安装LNMP环境(nginx+mysql+php)</title>
		<link>https://www.yunda51.com/?p=1806</link>
		<comments>https://www.yunda51.com/?p=1806#comments</comments>
		<pubDate>Tue, 12 Sep 2017 08:14:46 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1806</guid>
		<description><![CDATA[最近重新整理下LNMP环境搭建的步骤： 1.1路径说明： 1、安装包存放目录： /app/tool/ 2、软件<a href="https://www.yunda51.com/?p=1806" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>最近重新整理下LNMP环境搭建的步骤：<br />
1.1路径说明：<br />
1、安装包存放目录： /app/tool/<br />
2、软件安装目录：/app/soft/<br />
3、项目存放目录：/app/www/<br />
4、提示：管理用户是www<br />
5、启动路径：</p>
<pre class="wp-code-highlight prettyprint">1) mysql：/etc/init.d/mysqld {start|stop|restart}
2) php：/app/soft/php5.6.16/sbin/php-fpm
3) nginx：/app/soft/nginx/sbin/nginx -t &amp;amp;&amp;amp; /app/soft/nginx/sbin/nginx -s reload
</pre>
<p>设置开机自动启动：<br />
<strong>编辑：</strong></p>
<pre class="wp-code-highlight prettyprint">
vim /etc/rc.local
</pre>
<p><strong>添加：</strong></p>
<pre class="wp-code-highlight prettyprint">
#开机启动mysql服务
/etc/init.d/mysqld start
#开机启动php服务
/app/soft/php5.6.16/sbin/php-fpm
#开机启动Nginx服务
/app/soft/nginx/sbin/nginx
#关闭防火墙
systemctl stop firewalld.service
</pre>
<p><strong>mysql的安装（版本：mysql-5.5.25）：</strong><br />
1、上传cmake-2.8.8.tar.gz mysql-5.5.25.tar.gz<br />
2、安装编译MySQL过程中需要的依赖包：</p>
<pre class="wp-code-highlight prettyprint">yum install ncurses-devel libaio-devel -y
yum install gcc-c++ -y
</pre>
<p>3、安装编译安装需要的软件：</p>
<pre class="wp-code-highlight prettyprint">cd /app/tool/
tar zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure 
gmake
gmake install
</pre>
<p>4、开始安装MySQL，在主服务器上搭建MySQL：</p>
<pre class="wp-code-highlight prettyprint">useradd mysql -s /sbin/nologin -M
tar zxf mysql-5.5.25.tar.gz 
cd mysql-5.5.25
cmake . -DCMAKE_INSTALL_PREFIX=/app/soft/mysql-5.5.25 \
-DMYSQL_DATADIR=/app/soft/mysql-5.5.25/data \
-DMYSQL_UNIX_ADDR=/app/soft/mysql-5.5.25/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make   
make install
ln -s mysql-5.5.25/ /app/soft/mysql     //创建MySQL软连接
echo &#039;PATH=&quot;/app/soft/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin&quot;&#039;&amp;gt;&amp;gt;/etc/profile
. /etc/profile
</pre>
<p>5、配置MySQL初始数据，并启动:</p>
<pre class="wp-code-highlight prettyprint">chmod 755 /app/soft/mysql/scripts/mysql_install_db 
/app/soft/mysql/scripts/mysql_install_db --basedir=/app/soft/mysql/ --datadir=/app/soft/mysql/data/ --user=mysql
##如果在这个环节出现了/app/soft/mysql/scripts/mysql_install_db 不存在的报错时，重新进行编译安装。
cp /app/soft/mysql/support-files/my-small.cnf /etc/my.cnf
cp /app/soft/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld   //授予执行的权限
mysql_secure_installation #设置Mysql密码
/etc/init.d/mysqld start  //重新启动
</pre>
<p>至此，MySQL编译安装完成。</p>
<p><strong>Nginx安装（版本：nginx-1.9.9）：</strong><br />
nginx使用的是一键安装脚本：安装的是nginx-1.9.9版本（你可以创建一个.sh，把下面脚本代码拷贝进去直接执行）</p>
<pre class="wp-code-highlight prettyprint">#!/bin/sh
####################################################
#This is a shell scripts to one-key install for lnmp  
#######################start########################
cd /app/tool &amp;amp;&amp;amp;\
[ -f nginx-1.9.9.tar.gz ] || wget http://nginx.org/download/nginx-1.9.9.tar.gz
[ -f pcre-8.37.tar.gz ] || wget http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gz/download
#####################install libpcre################
tar zxf pcre-8.37.tar.gz
cd ./pcre-8.37 &amp;amp;&amp;amp;\
./configure
make &amp;amp;&amp;amp; make install
cd .. &amp;amp;&amp;amp;\
rm -rf ./pcre-8.37
######################install nginx#################
cd /app/tool &amp;amp;&amp;amp; tar zxf nginx-1.9.9.tar.gz
cd ./nginx-1.9.9
mkdir /app/soft/nginx-1.9.9
useradd nginx -s /sbin/nologin -M
yum install openssl* gd-devel -y
./configure --user=nginx --group=nginx --prefix=/app/soft/nginx-1.9.9 --with-http_image_filter_module --with-http_stub_status_module --with-http_ssl_module
make &amp;amp;&amp;amp; make install
#######################test install#################
ln -s /app/soft/nginx-1.9.9/ /app/soft/nginx
cd /app/soft
if [ $? -eq 0 ];then
  echo &quot;/usr/local/lib&quot; &amp;gt;&amp;gt; /etc/ld.so.conf
  ldconfig
  /app/soft/nginx-1.9.9/sbin/nginx
  if [ $? -eq 0 ];then
     echo &quot;service nginx start&quot;
     echo  `lsof -i :80`
  fi
fi
</pre>
<p><strong>PHP安装步骤：</strong><br />
php使用的是编译安装，安装的是php-5.6.16版本<br />
###安装依赖环境包</p>
<pre class="wp-code-highlight prettyprint">yum -y install curl-devel
yum -y install libxslt-deve
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libevent libevent-devel
yum install zlib libxml libjpeg freetype libpng gd curl libiconv mysql-devel zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel libxslt* -y
yum -y install libxslt-deve
cd /app/tool/
</pre>
<p>下载libmcrypt（PHPlibmcrypt模块）<br />
安装libmcrypt</p>
<pre class="wp-code-highlight prettyprint">cd /usr/local/src
tar zxvf libmcrypt-2.5.7.tar.gz   #解压
cd libmcrypt-2.5.7      #进入目录
./configure      #配置
make    #编译
make install #安装
</pre>
<p>下载mhash并安装：</p>
<pre class="wp-code-highlight prettyprint">wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make &amp;amp;&amp;amp; make install
</pre>
<p>下载mcrypt并安装：</p>
<pre class="wp-code-highlight prettyprint">wget http://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make &amp;amp;&amp;amp; make install
</pre>
<p>下载libiconv并安装：</p>
<pre class="wp-code-highlight prettyprint">wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.13.tar.gz
tar zxf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure --prefix=/usr/local/libiconv
make &amp;amp;&amp;amp; make install

echo &quot;/usr/local/lib&quot; &amp;gt;&amp;gt;/etc/ld.so.conf
rm -f /usr/lib/libmcrypt.*
rm -f /usr/lib/libmhash*
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
</pre>
<p><strong>###安装PHP：</strong></p>
<pre class="wp-code-highlight prettyprint">cd /app/tool/
wget http://cn2.php.net/distributions/php-5.6.16.tar.gz
tar zxf php-5.6.16.tar.gz
cd php-5.6.16
./configure --prefix=/app/soft/php5.6.16 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no
make
make install
cp php.ini-development /app/soft/php5.6.16/lib/php.ini
cp /app/soft/php5.6.16/etc/php-fpm.conf.default /app/soft/php5.6.16/etc/php-fpm.conf
cp -R ./sapi/fpm/php-fpm /app/soft/php5.6.16/sbin/php-fpm
/app/soft/php5.6.16/sbin/php-fpm
lsof-i :9000
</pre>
<pre class="wp-code-highlight prettyprint">yum install -y vim lrzsz netstat
最后关闭SELinux（SELinux是一种安全子系统它能控制程序只能访问特定文件）
vim /etc/selinux/config
修改为：SELINUX=disabled
</pre>
<p>至此LNMP环境已经完美搭建，现在可以开启你的LNMP之旅了~<br />
转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1802.html">http://www.yunda51.com/1802.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1806</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL编译安装及主从同步</title>
		<link>https://www.yunda51.com/?p=1802</link>
		<comments>https://www.yunda51.com/?p=1802#comments</comments>
		<pubDate>Tue, 12 Sep 2017 07:04:00 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[centos]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1802</guid>
		<description><![CDATA[1、上传cmake-2.8.8.tar.gz mysql-5.5.25.tar.gz 2、安装编译MySQL过<a href="https://www.yunda51.com/?p=1802" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>1、上传cmake-2.8.8.tar.gz mysql-5.5.25.tar.gz</p>
<p>2、安装编译MySQL过程中需要的依赖包：</p>
<pre class="wp-code-highlight prettyprint">
yum install ncurses-devel libaio-devel -y
yum install gcc-c++ -y
</pre>
<p>3、安装编译安装需要的软件：</p>
<pre class="wp-code-highlight prettyprint">
cd /app/tool/
tar zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure 
gmake
gmake install
</pre>
<p>4、开始安装MySQL，在主服务器上搭建MySQL：</p>
<pre class="wp-code-highlight prettyprint">
useradd mysql -s /sbin/nologin -M
tar zxf mysql-5.5.25.tar.gz 
cd mysql-5.5.25
cmake . -DCMAKE_INSTALL_PREFIX=/app/soft/mysql-5.5.25 \
-DMYSQL_DATADIR=/app/soft/mysql-5.5.25/data \
-DMYSQL_UNIX_ADDR=/app/soft/mysql-5.5.25/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0

make   
make install
ln -s mysql-5.5.25/ /app/soft/mysql     //创建MySQL软连接
echo &#039;PATH=&quot;/app/soft/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin&quot;&#039;&gt;&gt;/etc/profile
. /etc/profile
</pre>
<p>5、配置MySQL初始数据，并启动:</p>
<pre class="wp-code-highlight prettyprint">
chmod 755 /app/soft/mysql/scripts/mysql_install_db 

/app/soft/mysql/scripts/mysql_install_db --basedir=/app/soft/mysql/ --datadir=/app/soft/mysql/data/ --user=mysql
##如果在这个环节出现了/app/soft/mysql/scripts/mysql_install_db 不存在的报错时，重新进行编译安装。

cp /app/soft/mysql/support-files/my-small.cnf /etc/my.cnf

cp /app/soft/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld   //授予执行的权限

mysql_secure_installation #设置Mysql密码

/etc/init.d/mysqld start  //重新启动
</pre>
<p>至此，MySQL编译安装完成。</p>
<p><strong>搭建从库：</strong></p>
<p>按照主库的流程安装从库。<br />
配置主从关系<br />
设置好my.cnf的配置文件<br />
主数据库的配置文件：</p>
<pre class="wp-code-highlight prettyprint">
[root@db01 ~]# cat /etc/my.cnf

[client]
port		= 3306
socket		= /app/soft/mysql-5.5.25/tmp/mysql.sock


[mysqld]
port		= 3306
socket		= /app/soft/mysql-5.5.25/tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
log-slow-queries=/data/mysqldata/slowquery.log

long_query_time=1
thread_concurrency = 8


log-bin=mysql-bin
server-id	= 1
expire-logs-days = 7
relay-log-space-limit           = 16G
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396,2003 


[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
</pre>
<p>从数据库的配置文件:</p>
<pre class="wp-code-highlight prettyprint">
[root@db02 ~]# cat /etc/my.cnf
[client]
port		= 3306
socket		= /app/soft/mysql-5.5.25/tmp/mysql.sock


[mysqld]
port		= 3306
socket		= /app/soft/mysql-5.5.25/tmp/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
log-slow-queries=/data/mysqldata/slowquery.log

long_query_time=1
thread_concurrency = 8

#log-bin=mysql-bin
server-id	= 2
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
</pre>
<p>进入到主数据库:</p>
<pre class="wp-code-highlight prettyprint">
mysql
useradd liuyd  //创建liuyd用户
id liuyd      //查看liuyd
su - liuyd    //切换用户
passwd        //设置密码
grant replication slave on *.* to liuyd@&#039;192.168.199.%&#039; identified by &#039;123456&#039;;
flush privileges;
</pre>
<p>锁表导出数据：</p>
<pre class="wp-code-highlight prettyprint">
flush table with read lock;
\q
mysqldump -uroot -A -B --events |gzip &gt;/server/backup/repl_bak_$(date +%F).sql.gz
</pre>
<p>将导出的数据传到从库上面去并解压导入到数据库中：</p>
<pre class="wp-code-highlight prettyprint">
scp -a /server/backup/repl_bak_$(date +%F).sql.gz root@192.168.199.160:/server/backup/
mysql &lt; /server/backup/repl_bak_$(date +%F).sql.gz
</pre>
<p>进入到从库：</p>
<pre class="wp-code-highlight prettyprint">
mysql
stop slave;
CHANGE MASTER TO  
MASTER_HOST=&#039;192.168.199.159&#039;, 
MASTER_PORT=3306,
MASTER_USER=&#039;rep&#039;, 
MASTER_PASSWORD=&#039;oldboy123456&#039;, 
MASTER_LOG_FILE=&#039;mysql-bin.000010&#039;,
MASTER_LOG_POS=245;
start slave;
show slave status\G;
#             Slave_IO_Running: Yes
#             Slave_SQL_Running: Yes
#             Seconds_Behind_Master: 0
</pre>
<p>##出现以上数据，同步成功。</p>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1802.html">http://www.yunda51.com/1802.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1802</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FastDFS安装部署</title>
		<link>https://www.yunda51.com/?p=1786</link>
		<comments>https://www.yunda51.com/?p=1786#comments</comments>
		<pubDate>Wed, 09 Aug 2017 10:05:44 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[FastDFS]]></category>
		<category><![CDATA[分布式存储]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1786</guid>
		<description><![CDATA[FastDFS原理：FastDFS是一个开源的轻量级分布式文件系统，它对文件进行管理，功能包括：文件存储、文件<a href="https://www.yunda51.com/?p=1786" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>FastDFS原理：</strong>FastDFS是一个开源的轻量级分布式文件系统，它对文件进行管理，功能包括：文件存储、文件同步、文件访问（文件上传、文件下载）等，解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务，如相册网站、视频网站等等。<br />
FastDFS为互联网量身定制，充分考虑了冗余备份、负载均衡、线性扩容等机制，并注重高可用、高性能等指标，使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。<br />
FastDFS服务端有两个角色：跟踪器（tracker）和存储节点（storage）。跟踪器主要做调度工作，在访问上起负载均衡的作用。<br />
需要说明的是，client为使用FastDFS服务的调用方，client也应该是一台服务器，它对tracker和storage的调用均为服务器间的调用。<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175430.png"><img class="alignnone size-full wp-image-1787" src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175430.png" alt="20170809175430" width="691" height="573" /></a><br />
1.1安装依赖应用：</p>
<pre class="wp-code-highlight prettyprint">yum install vim wget zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel 
libevent libevent-devel perl net-tools unzip -y
</pre>
<p>1.2上传libfastcommon-master.zip至/usr/local/路径下面<br />
解压：(##如果没有安装解压工具，可以直接yum install unzip zip –y)<br />
unzip libfastcommon-master.zip<br />
进入到目录查看压缩包的内容：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175446.png"><img class="alignnone size-full wp-image-1788" src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175446.png" alt="20170809175446" width="693" height="56" /></a></p>
<p>1.3安装libfastcommon-master<br />
解压完成后进行编译安装。由于文件没有make.sh脚本，所以编译安装执行命令：##在当前路径下直接执行如下命令：</p>
<pre class="wp-code-highlight prettyprint">./make.sh
./make.sh install
</pre>
<p>当./make.sh install编译后看见如下信息，表示变异完成。<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175500.png"><img class="alignnone size-full wp-image-1789" src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175500.png" alt="20170809175500" width="693" height="233" /></a><br />
至此，libfastcommon就已经安装成功了，这里需要留一下红色方框中标志的两个路径，其中libfastcommon.so是默认安装到/usr/lib64/libfastcommon.so，但是FastDFS主程序设置的lib目录是/usr/local/lib，所以此处需要重新设置软连接。</p>
<pre class="wp-code-highlight prettyprint">ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
</pre>
<p>设置完后开始安装fastdfs。</p>
<p>1.4安装fastdfs<br />
1.4.1解压安装包</p>
<pre class="wp-code-highlight prettyprint">
tar -zxvf fastdfs-5.05.tar.gz
</pre>
<p>1.4.2进入到目录下进行编译</p>
<pre class="wp-code-highlight prettyprint">cd fastdfs-5.05
./make.sh
./make.sh install
</pre>
<p><a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175510.png"><img class="alignnone size-full wp-image-1790" src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175510.png" alt="20170809175510" width="693" height="165" /></a><br />
编译后 可以看见系统创建了标记的路径，进入查看，编译后的文件安装在了该路径下面。<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175519.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175519.png" alt="20170809175519" width="693" height="44" class="alignnone size-full wp-image-1791" /></a><br />
将/etc/fdfs/路径下生成的三个文件拷贝生成正式的配置文件。</p>
<pre class="wp-code-highlight prettyprint">
cd /etc/fdfs/
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
</pre>
<p>再次查看：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175537.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175537.png" alt="20170809175537" width="693" height="135" class="alignnone size-full wp-image-1792" /></a></p>
<p>1.5配置，启动Tracker<br />
Tracker在配置他之前，首先需要创建Tracker服务器的文件路径，即用于存储Tracker的数据文件和日志文件等。在此，我将在/opt/目录下面创建一个    fastdfs_tracker目录，用于存放Tracker服务器的相关文件：<br />
mkdir /opt/fastdfs_tracker<br />
1.5.1更改配置文件<br />
重新编辑上一步准备好的/etc/fdfs目录下的tracker.conf配置文件，打开文件后依次做以下修改：</p>
<pre class="wp-code-highlight prettyprint">
[root@localhost fdfs]# vim tracker.conf
1、disabled=false #启用配置文件（默认启用）
2、port=22122 #设置tracker的端口号，通常采用22122这个默认端口
3、base_path=/opt/fastdfs_tracker #设置tracker的数据文件和日志目录
4、http.server_port=6666 #设置http端口号，默认为8080
</pre>
<p>1.5.2配置启动路径：</p>
<pre class="wp-code-highlight prettyprint">
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
</pre>
<p>最后通过命令启动Tracker服务器：</p>
<pre class="wp-code-highlight prettyprint">
service fdfs_trackerd start
</pre>
<p>命令执行后可以看到以下提示：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175547.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175547.png" alt="20170809175547" width="693" height="65" class="alignnone size-full wp-image-1793" /></a><br />
查看端口是否被监听：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175558.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175558.png" alt="20170809175558" width="693" height="53" class="alignnone size-full wp-image-1794" /></a></p>
<p>将启动命令加入到开机自启动。<br />
echo “service fdfs_trackerd start”  >>/etc/rc.d/rc.local</p>
<p>1.6配置，启动Storage<br />
与Tracker做相似的修改<br />
1.6.1创建存储目录<br />
同理，步骤基本与配置Tracker一致，首先是创建Storage服务器的文件目录，需要注意的是同Tracker相比我多建了一个目录，因为Storage还需要一个文件存储路径，用于存放接收的文件：：</p>
<pre class="wp-code-highlight prettyprint">
mkdir /opt/ fastdfs_storage
mkdir /opt/fastdfs_storage_data
</pre>
<p>1.6.2修改编辑配置文件<br />
接下来修改/etc/fdfs目录下的storage.conf配置文件，打开文件后依次做以下修改：</p>
<pre class="wp-code-highlight prettyprint">
[root@localhost fdfs]# vim storage.conf
disabled=false #启用配置文件（默认启用）
group_name=group1 #组名，根据实际情况修改
port=23000 #设置storage的端口号，默认是23000，同一个组的storage端口号必须一致
base_path=/opt/fastdfs_storage #设置storage数据文件和日志目录
store_path_count=1 #存储路径个数，需要和store_path个数匹配
store_path0=/opt/fastdfs_storage_data #实际文件存储路径
tracker_server=192.168.199.33:22122   #tracker 服务器的 IP地址和端口号，如果是单机搭建，IP不要写127.0.0.1，否则启动不成功（此处的ip是为CentOS虚拟机ip），此处只装有一个server端  如果有两个，可在下面一行安装该模式，修改ip做添加。
http.server_port=8888 #设置 http 端口号
</pre>
<p>1.6.3配置启动路径<br />
配置完成后同样要为Storage服务器的启动脚本设置软引用：</p>
<pre class="wp-code-highlight prettyprint">
ln -s /usr/bin/fdfs_storaged /usr/local/bin
</pre>
<p>接下来启动Storage服务：（##并加入到开机自启动项）</p>
<pre class="wp-code-highlight prettyprint">
service fdfs_storaged start
</pre>
<p><a href="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175614.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/08/20170809175614.png" alt="20170809175614" width="693" height="57" class="alignnone size-full wp-image-1795" /></a><br />
见到如图所示的结果表示启动成功。</p>
<p>1.7修改启动脚本：</p>
<pre class="wp-code-highlight prettyprint">
cd /etc/fdfs/
ls -l /etc/init.d/fdfs*
whereis fdfs_trackerd
fdfs_trackerd: /usr/bin/fdfs_trackerd
sed -i &#039;s#/usr/local/bin#/usr/bin#g&#039;  /etc/init.d/fdfs_storaged
sed -i &#039;s#/usr/local/bin#/usr/bin#g&#039;  /etc/init.d/fdfs_trackerd
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1786</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux下添加FTP账号和服务器、增加密码和用户，更改FTP目录</title>
		<link>https://www.yunda51.com/?p=1780</link>
		<comments>https://www.yunda51.com/?p=1780#comments</comments>
		<pubDate>Sat, 27 May 2017 08:04:07 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[FTP]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1780</guid>
		<description><![CDATA[1、 启动VSFTP服务器 A:Cenos下运行:yum install vsftpd B. 登录Linux主<a href="https://www.yunda51.com/?p=1780" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>1、 启动VSFTP服务器</strong><br />
A:Cenos下运行:yum  install  vsftpd<br />
B. 登录Linux主机后，运行命令：”service vsftpd start”<br />
C. 要让FTP每次开机自动启动，运行命令:  “chkconfig --level 35 vsftpd on”</p>
<p><strong>2、设置FTP权限</strong><br />
A. 编辑VSFTP配置文件，运行命令：”vi /etc/vsftpd/vsftpd.conf “<br />
B. 将配置文件中”anonymous_enable=YES “改为 “anonymous_enable=NO”<br />
C. 保存修改，按ESC键，运行命令：“：wq”<br />
这样关闭了匿名登录功能。<br />
<strong><br />
3、添加FTP账号</strong><br />
A. 登录Linux主机后，运行命令：”useradd ftpadmin -s /sbin/nologin “。该账户路径默认指向/home/ftpadmin目录；<br />
如果需要将用户指向其他目录，请运行命令：useradd ftpadmin -s /sbin/nologin –d /www(其他目录)<br />
修改指向目录如下：</p>
<pre class="wp-code-highlight prettyprint">
vim /etc/passwd
</pre>
<p>如图：<a href="http://www.yunda51.com/wp-content/uploads/2017/05/20170527160054.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/05/20170527160054.png" alt="20170527160054" width="686" height="105" class="alignnone size-full wp-image-1781" /></a></p>
<p>B. 设置ftpadmin用户密码，运行命令：”passwd ftpadmin” ; 输入两次密码，匹配成功后，就设置好了ftpadmin用户的密码了。</p>
<pre class="wp-code-highlight prettyprint">
设置完之后记得给指向目录权限：chmod 777 /app/www/
</pre>
<p>C.打开你的filezilla连接软件进行连接！</p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1780</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Git的基本操作指令</title>
		<link>https://www.yunda51.com/?p=1762</link>
		<comments>https://www.yunda51.com/?p=1762#comments</comments>
		<pubDate>Fri, 05 May 2017 02:19:34 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1762</guid>
		<description><![CDATA[1.1.0git创建密钥 $ ssh-keygen -t rsa //创建密钥 $ cat ~/.ssh/id<a href="https://www.yunda51.com/?p=1762" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>1.1.0git创建密钥</strong></p>
<pre class="wp-code-highlight prettyprint">
$ ssh-keygen -t rsa   //创建密钥
$ cat ~/.ssh/id_rsa.pub //查看密钥
git clone ssh://git@192.168.199.154:52113/yunda/router.git  //克隆
git add  aa.php  //添加   touch ceshi.php 创建php文件
git status   //查看状态
git commit -m &quot;php用例&quot;;    //提交并添加注释
git push //推
git pull //拉取
</pre>
<p><strong>1.1.1git提交数据</strong><br />
我们可以简单的把工作目录理解成是一个被git服务程序管理的目录，githi时刻的追踪目录类文件的改动，另外在安装好了git服务程序后，默认就会城建好了一个叫做master的分支，我们直接可以提交数据了。</p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1~]# mkdir sutongwang  #创建本地工作目录
[root@git-node1~]# cd sutongwang/     #进入本地工作目录
[root@git-node1 sutongwang]# git init  #初始为git工作目录
Initialized empty Git repository in /root/sutongwang/.git/
[root@git-node1 sutongwang]# touch readme.txt  #创建文件
[root@git-node1 sutongwang]# git status  #查看git状态
#Untracked files:
#   (use &quot;git add &lt;file&gt;...&quot; toinclude in what will be committed)
#       readme.txt  #发现新建的readme.txt文件
…

[root@git-node1sutongwang]# git add readme.txt  #git添加文件至暂存区
[root@git-node1 sutongwang]# git status  #再次查看状态
#Changes to be committed:
#   (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)
#       new file:   readme.txt#发现新建立的文件readme.txt已经变绿
…
 
[root@git-node1 sutongwang]# git commit -m &quot;the first commit&quot;  #git cmmit提交暂存取文件至git版本仓库
[master (root-commit) dde9e40] the first commit1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
</pre>
<p><strong>1.1.2git移除数据</strong><br />
有些时候会把已经添加早暂存区的文件移除，但仍希望文件在工作目录中不丢失，换句话说，就是把问价从追踪清单中删除。</p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# touch database  #建立文件
[root@git-node1 sutongwang]# git add database   #添加文件至暂存区
[root@git-node1 sutongwang]# git status  #查看当前git状态
# On branch master
# Your branch is ahead of &#039;origin/master&#039; by 4 commits.
#   (use &quot;git push&quot; to publish your local commits)
#
# Changes to be committed:
#   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
#
#       new file:   database
[root@git-node1 sutongwang]# git rm --cached database  #将文件从git暂存区域的追踪列表移除(并不会删除当前工作目录内的数据文件)
rm &#039;database&#039;
[root@git-node1 sutongwang]# git status  #此时文件已经是未追踪状态了
# On branch master
#Untracked files:
#   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)
#
#       database
no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
#如果想将文件数据从git暂存区和工作目录一起删除，可以做如下操作。
[root@git-node1 sutongwang]# git add database  #再将database文件提交到git暂存区
[root@git-node1 sutongwang]# git rm -f database  #但如果在删除之前数据文件已经被放入到暂存区域的话，git会担心你误删未提交的文件而报错信息，此时可追加强制删除-f参数。
rm &#039;database&#039;
[root@git-node1 sutongwang]# ls  #查看工作区也没database文件
LICENSE  deployhelp.md  readme.txt
[root@git-node1 sutongwang]# git status  #查看当前状态
# Onbranch master
no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
</pre>
<p><strong>1.1.3git移动数据</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git mv readme.txt test.txt  #git如果要修改文件名称,则使用git mv命令
[root@git-node1 sutongwang]# git status  #查看状态发现下次提交会有一个改名操作
# On branch master
# Changes to be committed:
#   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
#
#       renamed:    readme.txt -&gt; test.txt
[root@git-node1 sutongwang]# git commit -m &quot;changed name&quot;  #提交到git版本仓库
[master 88f3791] changed name
 2 files changed, 31 deletions(-)
 delete mode 100644 1
 rename readme.txt =&gt; test.txt (100%)
 
#其实可以如下方法改名
[root@git-node1 sutongwang]# mv test.txt readme.txt  #先修改名称
[root@git-node1 sutongwang]# git rm test.txt  #然后删除git版本仓库内的文件快照
rm &#039;test.txt&#039;
[root@git-node1 sutongwang]# git add readme.txt  #最后再将新的文件添加进入
[root@git-node1 sutongwang]# git commit -m &quot;changed the file name&quot;  #提交至git版本仓库
[master 2caa209] changed the file name
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename test.txt =&gt; readme.txt (100%)
</pre>
<p><strong>1.1.4git的历史记录：</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git log  #查看提交历史记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
commit 76c486fcf5d70b6a443ba9e7dad209c6722c8bee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:22:39 2016 +0800
 
    tet
[root@git-node1 sutongwang]# git log -2  #查看最近几条记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
[root@git-node1 sutongwang]#
[root@git-node1 sutongwang]# git log -p -1  #-p显示每次提交的内容差异,例如仅查看最近一次差异
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..a9b574e
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,3 @@
+1 hehe
+Create new mode two
+Create new branch is linux
diff --git a/test.txt b/test.txt
deleted file mode 100644
index a9b574e..0000000
--- a/test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-1 hehe
-Create new mode two
-Create new branch is linux
[root@git-node1 sutongwang]# git log --stat -2 #--stat简要显示数据增改行数，这样能够看到提交中修改过的内容，对文件添加或移动的行数，并在最后列出所有增减行的概要信息
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
 readme.txt | 3 +++
 test.txt| 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author: sutongwang &lt;sutongwang@mail.com&gt;
Date:   Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
 1| 31 -------------------------------
 readme.txt |3 ---
 test.txt|  3 +++
 3 files changed, 3 insertions(+), 34 deletions(-)
[root@git-node1 sutongwang]# git log --pretty=oneline #--pretty根据不同的格式展示提交的历史信息
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
76c486fcf5d70b6a443ba9e7dad209c6722c8bee tet
[root@git-node1 sutongwang]# git log --pretty=fuller -2 #以更详细的模式输出提交的历史记录
commit 2caa2090efa1aaf5c32524a13c500c1524e0a5ee
Author:     sutongwang &lt;sutongwang@mail.com&gt;
AuthorDate: Sat Jan 16 18:32:53 2016 +0800
Commit:     sutongwang &lt;sutongwang@mail.com&gt;
CommitDate: Sat Jan 16 18:32:53 2016 +0800
 
    changed the file name
 
commit 88f379175b5ead7e0d84e47bd6db6f5a3b072921
Author:     sutongwang &lt;sutongwang@mail.com&gt;
AuthorDate: Sat Jan 16 18:31:03 2016 +0800
Commit:     sutongwang &lt;sutongwang@mail.com&gt;
CommitDate: Sat Jan 16 18:31:03 2016 +0800
 
    changed name
 
还可以使用format参数来指定具体的输出格式，这样非常便于后期编程的提取分析哦，常用的格式有：
%s  提交说明。
%cd 提交日期。
%an 作者的名字。
%cn 提交者的姓名。
%ce 提交者的电子邮件。
%H  提交对象的完整SHA-1哈希字串。
%h  提交对象的简短SHA-1哈希字串。
%T  树对象的完整SHA-1哈希字串。
%t  树对象的简短SHA-1哈希字串。
%P  父对象的完整SHA-1哈希字串。
%p  父对象的简短SHA-1哈希字串。
%ad 作者的修订时间。
 
[root@git-node1 sutongwang]# git log --pretty=fomat:&quot;%h %cn&quot; #查看当前所有提交记录的简短SHA-1哈希字串与提交着的姓名
fomat:2caa209 sutongwang
fomat:88f3791 sutongwang
fomat:76c486f sutongwang
</pre>
<p><strong>1.1.5git还原数据</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# echo &quot;Git is a version control system&quot; &gt;&gt; readme.txt #追加一段话
[root@git-node1 sutongwang]# git add readme.txt  #添加至暂存区
[root@git-node1 sutongwang]# git commit -m &quot;introduction software&quot; #提交至git版本仓库
[master 4bf5b29] introduction software
 1 file changed, 1 insertion(+)
 
此时觉得写得不妥，想还原某一次提交的文件快照
[root@git-node1 sutongwang]# git log --pretty=oneline #提交的历史信息
4bf5b296db9678f1851b896ed040fe37e6d7efb5 introduction software
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
Git服务程序中有一个叫做HEAD的版本指针，当用户申请还原数据时，其实就是将HEAD指针指向到某个特定的提交版本，但是因为Git是分布式版本控制系统，为了避免历史记录冲突，故使用了SHA-1计算出十六进制的哈希字串来区分每个提交版本，另外默认的HEAD版本指针会指向到最近的一次提交版本记录，而上一个提交版本会叫HEAD^，上上一个版本则会叫做HEAD^^，当然一般会用HEAD~5来表示往上数第五个提交版本。
 
[root@git-node1 sutongwang]# git reset --hard HEAD^  #还原历史提交版本上一次
HEAD is now at 2caa209 changed the file name
[root@git-node1 sutongwang]#  cat readme.txt  #查看文件内容(已经还原)
Create new branch is linux
 
刚刚的操作实际上就是改变了一下HEAD版本指针的位置，就是你将HEAD指针放在那里，那么你的当前工作版本就会定位在那里，要想把内容再还原到最新提交的版本，先看查看下提交版本号
[root@git-node1 sutongwang]# git log --pretty=oneline
2caa2090efa1aaf5c32524a13c500c1524e0a5ee changed the file name
88f379175b5ead7e0d84e47bd6db6f5a3b072921 changed name
 
怎么搞得？竟然没有了Introduction software这个提交版本记录？
原因很简单，因为我们当前的工作版本是历史的一个提交点，这个历史提交点还没有发生过Introduction software更新记录，所以当然就看不到了，要是想“还原到未来”的历史更新点，可以用git reflog命令来查看所有的历史记录：
 
[root@git-node1 sutongwang]# git reflog  #查看未来历史更新点
2caa209 HEAD@{0}: reset: moving to HEAD^
4bf5b29 HEAD@{1}: commit: introduction software
2caa209 HEAD@{2}: commit: changed the file name
 
[root@git-node1 sutongwang]# git reset --hard 4bf5b29  #找到历史还原点的SHA-1值后，就可以还原(值不写全,系统会自动匹配)
HEAD is now at 4bf5b29 introduction software
[root@git-node1 sutongwang]# cat readme.txt  #查看文件内容(已经还原)
Create new branch is linux
Git is a version control system
 
如是只是想把某个文件内容还原，就不必这么麻烦，直接用git checkout命令就可以的，先写一段话
[root@git-node1 sutongwang]# echo &quot;Some mistkes words&quot; &gt;&gt; readme.txt
[root@git-node1 sutongwang]# cat readme.txt  #查看内容
Git is a version control system
Some mistkes words
我们突然发现不应该写一句话的,可以手工删除（当内容比较多的时候会很麻烦）,还可以将文件内容从暂存区中恢复
[root@git-node1 sutongwang]# git checkout -- readme.txt
[root@git-node1 sutongwang]# cat readme.txt
Git is a version control system
这其中是有一套规则，如果暂存区中有该文件，则直接从暂存区恢复，如果暂存区没有该文件，则将还原成最近一次文件提交时的快照。
</pre>
<p><strong>1.1.6创建git分支</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git branch linux  #创建分支
[root@git-node1 sutongwang]# git checkout linux  #切换分支
Switched to branch &#039;linux&#039;
[root@git-node1 sutongwang]# git branch  #查看当前分支情况,当前分支前有*号
* linux
  master
[root@git-node1 sutongwang]# echo &quot;Create new branch is linux&quot; &gt;&gt; readme.txt   #我们对文件追加一行字符串
[root@git-node1 sutongwang]# git add readme.txt   #提交到暂存区
[root@git-node1 sutongwang]# git commit -m &quot;new branch&quot;  #提交到git版本仓库
[linux 8bf5757] new branch
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# git checkout master  #我们在提交文件后再切回master分支
Switched to branch &#039;master&#039;
[root@git-node1 sutongwang]# cat readme.txt   #查看文件内容,发现并没有新追加的字符串1 hehe
</pre>
<p><strong>1.1.7git合并分支</strong><br />
现在，我们想把linux的工作成果合并到master分支上，则可以使用“git merge“ 命令来讲指定的分支与当前的分支合并<br />
<a href="http://www.yunda51.com/wp-content/uploads/2017/05/图片1.png"><img src="http://www.yunda51.com/wp-content/uploads/2017/05/图片1.png" alt="图片1" width="567" height="228" class="alignnone size-full wp-image-1763" /></a></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git branch  #查看是否在master分支
  linux
* master
[root@git-node1 sutongwang]# git merge linux  #合并Linux分支至master
Updating 185d668..8bf5757
Fast-forward
 readme.txt | 1 +
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# cat readme.txt  #查看合并后的readme文件1 hehe
Create new branch is linux
[root@git-node1 sutongwang]# git branch -d linux  #确认合并完成后，可以放心地删除Linux分支
Deleted branch linux (was 8bf5757).
[root@git-node1 sutongwang]# git branch  #删除后，查看branch,只剩下master分支了
*master
</pre>
<p><strong>1.1.8git分支冲突</strong></p>
<pre class="wp-code-highlight prettyprint">
[root@git-node1 sutongwang]# git checkout -b linux  #创建分支并切换到该分支
[root@git-node1 sutongwang]# git branch  #查看分支
* linux
  master
[root@git-node1 sutongwang]# vim readme.txt  #编辑readme文件
[root@git-node1 sutongwang]# git add readme.txt  #在Linux分支添加readme至暂存区
[root@git-node1 sutongwang]# git commit -m &quot;create two&quot;  #在Linux分支提交readme
[linux 13a42ad] create two
1 file changed, 1 insertion(+), 2 deletions(-)
[root@git-node1 sutongwang]# git checkout master  #切换到master分支
Switched to branch &#039;master&#039;
[root@git-node1 sutongwang]# git branch  #查看是否切换至master分支
  linux
* master
[root@git-node1 sutongwang]# vim readme.txt  #编在master分支上修改readme文件同一行的内容
[root@git-node1 sutongwang]# git add readme.txt  #添加至暂存区
[root@git-node1 sutongwang]# git commit -m &#039;create to master&#039;  #提交至Git版本仓库
[master 75bd55c] create to master
 1 file changed, 1 insertion(+)
[root@git-node1 sutongwang]# git merge linux  #合并Linux分支(冲突)
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
#那么此时，我们在master与linux分支上都分别对中readme文件进行了修改并提交了，那这种情况下Git就没法再为我们自动的快速合并了，它只能告诉我们readme文件的内容有冲突，需要手工处理冲突的内容后才能继续合并
[root@git-node1 sutongwang]# cat readme.txt #冲突内容如下
#Git用&lt; &lt;&lt;&lt;&lt;&lt;&lt;，=======，&gt;&gt;&gt;&gt;&gt;&gt;&gt;分割开了各个分支冲突的内容，我们需要手工的删除这些符号，并将内容修改
1 hehe
&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
=======
&gt;&gt;&gt;&gt;&gt;&gt;&gt; linux
Create new branch is linux
[root@git-node1 sutongwang]# git add readme.txt  #再次添加至暂存区
[root@git-node1 sutongwang]# git commit -m &#039;config&#039;  #提交至git版本仓库
[master eb9bb83] config
[root@git-node1 sutongwang]# git branch -d linux  #最后删除Linux分支结束
Deleted branch linux (was 13a42ad).
[root@git-node1 sutongwang]# git branch  #检查是否删除完毕
* master
</pre>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1762.html">http://www.yunda51.com/1762.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1762</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
