实践发现:删除多了一个linux-image-extra-4..0-78-generic,应该留下俩。

当linux有新的内核发布时,ubuntu会把当前的内核更新为最新的内核,时间久了,电脑中会同时存在多个内核,最明显的是每次开机的时候,会有多个开机选项,比较麻烦。如果自己不想再使用以前的内核,可以考虑删除旧的内核,一来可以释放部分硬盘资源(一个内核100多M的样子吧),二来开机界面比较清新。



1.sunny@ubuntu:~$ dpkg --get-selections|grep linux-image
linux-image-2.6.38-10-generic            install
linux-image-2.6.38-11-generic            install
linux-image-2.6.38-12-generic            install
linux-image-2.6.38-13-generic            install
linux-image-generic                            install



2.查看当前使用的内核

sunny@ubuntu:~$ uname -a
Linux ubuntu 2.6.38-13-generic #56-Ubuntu SMP Tue Feb 14 12:40:40 UTC 2012 i686 i686 i386 GNU/Linux



3.删除其它旧的内核

sunny@ubuntu:~$ sudo apt-get remove linux-image-2.6.38-10-generic linux-image-2.6.38-11-generic linux-image-2.6.38-12-generic



4. 然后做下清理(可有可无)

sunny@ubuntu/usr/src sudo apt−get clean
sunny@ubuntu:/usr/srcsudoapt−getclean
sunny@ubuntu:/usr/src sudo apt-get autoclean


ubuntu中删除显示为deinstall的linux内核:
http://blog.csdn.net/iam333/article/details/37874683

下次开机就没有那些旧的内核了。
来自:http://www.cnblogs.com/king-77024128/articles/2507280.html

http://blog.csdn.net/u010987458/article/details/72381998
下载Adobe Flash Player

https://get.adobe.com/flashplayer/?no_redirect

解压:


tar -xf xxx.tar
得到一个libpepflashplayer.so文件。


2. 加入Chromium的插件文件夹


sudo cp libpepflashplayer.so /usr/lib/chromium-browser/plugins

3. 在Chromium的启动选项中加入这一插件


sudo gedit /etc/chromium-browser/default
在flags一行加上:


CHROMIUM_FLAGS="--ppapi-flash-path=/usr/lib/chromium-browser/plugins/libpepflashplayer.so --ppapi-flash-version=11.5.31.2"
version可以从下载包里面的manifest.json文件里面看到。

启用插件

启动Chromium浏览器,在地址栏输入
chrome://plugins/

启用插件即可


http://www.cnblogs.com/linkzijun/p/6492761.html
save_cycle_data || { echo 'save cycle data failed' && exit 1; }  #调用函数失败的写法
basedir=$(cd "$(dirname "$0")";pwd)
echo $basedir

cat /backup/3306/cycle_file
BASE_ID=base-2018-06-11-1203
INCREMENTAL_STEP=20534973839
LAST_LSN=2
获取到等号后面的位置:


获取INNODB的Last checkpoint at:


参数之f3,砍断后第三节,如下:

$git branch -a|grep -v "*" | grep -v ">"
  master
  remotes/origin/dev
  remotes/origin/master


Cut上来:

$git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3
  master
dev
master



sed 去空格和Tab:

git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3|sed "s/^[ \t]*//g"



去掉重复行:

$git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3|sed "s/^[ \t]*//g"
master
dev
master



按正顺序sort:(反着排序 -r)

$git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3|sed "s/^[ \t]*//g"|sort
dev
master
master



uniq上来去重:

git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3|sed "s/^[ \t]*//g"|sort|uniq



防止太多,限制10条,head -10上来:

git branch -a|grep -v "*" | grep -v ">"|cut -d "/" -f3|sed "s/^[ \t]*//g"|sort|uniq|head -10




当然,还有更简单的,不用git branch -a:
主要是了解命令:

$git branch |sed "s# ##g"|sed "s#*##"
dev
master

addr:You have new mail in /var/spool/mail/root


背景:研究一下这个Swoole2.X(V2.0.8)的协程,于是试了一下Tcp/Mysql/Redis/Http(在一个以Http形式下,协程了:TcpServer配置、Redis配置、Mysql配置、Http,最后的接口返回时间以里面最长的那个为准,也就是一般是Mysql耗时最长,它就是最长的接口返回时间了。)一起上,Swoole顾问觉得要想性能高还得加上RPC,再就是在一些数据的Pack和Unpack性能上予以加强,以争取每个请求都非常快非常高效,一请求发现出现了段错误,最新版本出现小小的问题属于正常性况,关键是如何反馈问题,看了一下Swoole的Wiki是如何提Bug的连接,于是就试着提一个Bug吧,给其它用Swoole万一出现Coredump的兄弟们作一个示范,进行提Bug的和捕获相关的Coredump的输出,参考Swoole的Wiki,地址:https://wiki.swoole.com/wiki/page/10.html。

一、假如在你的项目中出现段错误,怎么办?重新编译打包Swoole的源码并打成RPm包,打开debug,参数是: --enable-debug ,如下:
swoole-php71-2.0.7.el7.x86_64.spec 打包./configure部分:
#./configure --with-php-config=%{php_bin}/php-config --enable-coroutine --enable-async-redis
./configure --with-php-config=%{php_bin}/php-config --enable-coroutine --enable-async-redis --enable-debug

二、Mysql部分做测试,加上用户权限,那个Tcp就用Swoole的示例打开9501端口,官网上有很简单的TcpServer样例(略),Mysql部分如下:
Mysql服务器上@101.200.*.135:
#mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 93109
Server version: 8.0.0-dmr-log Source distribution

mysql> grant all privileges on test.* to swooleUser@10.51.*.34 identified by "test123";
Query OK, 0 rows affected, 1 warning (0.04 sec)

mysql> flush privileges;    
Query OK, 0 rows affected (0.01 sec)

@测试机器@123.57.*.183
#rpm -ql mysql-client-8.0.0-170523211353.el7.centos.x86_64
/usr/local/mysql/bin/mysql
#/usr/local/mysql/bin/mysql -h10.44.*.177 -uswooleUser -p
Enter password:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)



三、根据TcpServer配置、Redis配置、Mysql配置、Http(试着访问百度的Http页面),一般来讲都是Mysql慢,所以,它才是重点,代码如下:
coroutinemysql.php

<?php
$server = new Swoole\Http\Server("123.57.*.183", 9507, SWOOLE_BASE);
$server->set([
    'worker_num' => 1,
]);

$server->on('Request', function ($request, $response) {
    $tcpclient = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
    $tcpclient->connect('127.0.0.1', 9501,0.5);
    $tcpclient->send("hello world\n");

    $redis = new Swoole\Coroutine\Redis();
    $redis->connect('123.57.*.183', 6379);
    $redis->setDefer();
    $redis->get('key');

    $mysql = new Swoole\Coroutine\MySQL();
    $ret = $mysql->connect([
    'host' => '10.44.*.177',
    'port' => 3306,
        'user' => 'swooleUser',
        'password' => 'test123',
        'database' => 'test',
    ]);
    if ($ret == false) {
        $response->end("MySQL connect fail!");
        return;
    }
    $mysql->setDefer();
    $mysql->query('select sleep(1)');

    $httpclient = new Swoole\Coroutine\Http\Client('123.125.114.144', 80);
    $httpclient->setHeaders(['Host' => "baidu.com"]);
    $httpclient->set([ 'timeout' => 1]);
    $httpclient->setDefer();
    $httpclient->get('/');

    $tcp_res  = $tcpclient->recv();
    $redis_res = $redis->recv();
    $mysql_res = $mysql->recv();
    $http_res  = $httpclient->recv();

    $response->end('Test End');
});
$server->start();




四、按Swoole官方的Wiki教程,设置一下吐核,From: https://wiki.swoole.com/wiki/page/10.html :
#ulimit -c unlimited

五、启动对外提供的Http协议的9507端口访问进来后的多种协议并发的协程服务,如下:
#php  coroutinemysql.php


六、访问Http时再触发一下协程:
触发一下:http://123.57.*.183:9507/

七、生成了段错误的Coredump文件,如下:
#php  coroutinemysql.php
段错误(吐核)

#ls *core*              
core.8494


八、用GDB去跟进其堆栈,BT显示调用层级定位出现问题所在位置:
#gdb php /tmp/core.8494
(gdb) bt
#0  0x00007f146b33e9a5 in http_client_coro_send_http_request (zobject=0x7f147248d190)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_client_coro.c:501
#1  0x00007f146b383c93 in swClient_onWrite (reactor=<optimized out>, event=0x7ffd0c185a10)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Client.c:1109
#2  0x00007f146b37d63c in swReactorEpoll_wait (reactor=0x1dfc338, timeo=<optimized out>)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/reactor/ReactorEpoll.c:270
#3  0x00007f146b389de9 in swReactorProcess_loop (pool=<optimized out>,
    worker=worker@entry=0x7ffd0c185ae0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/ReactorProcess.c:379
#4  0x00007f146b38a727 in swReactorProcess_start (serv=serv@entry=0x1dc7cf0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/ReactorProcess.c:112
#5  0x00007f146b381538 in swServer_start (serv=serv@entry=0x1dc7cf0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Server.c:696
#6  0x00007f146b333730 in zim_swoole_http_server_start (execute_data=0x7f14724130a0,
    return_value=0x7ffd0c185cb0)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_server.c:1567
#7  0x00000000008ad0c6 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
#8  0x000000000085bd3b in execute_ex ()
#9  0x00000000008aee24 in zend_execute ()
#10 0x0000000000816fc4 in zend_execute_scripts ()
#11 0x00000000007b8520 in php_execute_script ()
#12 0x00000000008b0fbf in do_cli ()
#13 0x000000000043d450 in main ()

(gdb)f 1
#1  0x00007f146b383c93 in swClient_onWrite (reactor=<optimized out>, event=0x7ffd0c185a10)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/src/network/Client.c:1109
1109                cli->onConnect(cli);

(gdb)f 0
#0  0x00007f146b33e9a5 in http_client_coro_send_http_request (zobject=0x7f147248d190)
    at /home/test/rpmbuild/BUILD/swoole-src-2.0.7-stable/swoole_http_client_coro.c:501
501         if (!http->cli || !http->cli->socket )

九、用valgrind大体排查一下是否有内存溢出等:
[root@测试服务器:/tmp]
#USE_ZEND_ALLOC=0 valgrind php coroutinemysql.php
==12833== Memcheck, a memory error detector
==12833== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==12833== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==12833== Command: php coroutinemysql.php
==12833==

==12833== Invalid read of size 8
==12833==    at 0x121249A5: http_client_coro_send_http_request (swoole_http_client_coro.c:501)
==12833==    by 0x12169C92: swClient_onWrite (Client.c:1109)
==12833==    by 0x1216363B: swReactorEpoll_wait (ReactorEpoll.c:270)
==12833==    by 0x1216FDE8: swReactorProcess_loop (ReactorProcess.c:379)
==12833==    by 0x12170726: swReactorProcess_start (ReactorProcess.c:112)
==12833==    by 0x12167537: swServer_start (Server.c:696)
==12833==    by 0x1211972F: zim_swoole_http_server_start (swoole_http_server.c:1567)
==12833==    by 0x8AD0C5: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (in /usr/local/php/bin/php)
==12833==    by 0x85BD3A: execute_ex (in /usr/local/php/bin/php)
==12833==    by 0x8AEE23: zend_execute (in /usr/local/php/bin/php)
==12833==    by 0x816FC3: zend_execute_scripts (in /usr/local/php/bin/php)
==12833==    by 0x7B851F: php_execute_script (in /usr/local/php/bin/php)
==12833==  Address 0x100000188 is not stack'd, malloc'd or (recently) free'd
==12833==
==12833==
==12833== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==12833==  Access not within mapped region at address 0x100000188
==12833==    at 0x121249A5: http_client_coro_send_http_request (swoole_http_client_coro.c:501)
==12833==    by 0x12169C92: swClient_onWrite (Client.c:1109)
==12833==    by 0x1216363B: swReactorEpoll_wait (ReactorEpoll.c:270)
==12833==    by 0x1216FDE8: swReactorProcess_loop (ReactorProcess.c:379)
==12833==    by 0x12170726: swReactorProcess_start (ReactorProcess.c:112)
==12833==    by 0x12167537: swServer_start (Server.c:696)
==12833==    by 0x1211972F: zim_swoole_http_server_start (swoole_http_server.c:1567)
==12833==    by 0x8AD0C5: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (in /usr/local/php/bin/php)
==12833==    by 0x85BD3A: execute_ex (in /usr/local/php/bin/php)
==12833==    by 0x8AEE23: zend_execute (in /usr/local/php/bin/php)
==12833==    by 0x816FC3: zend_execute_scripts (in /usr/local/php/bin/php)
==12833==    by 0x7B851F: php_execute_script (in /usr/local/php/bin/php)
==12833==  If you believe this happened as a result of a stack
==12833==  overflow in your program's main thread (unlikely but
==12833==  possible), you can try to increase the size of the
==12833==  main thread stack using the --main-stacksize= flag.
==12833==  The main thread stack size used in this run was 8388608.
==12833==
==12833== HEAP SUMMARY:
==12833==     in use at exit: 22,357,752 bytes in 22,711 blocks
==12833==   total heap usage: 29,852 allocs, 7,141 frees, 23,257,973 bytes allocated
==12833==
==12833== LEAK SUMMARY:
==12833==    definitely lost: 64 bytes in 2 blocks
==12833==    indirectly lost: 4,096 bytes in 2 blocks
==12833==      possibly lost: 1,813,286 bytes in 18,399 blocks
==12833==    still reachable: 20,540,306 bytes in 4,308 blocks
==12833==         suppressed: 0 bytes in 0 blocks
==12833== Rerun with --leak-check=full to see details of leaked memory
==12833==
==12833== For counts of detected and suppressed errors, rerun with: -v
==12833== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
段错误


十、在PHP代码上加加减减,定位一下PHP这个协程是哪个协议出现问题,经定位发现是发起http这块的协程可能有问题,如下:
再细节一点:
#php coroutinemysql.php
段错误(吐核)
这一行引起的:$httpclient->setDefer();     #setDefer函数的Wiki地址:https://wiki.swoole.com/wiki/page/607.html

$httpclient = new Swoole\Coroutine\Http\Client('123.125.114.144', 80);
$httpclient->setHeaders(['Host' => "baidu.com"]);
$httpclient->set([ 'timeout' => 3]);
$httpclient->setDefer();            #注释这一行,就会报下面的警告,不会Coredump,如下:                                                                
$httpclient->get('/');

#php coroutinemysql.php   #浏览器访问一下:http://123.57.*.183:9507/
PHP Warning:  Swoole\Coroutine\Http\Client::recv(): you should not use recv without defer  in /tmp/coroutinemysql.php on line 40
PHP Warning:  Swoole\Coroutine\Http\Client::recv(): you should not use recv without defer  in /tmp/coroutinemysql.php on line 40

在服务器上CURL形式访问一下百度,没毛病:
curl -i -H"Host:baidu.com" http://123.125.114.144            
HTTP/1.1 200 OK  
<html>
<meta http-equiv=refresh content=0;url=http://www.baidu.com/>
</html>


十一、提交出现Coredump以及和环境相关的问题给Swoole的CoreTeam研发小组的兄弟:
请将上面的得到的信息,连同机器信息,包括php -v gcc -v uname -a 提交到Github Issues页面或者发送邮件到 team@swoole.com。
若确定是Swoole的问题,开发组会快速解决问题。
其它涉及到编译器和PHP版本、系统环境:
#php -v
PHP 7.1.5 (cli) (built: May 23 2017 10:35:57) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

#gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)


#uname -a
Linux 测试服务器 4.11.2-1.el7.elrepo.x86_64 #1 SMP Sun May 21 19:31:34 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux


#php --ri swoole

swoole

swoole support => enabled
Version => 2.0.8
Author => tianfeng.han[email: mikan.tenny@gmail.com]
epoll => enabled
eventfd => enabled
timerfd => enabled
signalfd => enabled
cpu affinity => enabled
spinlock => enabled
rwlock => enabled
async redis client => enabled
async http/websocket client => enabled
Linux Native AIO => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled

Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.fast_serialize => 1 => 1
swoole.unixsock_buffer_size => 8388608 => 8388608


EOF
背景:发现df 特别慢,用strace df -h ,发现卡在/mnt/backup,想cd /mnt卡住了,于是,怎么办?发现NFS的Server端都宕机了。
cat /proc/mounts
umount -lf   /mnt/backup
umount: only root can do that
Root:
umount -lf   /mnt/backup
More: http://justwinit.cn/post/6800/
-------------------------------------------------------------------------------------
这个问题是第二次遇到了。这次一定要记下来,免得日后麻烦!!
问题描述:

有两台服务器,其中一台向另一台通过nfs共享分区,如下:

server A: nfs server
server B: nfs Client

事件发生: Server A,B 因故障同时重启。 重启后,用putty登陆到server A ,运行‘df’命令:
$ df

$ Filesystem           1K-blocks      Used Available Use% Mounted on

/dev/sda5             80632188   8899080  67636940  12% /

none                   4086484         0   4086484   0% /dev/shm

/dev/sda2            201582252  32076524 159265900  17% /opt

/dev/sda3            201582252  44511180 146831244  24% /fs

/dev/sda7             20161172    332916  18804116   2% /usr/local

/dev/sda8             20161172     78360  19058672   1% /tmp

$(没有出现这个命令提示符)

无奈,只好再用putty 登陆Server A ,将 df 进程kill......


只好尝试重新mount

$mount -t nfs B:/data /mnt/data

failed: RPC Error: Program not registered


哦~~~ ,原来B的nfs 服务没有start...  登陆B:
$serive nfs restart

重新再A上运行df,仍然死掉...

想到先卸载,在挂载:

$umount /mnt/data

device is busy 。



运行fuser -mk /mnt/data 杀掉访问/mnt/data所有进程。

/mnt/data: Stale NFS file handle



在server A 运行 A , ok ~~~

重新mount -t nfs B:/data /mnt/data  打完收工。

来自:http://blog.csdn.net/daniel_cao_/article/details/4584443
TPLink_TLWN725N无线网卡支持SoftAP功能,在XP下面配置模拟AP时,开启SoftAP功能,
可能会弹出报错信息“配置ICS失败,你可以连接到SoftAP,但可能无法使用因特网服务”。
解决方法:
1.电脑上打开“服务与应用程序”---“服务”,找到“Windows Firewall/Internet Connection Sharing(ICS)”服务,确保此服务已经开启,如未开启,将此服务手动开启并将启动类型设置为自动。

2.如果电脑上网络连接在开启SoftAP之前就已经手动共享过了,将此共享取消。

3.如果电脑上网络连接在开启SoftAP之前并没有手动共享过,但是仍然提示错误,很有可能是电脑的系统在开启SoftAP功能之前曾经使用过网络连接共享的应用,其状态尚未恢复到初始状态。首先关闭SoftAP功能。接着打开电脑网络连接页面,找到本地连接,查看本地连接状态是否已经共享。
(1)若已经共享,右键“本地连接”选择“属性”---“高级”选项卡,将“Internet连接共享”关闭,点击“确定”。然后将另外一个网络连接的共享开启之后再关闭。重新尝试开启SoftAP功能。
(2)若未共享,随便找一个网络连接,将其共享开启之后再关闭,然后重新尝试开启SoftAP功能。


来自:http://www.360doc.com/content/13/1010/18/2250352_320378101.shtml
分析文章:https://huoding.com/2013/10/06/288
内存不够用时通过它来申请新内存(data segment)


「man brk」来查询一下它的含义:

brk() sets the end of the data segment to the value specified by end_data_segment, when that value is reasonable, the system does have enough memory and the process does not exceed its max data size (see setrlimit(2)).

在Strace中和操作花费时间相关的选项有两个,分别是「-r」和「-T」,它们的差别是「-r」表示相对时间,而「-T」表示绝对时间。简单统计可以用「-r」,但是需要注意的是在多任务背景下,CPU随时可能会被切换出去做别的事情,所以相对时间不一定准确,此时最好使用「-T」,在行尾可以看到操作时间,可以发现确实很慢。 更多:https://blog.huoding.com/2013/10/06/288


shell> strace -T -p $(pgrep -n php-cgi) 2>&1 | grep -B 10 brk
stat("/path/to/script.php", {...}) = 0 <0.000064>
brk(0x1d9a000) = 0x1d9a000 <0.000067>
brk(0x1dda000) = 0x1dda000 <0.001134>
brk(0x1e1a000) = 0x1e1a000 <0.000065>
brk(0x1e5a000) = 0x1e5a000 <0.012396>
brk(0x1e9a000) = 0x1e9a000 <0.000092>

cat bak0.c
#include<stdio.h>
#include <unistd.h>

int main()
{
    int*p1 = sbrk(4);
    int*p2 = sbrk(4);
    int*p3 = sbrk(4);
    printf("pid%d\n",getpid());
    printf("p1:%p\n",p1);
    printf("p2:%p\n",p2);
    printf("p3:%p\n",p3);
     while(1);
}

gcc bak0.c  -o main
#./main
pid2816
p1:0x602000
p2:0x602004
p3:0x602008
ps -ef|grep main
root      2994  2461 94 10:26 pts/3    00:00:07 ./main
此时我们可以看下他的maps文件
cat /proc/2994/maps
00602000-00603000 rw-p 00000000 00:00 0                                  [heap]


2)  内核维护一个指针,假设是p,那么sbrk(0)或得到一个没有被占用的虚拟内存地址,但是此时不分配空间,但是此时只是初始化p,所以你如果对此时得到的内存地址赋值,那么就会出现段错误
cat bak.c
#include<stdio.h>
#include<unistd.h>

int main()
{
         int *p = sbrk(0);
         printf("%p\n",p);
         *p = 111;

}
gcc bak.c -o main

#./main
0x602000
段错误(吐核)


来自:https://blog.csdn.net/xiaoxiaopengbo/article/details/78206953
https://www.cnblogs.com/chengxuyuancc/p/3566710.html
检查是否安装了libxm包

[root@rh-Linux software]# rpm -qa |grep libxml2
libxml2-2.7.6-21.el6_8.1.x86_64
libxml2-devel-2.7.6-21.el6_8.1.x86_64
libxml2-python-2.7.6-21.el6_8.1.x86_64
重新安装libxml2和libxml2-devel包, yum安装的时候发现新版本会提示更新,需要更新的可以更新,不要跳过就行了。

[root@rh-linux /]# yum install libxml2
[root@rh-linux /]# yum install libxml2-devel -y
安装完之后查找xml2-config文件是否存在

[root@rh-linux /] #find / -name "xml2-config"
/usr/bin/xml2-config

From:http://blog.csdn.net/risingsun001/article/details/43705273
PHP版本的实践:https://www.imooc.com/article/10431

背景:在工作中经常会遇到一些关于定时任务的实际场景,比如每天凌晨1点自动备份数据库,或者,每隔1小时执行一次爬虫脚本,这种固定时间执行固定动作的需求我们称之为定时任务,利用crontab即可轻松实现。如果我们对自动备份数据库这个定时任务改变一下需求(这种情况就像你邀请一个人,一天内如果没有人来或有人来你通知下你,你邀请的人来了,这种任务。二、再就是公司没啥好的设备,钱少,网太烂了搞一个任务比如Mysql备份数据库的脚本,比如备份Redis的数据Bgsave的Scp拷贝经常出现网络不好,第一次备份会失败,于是得第二次这种垃圾需求。有垃圾需求就有解决办法,于于优雅或不优雅是一回事,但得技术人员觉得有一个流程总比没有流程好,本来没有方案的,于是就有技术方案。),如图:
点击在新窗口中浏览此图片  
如果仍然利用crontab来实现,就有点勉强了。类似这种需求最常见的是服务器之间的消息通知,假如服务器B由于网络不稳定或者服务器压力较大导致不能即时对服务器A的消息作出正确响应,那么服务器A就会延迟一段时间再次发送消息,直到收到服务器B的正确响应或者超出最大通知次数为止。过去的做法是定时扫表,把通知失败的消息再次发送一遍,虽然可以多次发送通知,但是发送间隔太短会增加服务器B的压力,发送间隔太长消息的时效性就不能保证,显然处理这种延时任务用crontab根本不能解决问题。
Node之Error: Cannot find module 'redis:
#npm install -g redis
/usr/lib
└─┬ redis@2.7.1
  ├── double-ended-queue@2.1.0-0
  ├── redis-commands@1.3.1
  └── redis-parser@2.6.0
环境变量:
#rpm -ql nodejs-6.10.3-1.el7.x86_64
/usr/bin/node
/usr/lib/node_modules
export NODE_PATH=/usr/lib/node_modules
#echo $NODE_PATH  
/usr/lib/node_modules
#node notice.js
订阅成功

select 3
OK
setex msg_2 2 chokingwin
OK
client.on("pmessage", function(pattern, channel, expiredKey) {
    console.log(pattern + "|" + channel + "|" + expiredKey);
_             _keyevent@3__:expired|__keyevent@3__:expired|msg_2




从Redis 2.8.0版本起,加入了"Keyspace notifications"(即"键空间通知")的功能。按照官方的说法:键空间通知,允许Redis客户端从“发布/订阅”通道中建立订阅关系,以便客户端能够在Redis中的数据因某种方式受到影响时收到相应事件。比如:所有改变给定key的命令;所有经过lpush操作的key;所有在0号数据库中过期的key等等。我们在处理延时任务的时候,先把通知失败的消息ID作为key的一部分存到redis缓存中,并设定过期时间(相当于延时),当这条缓存数据失效的时候,通过订阅关系(用NodeJS实现)就可以收到消息,通过分析消息就可以知道过期KEY,这样就可以再次发送消息通知,从而实现延时任务。
不过,需要注意一点:Redis的发布/订阅目前是即发即弃(fire and forget)模式的,因此无法实现事件的可靠通知。也就是说,如果发布/订阅的客户端断链之后又重连,则在客户端断链期间的所有事件都丢失了。
核心部分是两个Redis的终端,分别连接上Redis,并打开这个特性,另一个终端是监控的,这块里面用代码进行编写订阅,如下:
订阅,作者用的是Node,我在这儿不得不打下广告了,Swoole是不是应该也能支持这个功能?https://wiki.swoole.com/wiki/page/523.html ,http://blog.csdn.net/koastal/article/details/52869140,subscribe。
psubscribe来自:https://wiki.swoole.com/wiki/page/590.html

<?php
$serv = new Swoole\Server("127.0.0.1", 9501);
$serv->set(array(
    'worker_num' => 8,   //工作进程数量
    'daemonize' => false, //是否作为守护进程
));
$serv->on('connect', function ($serv, $fd){
    echo "Client:Connect.\n";
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $val = "";
    $redis = new Swoole\Coroutine\Redis();
    $redis->connect('10.51.77.34', 6379);
    while (true) {
        $val = $redis->psubscribe(['psubscribe __keyevent@3__:expired']);
        //订阅的channel,以第一次调用subscribe时的channel为准,后续的subscribe调用是为了收取Redis Server>的回包
        //如果需要改变订阅的channel,请close掉连接,再调用subscribe
        var_dump($val);
    }                                                                                                    
});
$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});
$serv->start();


Swoole的这个Redis的Coroutine必须要有一个端口暴露,这是和Node最大的不同吧?上面这个图我试着使用了一下,感觉有点问题。
=============================================================================

#redis-cli -h 10.51.77.34
10.51.77.34:6379>  psubscribe __keyevent@0__:expired
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "__keyevent@0__:expired"
3) (integer) 1



1) "pmessage"
2) "__keyevent@0__:expired"
3) "__keyevent@0__:expired"
4) "name"



塞一个数据进去:

#redis-cli -h 10.51.77.34
10.51.77.34:6379> config set notify-keyspace-events Ex
OK
10.51.77.34:6379> setex name 10 chokingwin
OK


===================================================================================
关于expired事件通知的发送时间
Redis使用以下两种方式删除过期的键:a:当一个键被访问时,程序会对这个键进行检查,如果键已过期,则删除该键;b:系统会在后台定期扫描并删除那些过期的键。
当过期键被以上两种方式中的任意一种发现并且删除时,才会产生expired事件通知。
Redis不保证生存时间(TTL)变为 0 的键会立即被删除:如果没有命令访问这个键,或者设置生存时间的键非常多的话,那么在键的生存时间变为0,到该键真正被删除,这中间可能会有一段比较显著的时间间隔。
因此,Redis产生expired事件通知的时间,是过期键被删除的时候,而不是键的生存时间变为 0 的时候。
接下来我们开始代码实现(假定阅读本文的同学已正确安装Nginx/PHP/Redis/NodeJS的环境)。

一、与本文相关的环境信息
Redis配置文件路径:/etc/redis/6379.conf
测试用的Redis库编号为:3
监听消息的NodeJS文件:/NodeApp/notice.js
发送消息的PHP代码为:/send.php
接收redis数据的PHP代码:/test.php
业务流程:首先运行notice.js开启监听,然后运行send.php发送消息,如果没有收到成功响应,将消息ID存入redis缓存,之后按照10秒、30秒、60秒、120秒、300秒的时间间隔,再次发送消息通知,直到收到对消息的成功响应,或者超出最大通知次数为止。

二、修改Redis配置文件
因为键空间通知功能需要耗费一定的CPU时间,因此默认情况下,该功能是关闭的。可以通过修改配置文件,或者通过CONFIG SET命令,设置notify-keyspace-events选项,来启用或关闭该功能。
该选项的值为空字符串时,该功能禁用,选项值为非空字符串时,启用该功能,非空字符串由特定的多个字符组成,每个字符表示不同的意义:
K keyspace事件,事件以__keyspace@<db>__为前缀进行发布
E keyevent事件,事件以__keyevent@<db>__为前缀进行发布
g 一般性的,非特定类型的命令,比如del,expire,rename等
$ 字符串特定命令
l 列表特定命令
s 集合特定命令
h 哈希特定命令
z 有序集合特定命令
x 过期事件,当某个键过期并删除时会产生该事件
e 驱逐事件,当某个键因maxmemore策略而被删除时,产生该事件
A g$lshzxe的别名,因此”AKE”意味着所有事件
注意:该选项的值中至少需要包含K或者E,否则不会发布任何事件。比如,如果需要开启针对列表的keyspace事件通知,则该选项需要配置为"Kl"。

我们在服务器上运行vim /etc/redis/6379.conf,找到notify-keyspace-events开头的一行,将其配置为:notify-keyspace-events Ex,含义为:发布keyevent事件,使用过期事件(当每一个key失效时,都会生成该事件)。保存退出,并重启redis服务。如图:
点击在新窗口中浏览此图片

三、安装Node扩展
在网站根目录下,依次运行:
npm init #初始化创建package.json
npm install redis #安装redis扩展
npm install mysql #安装mysql扩展

四、实现send.php

为了便于实现延时的计算,我们将存入redis的key格式设计为:固定前缀+消息ID+时间戳+次数,如:noticeId_12345678_1482991887_2点击在新窗口中浏览此图片
关键代码:
$delayArr=[0,10,30,60,120,300];//延时间隔,相对于首次通知时间,单位为 s
$res=doSomething();//发送消息
$content=date('Y-m-d H:i:s').' 第 '.$nums.' 次发送通知,消息ID为:'.$noticeId."\n";
if($res==true){
$content.='消息发送成功'."\n";
}else{//未收到对方回应
$content.='消息发送失败,等待下次重发'."\n";
$expTime=$delayArr[$nums];
$nums++;
saveNoticeToRedis($noticeId,$stamp,$nums,$expTime);//存入缓存
}
//记录日志
file_put_contents($root.'/tmp.log',$content,FILE_APPEND);

五、实现 notice.js
服务器端运行notice.js后,会一直监听redis的Expired事件,取到ExpiredKey后,把消息ID、时间、通知次数,POST给test.php,从而实现再次发送消息。

关键代码:
var client = redis.createClient('6379', '127.0.0.1');
client.psubscribe("__keyevent@"+redisDB+"__:expired",function(){
//console.log('订阅成功');
});
client.on("pmessage", function(pattern, channel, expiredKey) {
var tmpArr=expiredKey.split('_');
if(tmpArr[0]==keyPrefix){
console.log('-----expired Key-----',expiredKey);
var noticeId=tmpArr[1];
var stamp=parseInt(tmpArr[2]);
var nums=parseInt(tmpArr[3]);
sendPost(noticeId,stamp,nums,logFile);//向test.php发送数据
}else{
console.log('-----error Key-----',expiredKey);
writeLog(logFile,'The key "'+expiredKey+'" is a error key.');
}
});

六、实现 test.php
点击在新窗口中浏览此图片

关键代码:

$delayArr=[0,10,30,60,120,300];//延时间隔,相对于首次通知时间,单位为 s
$res=doSomething();//发送消息
$content=date('Y-m-d H:i:s').' 第 '.$nums.' 次发送通知,消息ID为:'.$noticeId."\n";
if($res==true){
$content.='消息发送成功'."\n";
}else{//未收到对方回应
if($nums && $nums>=6){
$content.='消息ID:'.$noticeId."已达到最大通知次数,任务停止\n";
}else{
$content.='消息发送失败,等待下次重发'."\n";
$expTime=$stamp+$delayArr[$nums]-time();
$nums++;
saveNoticeToRedis($noticeId,$stamp,$nums,$expTime);//存入缓存
}
}
//记录日志
file_put_contents($root.'/tmp.log',$content,FILE_APPEND);

七、测试结果
点击在新窗口中浏览此图片

八、其他说明
本文内容为个人原创,首发今日头条,同时提供代码下载地址,供大家学习交流。本人以后还会发布更多原创干货,如果觉得有用,希望及时关注本头条号。

代码下载地址:http://www.i1981.com/zb_users/upload/2016/12/20161223.zip
DownLoad:
下载文件
点击这里下载文件


From: http://www.toutiao.com/a6369425996433408257/?tt_from=weixin&utm_campaign=client_share&app=news_article&utm_source=weixin&iid=11032449540&utm_medium=toutiao_ios&wxshare_count=1
背景:Node和PHP在IO密集型上的一个探讨,IO密集可能Node要好一点,能更多压榨系统性能。这个链接应该有一定向Node的倾向性,但都看看叫兼听则明嘛。
Q:兄弟用Node搞毛,赶紧竹筒倒豆子,呵呵
A:做接入层啊,替代PHP接入层的角色.异步嘛 PHP同步是短板

Q:哪些函数异步了?函数支持异步才行吧,要是同步函数不也是同步嘛。
A:nodejs本身天然就支持异步的,里面的所以IO操作都是天然就是异步的。

Q:PHP vs NODE:喔,像兄弟们主要用的Mysql和那个Redis啥的接口吧,还有啥?
A:看场景,如果IO多的话,并发性能能高很多:http://taobaofed.org/blog/2015/11/24/nodejs-php-process-manager/

Q:说白了就是把Node当PHP用呗,IO密集有奇效?
A:是的
php安装模块见http://fffo.blog.163.com/blog/static/211913068201401464238334/

1、官网下载
wget http://prdownloads.sourceforge.net/lam/ldap-account-manager-4.3.tar.bz2?download
2、解压
tar -xjf  ldap-account-manager-4.3.tar.bz2
3、直接移动到apache 根目录
mv  ldap-account-manager-4.3 /usr/local/apache/htdocs/lam
4、给它可以访问的权限
chmod 777 -R /usr/local/apache/htdocs/lam
5、进入配置目录
cd /usr/local/apache/htdocs/lam/config
6、创建主参数文件
cp config.cfg_sample config.cfg
7、创建连接ldap服务器参数文件
cp lam.conf_sample lam.conf
vim lam.conf
修改 所有的dc=1v,dc=cn
8、web访问
http://203.195.187.200/lam/templates/login.php

上面的模式是只限管理员登录模式。现在切换到用户登录模式
点击LAM配置——>编辑服务器配置文件——>默认密码是lam(可修改)——>通用设置——>安全设定

From:http://blog.csdn.net/u012461550/article/details/42608781

我的是在:
/usr/local/lam/etc/unix.conf
一、旧版本的PHP(php5.3.27)要装Mysql之后才能装Mysql(mysqli)扩展?编译选项有这个:
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config

传统的安装php的方式中,我们在编译PHP时,一般需要指定以下几项:
--with-mysql=/usr/local/mysql
--with-pdo-mysql=/usr/local/mysql
这实际上就是使用了mysql官方自带的libmysql驱动, 这是比较老的驱动, PHP 5.3开始已经不建议使用它了, 而建议使用mysqlnd.


以上是摘录,更多查看:http://blog.163.com/yxba_02/blog/static/187557620160401018458/


二、PHP7啥的都不用指定Mysql的位置,直接就能编译通过的呀~

PHP7这样的:
--with-mysql=mysqlnd \    
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \

现在系统存在历史问题,没法一时半会升级PHP7了,还在用 php5.3.27上混,编译选项有指定Mysql路径的。
ldd php
发现:
libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 (0x00002b5b5dec7000)
也就是说PHP5.3.7最后还是编译成自己的LIb了,没有Mysql一样能跑,这TM是个问题,装个PHP还得装上Mysql,这个低版本的PHP还得装Mysql服务才行哟。

总之,Mysql和PHP在低版本有了较强的捆绑,而新的PHP7采用Mysqlnd(MySQL Native Driver),摆脱了这一依赖,更简单,更高效。php高版本不再使用mysql_connect()来连接数据库。

背景:一般来讲Linux对明文登录用户的密码在CentOS里有多种,但是MD5长度在36位以下。容量被破解,正向算法、碰撞等,特别是那个万能Wifi钥匙,我去。CentOS5和CentOS6的想法是更安全,但为了兼容统一管理密码Shadow,批量刷一样的,往往会用MD5这种方式,但是被破解后也是很容易给被攻下的一种弱的加密验证方式。
当用户发出useradd命令时,useradd命令读取/ etc / default / useradd和/etc/login.defs并确定useradd的默认值。 要显示/ etc / defaults / useradd的值,请参阅显示useradd的默认值

#使用MD5或DES加密密码? 红帽默认使用MD5。
MD5_CRYPT_ENAB是的

ENCRYPT_METHOD MD5

背景:原来是因为Jenkins的组不对,再把组修正了下,再加上chmod a+s /bin/su ,后来发现是因为/etc/passwd 里面的shell是 :/bin/false导致没法sudo 成功。
su jenkins
id
uid=0(root) gid=0(root) 组=0(root)

试了下Su到其它用户可以,于是查了一下 vi /etc/passwd :
jenkins:x:1012:1010:Jenkins Continuous Integration Server:/data/jenkins:/bin/false
原来是这儿/bin/false,不是su的问题:
jenkins:x:497:601:Jenkins Continuous Integration Server:/data/jenkins:/bin/bash

于是就好了:
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# su jenkins
[jenkins@iZ2zehnf4lbq2wf83bmzk1Z root]$ id
uid=1012(jenkins) gid=1010(jenkins) 组=1010(jenkins)
==================================================

[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# su jenkins
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# id
uid=0(root) gid=0(root) 组=0(root)
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# whoami
root
[root@iZ2zehnf4lbq2wf83bmzk1Z ~]# id jenkins
uid=984(jenkins) gid=990(jenkins) 组=990(jenkins)

========================================
原因1
/bin/su文件没有s位权限


chmod a+s /bin/su


来自:http://blog.itpub.net/26432034/viewspace-1688391/

解决办法
感谢csdn用户jeecg-scott分享的博文《su 切换,提示:“密码不正确”》以下是连接
http://blog.csdn.net/zhangdaiscott/article/details/18666471

step1
检查/etc目录下passwd的权限
[root@dev /]# ll /etc/passwd
-rw-r--r--. 1 root root 1975 5月  27 06:04 /etc/passwd
如果普通用户不能读请改成644权限
[root@dev /]# chmod 644 /etc/passwd

step2
检查/bin/su文件是否有s位权限
[root@dev ~]# ll /bin/su
-rwxrwxrwx. 1 root root 34904 10月 17 2013 /bin/su
如果不存在则添加上
[root@dev /]# chmod a+s /bin/su
[root@dev /]# ll /bin/su
-rwsrwsrwx. 1 root root 34904 10月 17 2013 /bin/su

step3
测试成功否
[oracle@dev ~]$ su - root
密码:
[root@dev ~]#

背景:频繁调用itv投票和调查接口,导致 redis 频繁bgsave ,进而引起大量磁盘io报警,在一些大型的活动,如奥运会、世界杯一些业务会量比较大,在后端肯定是Redis来扛了,而出现了大量的bgsave,导致Redis在刷磁盘时会出现性能陡然下降,触发了Zabbix的报警,鉴于此,得临时性关掉Redis,redis如何关闭持久化?

bgsave的进程在Fork时会生成一样的内存数据,
操作系统认为太多,导致内存不给分派于是出现,fork: Cannot allocate memory :
https://jee-appy.blogspot.com/2016/04/can-not-save-in-background-fork-redis.html?m=1


修改redis配置文件,redis.conf 第115行左右。

1.注释掉原来的持久化规则
#save 900 1
#save 300 10
#save 60 10000

2.设置为空

save ""

然后重启redis服务即可,Bgsave放在备份Redis里,这样就不会因为主Redis挂了导致宕机。

ls  -lart /data/redis6413 |less
-rw-r--r--  1 redis redis 211841024 Jan  9 14:00 temp-33345.rdb
-rw-r--r--  1 redis redis 212078592 Jan  9 15:00 temp-53462.rdb
-rw-r--r--  1 redis redis 220446720 Jan  9 16:00 temp-8399.rdb
-rw-r--r--  1 redis redis 212865024 Jan  9 17:00 temp-28516.rdb

http://blog.csdn.net/opens_tym/article/details/10097805

摘自 :https://blog.csdn.net/tomisaboy/article/details/53763537
背景:听说Lumen起家是以一个叫av的框架,larvael。以Auth2.0起步,Lumen是精简版本,于是想了解一下。发现居然边TM路由就卡住了,Fuck,不光是我老外也有这个问题,都没有解决,主要是一个Nginx的转写问题,这块在Lumen的文档里写的很垃圾,我都不知这些人是怎么写文档的,有用Apache,有Nginx的就不能写细一点么,说一下原理啥的,关键是Nginx配置文件里面的:location /里面的重写。
From:http://blog.csdn.net/wowkk/article/details/52104689

Lumen 5.5.*版本的Lumen,目录:lumen-clear-edition
composer create-project laravel/lumen lumen-clear-edition --prefer-dist  "5.5.*"  # proc_open,

vi ms/survey/bootstrap/app.php
require __DIR__.'/../config/providers.php'

vi ms/survey/config/providers.php
<?php
$app->register(Common\Providers\RedisServiceProvider::class);
$app->register(Common\Providers\MysqlServiceProvider::class);
$app->register(Common\Providers\KafkaServiceProvider::class);
$app->register(Common\Providers\EventServiceProvider::class);
$app->register(Common\Providers\QueueServiceProvider::class);

注册的文件在:
ls ./lumen-clear-edition/common/Providers
EventServiceProvider.php  MysqlServiceProvider.php  RedisServiceProvider.php

启动方法:
启动方法#服务提供者中注册一个视图 composer 则应该在 boot 方法中完成。此方法会在所有其它的服务提供者被注册后才被调用,意味着你能访问已经被框架注册的所有其它服务:https://lumen.laravel-china.org/docs/5.3/providers,ServiceProvider类,和绑定easy_kafka类:
lumen-clear-edition/common/Providers/KafkaServiceProvider.php

vi lumen-clear-edition/common/Service/Kafka/Kafka.php   #自己写这个类的方法。


绑定的easy_kafka在这儿:
lumen-clear-edition/common/Facades/Kafka.php


ms/survey/app/Http/Controllers/Api/V1/ActivityController.php  #路由@./ms/survey/routes/web.php
$router->group(['namespace'=>'Api\V1'], function () use ($router) {
    $router->post('activity/form', ['uses' => 'ActivityController@form']);


ms/survey/app/Helpers/Client/SurveyClient.php  


类的加载,common文件夹位置:
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Common\\": "common/"
        }
    },
#composer dump-autoload --optimize
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Generating optimized autoload files

生成文件在这儿(挪动一下文件放到新目录,建议重新运行一下这个:composer dump-autoload --optimize,再就是如果有PHP的OPcache得重新启动一下PHP-FPM或关闭掉Opcache,/usr/local/php/etc/php.d/opcache.ini ,opcache.enable=0):
./lumen-clear-edition/vendor/composer/autoload_psr4.php:    'Common\\' => array($baseDir . '/common'),
More:


#find ./ -mtime 0 -type f
./composer.json   <== "Common\\": "common/"
./app/Http/Controllers/Api/V1/ActivityController.php
./app/Helpers/Client/SurveyClient.php
./common/Providers/UserServiceProvider.php
./common/Facades/User.php
./common/Services/User/User.php
./config/providers.php


composer dump-autoload --optimize改动的:
./vendor/autoload.php  ==》return ComposerAutoloaderInit7d1969d6b0c0a5e119f2b7e0932178e2::getLoader();
./vendor/composer/autoload_psr4.php
./vendor/composer/autoload_static.php
./vendor/composer/autoload_classmap.php
./vendor/composer/autoload_files.php
./vendor/composer/ClassLoader.php
./vendor/composer/autoload_namespaces.php
./vendor/composer/autoload_real.php

访问URL: http://47.93.207.136/activity/survey
最后,这个Provider的类如何使用参考,但写得不是很明白,最新版本的和实际使用并不定一模一样的:http://www.cnblogs.com/cxscode/p/7569856.html



路由:https://lumen.laravel.com/docs/5.4
中文文档:http://laravelacademy.org/laravel-docs-5_4
5.4这个路由,老外写得很简单,这帮人可能是想你去看他的代码吧,有很多人在问:
http://www.thinksaas.cn/ask/question/22000/
class KafkaServiceProvider extends ServiceProvider{
return new \Common\Service\Kafka\Kafka(); #lumen-clear-edition/common/Service/Kafka/Kafka.php
lumen-clear-edition/common/Service/Kafka/Kafka.php 里:




做微服务:/usr/local/nginx/conf/vhosts/ms.conf

server_name  10.70.**.142;
root /data/www/ms/;
rewrite ^/(survey)/.*$ /$1/public/index.php last;
http://10.70.33.140/survey/public/index.php
/data/www/ms/survey/public/index.php
路由:
/data/www/ms/survey/routes/web.php

一)$app->group(['prefix' => 'private','namespace'=>'Api\V1'], function () use ($app) {
    $app->get('survey/list', ['uses' => 'SurveyController@list']);
http://47.93.207.136/private/survey/list
app/Http/Controllers/Api/V1/SurveyController.php

二)$app->group(['namespace'=>'Api\V1'], function () use ($app) {
    $app->get('activity/survey', ['uses' => 'ActivityController@survey']);
http://47.93.207.136/activity/survey
app/Http/Controllers/Api/V1/ActivityController.php 里有一行:
$client = new SurveyClient();
./app/Helpers/Client/SurveyClient.php:class SurveyClient{

Lumen (5.5.2) (Laravel Components 5.5.*),路由的写法有点不一样:
$router->group(['prefix' => 'private','namespace'=>'Api\V1'], function () use ($router) {
        $router->get('survey/list', ['uses' => 'SurveyController@list']);

$router->group(['namespace'=>'Api\V1'], function () use ($router) {
        $router->get('activity/survey', ['uses' => 'ActivityController@survey']);


调用层级及配置文件的一个情况,二是如何引入框架目录的入口:
./app/Http/Controllers/Api/V1/SurveyController.php:class SurveyController extends Controller{
/**
* 删除互动
*/
public function delete(Request $request){
  $iid = intval($request->input('iid'));
  $res = Survey::deleteSurvey($iid);#调用Models
  return $this->out($res?1:0,$res?"success":"failed");
}

调用Models位置:
./app/Models/Survey.php:        public static function deleteSurvey($iid){

配置文件:
/data/www/ms/survey/config_production/database.php
/data/www/ms/survey/config_production/kafka.php
/data/www/ms/survey/config_production/redis.php

vi /data/htdocs/lumen.levoo.com/bootstrap/app.php   #引入框架目录



======================================================================================
Lumen 中可以使用的 Facades,查看源代码,可用清单如下(https://segmentfault.com/a/1190000002902055):
/survey/bootstrap/app.php:$app->withFacades();  $app->withFacades();
./lumen-clear-edition/vendor/laravel/lumen-framework/src/Application.php:    public function withFacades($aliases = true, $userAliases = [])
./vendor/laravel/lumen-framework/src/Application.php
public function withAliases($userAliases = [])
if (! static::$aliasesRegistered) {
  static::$aliasesRegistered = true;

  $merged = array_merge($defaults, $userAliases);

  foreach ($merged as $original => $alias) {
    class_alias($original, $alias);
  }
}


==========================================================================================
/usr/local/composer/composer.phar  global require "laravel/lumen-installer"
https://lumen.laravel.com/docs/5.4#server-requirements 下面的:
chmod a+x /root/.config/composer/vendor/laravel/lumen-installer/lumen
/root/.config/composer/vendor/bin/lumen new lumen.levoo.com

/data/htdocs/lumen.levoo.com/blog/routes/web.php

你可以将所有路由都定义在routes/web.php中。最基本的 Lumen 路由接收:
http://laravelacademy.org/post/6337.html



$app->group(['prefix'=>'test'],function($app){
    $app->get("/index",["uses" => "TestController@index"]);
                                                                                                                                                                                                              
});


【lumen】基础点记录使用:blog.csdn.net/imdingding/article/details/48679359
app/Http/routes.php中进行路由配置可以使用如下路由组的形式,在路由上lumen和laravel有一些区别
$app->group(['prefix' => 'scrollnews','namespace' => 'App\Http\Controllers'],function($app) {
$app->get('/','NewsController@showall');
$app->get('/{time}_{newpage}.htm','NewsController@showtime');
$app->get('/{newpage}.htm', 'NewsController@show');

});


http://123.57.252.183/test/index
hello Lumen (5.4.5) (Laravel Components 5.4.*)
/data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;

use App\user;   //新增部分
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        echo "hello Lumen (5.4.5) (Laravel Components 5.4.*)。";die;                                                                                                                                          
        return User::all();
    }
}


以上实践来源及变通参看了:http://blog.5ibc.net/p/87952.html

PHP message: PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/data/htdocs/lumen.levoo.com/storage/logs/lumen.log" could not be opened: failed to open stream: Permission denied in /data/htdocs/lumen.levoo.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107
mkdir
chmod -R 755 /data/htdocs/lumen.levoo.com/storage
chown -R www /data/htdocs/lumen.levoo.com/storage


Controller类的写法:https://segmentfault.com/q/1010000002727820
/data/htdocs/lumen.levoo.com/blog/app/Http/Controllers/AccountController.php



关于数据库配置文件:
默认情况下, Lumen 使用单一的 .env 文件来配置你的应用, 然而, 你也可以使用 Laravel 风格 的配置方法.
/data/htdocs/lumen.levoo.com/vendor/laravel/lumen-framework/config/database.php
文件夹下对应的配置文件复制到根目录下的 config 文件里面就行.
https://lumen.laravel-china.org/docs/5.3/configuration#configuration-files

Redis:
CACHE_DRIVER=file
SESSION_DRIVER=redis
QUEUE_DRIVER=sync

REDIS_HOST=192.168.1.248
REDIS_PASSWORD=null
REDIS_PORT=6379



今天在部署服务器的时候,使用composer来安装依赖。遇到了如下情况,这块出错好像和Redis配置有关,得在.env里配置好并运行起来。
  The Process class relies on proc_open, which is not available on your PHP installation.
  [ErrorException]                                          
  proc_get_status() has been disabled for security reasons
  开始的时候,我有些不知所措,于是冷静下来思考一番,然后goolge了一下
解决方法:
  在php.ini中,找到disable_functions选项,看看后面是否有proc_open函数被禁用了,如果有的话,去掉即可
  其实如果php的文档熟悉的话,你应该马上就能知道proc_open实际上是一个函数,是php用来和shell交互的函数,一般这种可以直接作用于操作系统的函数是非常不安全的,对于这种不安全的函数,总是要做一些措施来进行保护

php artisan make:migration create_table_cars --create=cars
php artisan make:migration create_table_cars --create=cars
Created Migration: 2017_03_04_160644_create_table_cars
/data/htdocs/lumen.levoo.com/database/migrations/2017_03_04_160644_create_table_cars.php

    public function up()
    {
        Schema::create('cars', function (Blueprint $table) {
            $table->increments('id');
            $table->string('make');                                                                                                                                  
            $table->string('model');
            $table->string('year');
            $table->timestamps();
        });
    }



php artisan migrate
Migrated: 2017_03_04_161708_create_table_cars

migrations记录历史 /car 两个表:
id int(10) UNSIGNED
make  varchar(255)
model varchar(255)
year varchar(255)
create d_attimestamp


问题实践来源:http://www.cnblogs.com/crisenchou/p/6237781.html
打开方法来自:http://www.codesec.net/view/497671.html?winzoom=1



Model这块和Controll层的配置:
1)Controll层, /data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;
use App\Models\Information;
use App\Models\Collection;

//use App\User;     //新增部分APP目录下
use App\Models\User; //App\Models\User目录下
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        /*
            $UserModel = new User();
            $result = $User::all(); //这样也成
            $result2 = $UserModel::all2(); //这样也成
        */
        $result = User::all();
        $result2 = User::all2();//这个在Model自定义的all2也能被调用输出结果

        print_r($result);
        echo "<hr>";                                                                                                                                                                                          
        print_r($result2);
    }
}


2)Model层:/data/htdocs/lumen.levoo.com/app/Models/User.php

<?php
//namespace App; //这个得注释掉,容易和App/User.php发生错误引用。
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
//默认操作数据库的users表,需要定制的话请看文档,下面有自己的配置。
class User extends Model
{
    /**
    * The connection name for the model.
    *
    * @var string
    */
    protected $connection = 'mysql';

    /**
    * 表名
    *
    * @var string
    */
    protected $table = 'levoo_sns_user'; //指定操作表名
    protected $primaryKey = "id";        //指定主键
    public $timestamps = false;
    protected $dateFormat = 'U';

    static public function all2(){
        $User = User::all();
        return $User;                                                                                                                                                                                          
    }
}


=================MVC模板学习=============================
/data/htdocs/lumen.levoo.com/app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;
use App\Models\Information;
use App\Models\Collection;

//use App\User;     //新增部分APP目录下
use App\Models\User; //App\Models\User目录下
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;

class TestController extends BaseController
{
    //直接传人sql方式操作数据库
    function index(Request $request){
        /*
            $UserModel = new User();
            $result = $User::all(); //这样也成
            $result2 = $UserModel::all2(); //这样也成
        */
        $result = User::all();
        //$result2 = User::all2();//这个在Model自定义的all2也能被调用输出结果
        /*
        print_r($result);                                                                                                                                            
        echo "<hr>";
        print_r($result2);
        */
        //view()->exists('user');
        return view('test', ['name' => 'jackX','results' => $result]);
    }
}


vi /data/htdocs/lumen.levoo.com/resources/views/test.blade.php


<!-- 该视图存放 resources/views/greeting.php -->

<html>
    <body>
        <h1>Hello, {{ $name }}</h1>
        <h1>Hello, {{ $name2 or 'Default' }}</h1>
        <h1>Hello, {!! $name !!}</h1>
        <h1>Array, {{ $results}}</h1>
        <h1>Array, {!! $results !!}</h1>
        Blade for each:<br>
        <h1>
            @foreach ($results as $user)
                <ul>
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
            @endforeach
        </h1>
        <h1>
            @foreach ($results as $user)
                <ul>
                @if ($user->id == 1)
                   用户Id=1,标识一下:
                @endif
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
            @endforeach
        </h1>
        <h1>只显示id=1的区块:</h1>
        <h1>
            @foreach ($results as $user)
                <ul>
                 @continue($user->id == 2)
                <li>This is user {{ $user->id }}</li>
                <li>This is user {{ $user->mobile }}</li>
                <li>This is user {{ $user->fansmobile }}</li>
                <li>This is user {{ $user->followedTime }}</li>
                </ul>
                 @break($user->id == 1)
            @endforeach
        </h1>
    </body>
</html>




模板输出:http://123.57.252.183/test/index
Hello, jackX

Hello, Default

Hello, jackX

Array, [{"id":1,"mobile":"1881**65108","fansmobile":"18810322234","followedTime":1211212121},{"id":2,"mobile":"1881**65108","fansmobile":"18810322232","followedTime":121212}]

Array, [{"id":1,"mobile":"1881**65108","fansmobile":"18810322234","followedTime":1211212121},{"id":2,"mobile":"1881**65108","fansmobile":"18810322232","followedTime":121212}]

Blade for each:
This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121
This is user 2
This is user 1881**65108
This is user 18810322232
This is user 121212
用户Id=1,标识一下:
This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121
This is user 2
This is user 1881**65108
This is user 18810322232
This is user 121212
只显示id=1的区块:

This is user 1
This is user 1881**65108
This is user 18810322234
This is user 1211212121

这个叫Blade的模板引擎解析成PHP的,也就是相当于没有啥大的损耗,如果它的算法还算先进的前提下,位置在:
/data/htdocs/lumen.levoo.com/storage/framework/views/9e3b647aebb6a248d1ae42408e87c3fc7f5bc520.php
为什么这么说呢,如下,我在想为何要搞成这样,PHP裸写不也一样么,像Ci框架啥的,思考思考,这样也算是能模板和程序分离罢:


        <h1>只显示id=1的区块:</h1>
        <h1>
            <?php $__currentLoopData = $results; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <ul>
                 <?php if($user->id == 2) continue; ?>
                <li>This is user <?php echo e($user->id); ?></li>
                <li>This is user <?php echo e($user->mobile); ?></li>
                <li>This is user <?php echo e($user->fansmobile); ?></li>
                <li>This is user <?php echo e($user->followedTime); ?></li>
                </ul>
                 <?php if($user->id == 1) break; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </h1>



主要是对这个模板有一个大体理解,和Smarty啥的有一个初步了解,参考自:
http://laravelacademy.org/post/6780.html




======================================================================
Nginx配置文件:

server
{
    listen       80 default_server;
    server_name  101.200.189.210 lumen.levoo.com;
    index index.html index.htm index.php;
    root  /data/htdocs/lumen.levoo.com/blog/public;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;


    location ~ .*\.(php|php5)?$
    {
        fastcgi_pass unix:/dev/shm/php-fcgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        #if (!-f $request_filename){                                                                                                  
        #    rewrite ^/(.+)$ /index.php?s=$1 last;
        #    break;
        #}
    }
    access_log /data/logs/nginx/access_lumen_levoo.log;
}



上面location / {里被注释掉的也成,只是优雅度不够,这块好像手册有说明,我当时把 try_files $uri $uri/ /index.php?$query_string;放到location ~ .*\.(php|php5)?$ 里了,发现不对。

http://123.57.252.183/foo
Hello World


老外:
http://stackoverflow.com/questions/32281294/lumen-simple-route-request-doesnt-work
老外也有这个问题:
http://laravel.io/forum/05-08-2014-nginx-laravel-routing-shows-404?page=1

主从数据库配置(多台读库配置):
http://blog.sina.com.cn/s/blog_9bbafb790102win1.html
基于Lumen搭建一个OAUTH2认证的API框架:
http://www.bibihub.com/php/lumen-mobile-api-oauth-2-authentication/

========DB学习=========
基本使用
注意:如果你想要使用DB门面,应该取消bootstrap/app.php文件中$app->withFacades()调用前的注释
vi bootstrap/app.php

下面这个需要门面:

$app->get('/foo', function () use ($app) {
    $results = app('db')->select("SELECT * FROM levoo_sns_user");
    print_r($results);
    $results = DB::select("SELECT * FROM levoo_sns_user");//这个需要门面
    print_r($results);
    return 'Hello World';                                          
});

一些报错的日志:SQLSTATE[HY000] [2002] Connection refused
grep: ./survey/config_production/config_production: Too many levels of symbolic links
./survey/config_production/app.php:    'lumen_log_path'=>'/data/logs/lumen/survey.log',  //框架日志
grep: ./survey/config/config_production: Too many levels of symbolic links
./survey/config/app.php:    'lumen_log_path'=>'/data/logs/lumen/survey.log',  //框架日志
tail -f survey.log
Next Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Connection refused (SQL: select count(*) as aggregate from `survey` where `type` = 0 and `user` = 271 and `state` = 0) in /data/www/ms/lumen-clear-edition/vendor/illuminate/database/Connection.php:664
图解证明:当地看北极星仰角,就是当地纬度;两者
图解证明:当地看北极星仰角,就是当地纬度;两者互为充分必要条件! 第一种情况:当地在北极点上

第二种情况:当地位于赤道上

http://wapwenku.baidu.com/view/fb2d8e52f46527d3240ce0ec.html?ssid=0&from=844b&uid=0&pu=sz@1320_2001#3
分页: 33/339 第一页 上页 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 下页 最后页 [ 显示模式: 摘要 | 列表 ]