分类目录归档:LINUX

CentOS7安装Docker

系统为CentOS7,内核版本要求3.10以上
 1、安装需要的软件包,yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
 sudo yum install yum-utils device-mapper-persistent-data lvm2
 2、设置yum源
 --国内使用阿里云的源
 sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 --国外使用官方的源
 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
 3、可以查看所有仓库中所有docker版本,并选择特定版本安装
 yum list docker-ce --showduplicates | sort -r
 4、安装docker(默认安装稳定版)
 sudo yum install docker-ce
 5、启动并加入开机启动
 systemctl enable docker
 systemctl start docker
 6、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
 docker version

CentOS7编译rocketmq-client-cpp

一、安装依赖包
yum update
yum install git
yum install make gcc gcc-c++ automake libtool cmake bzip2 bzip2-devel zlib zlib-devel

二、编译rocketmq-client-cpp客户端
cd /opt
mkdir rocketmq-client
git clone https://github.com/apache/rocketmq-client-cpp.git
cd rocketmq-client-cpp
sh build.sh

Linux curl命令

一、GET请求
curl https://www.baidu.com/s?wd=Content-Type
curl www.baidu.com/s?wd=Content-Type

加http和不加http效果一样

二、POST请求
curl http://192.168.1.179:8501/posp/6c7c96072f0d4dd7a0d6d236ee50ac4c/orderQuery -X POST -H “Content-Type:application/json;charset:utf-8;” -d “1111111111”

参数说明:
-X:指定请求的方法
-H:指定请求头(如果有多个请求头就加多个-H)
-d:指定请求的数据
-i:显示http响应的头信息
-g:关闭url通配符功能,使用特殊符号{}和[]
-v:显示数据传输过程中的详细信息

Linux pmap命令

pmap命令用于查看进程的内存映像信息,查看进程加载了哪些模块。


Usage:
 pmap [options] PID [PID ...]

Options:
 -x, --extended              show details
 -X                          show even more details
            WARNING: format changes according to /proc/PID/smaps
 -XX                         show everything the kernel provides
 -c, --read-rc               read the default rc
 -C, --read-rc-from=   read the rc from file
 -n, --create-rc             create new default rc
 -N, --create-rc-to=   create new rc to file
            NOTE: pid arguments are not allowed with -n, -N
 -d, --device                show the device format
 -q, --quiet                 do not display header and footer
 -p, --show-path             show path in the mapping
 -A, --range=[,]  limit results to the given range

 -h, --help     display this help and exit
 -V, --version  output version information and exit



字段说明:
Address : start address ofmap 映像起始地址
Kbytes : size of map in kilobytes 映像大小
RSS : resident set size inkilobytes 驻留集大小
Dirty : dirty pages (both sharedand private) in kilobytes 脏页大小
Mode : permissions on map 映像权限: r=read,w=write, x=execute, s=shared, p=private (copy on write)
Mapping : file backing the map ,or ‘[ anon ]’ for allocated memory, or ‘[ stack ]’ for the program stack. 映像支持文件,[anon]为已分配内存[stack]为程序堆栈

CentOS7 yum 安装LAMP

最近把vps系统重新安装了一下,更换了系统模版为CentOS7。命令和CentOS6有所不同。

1、更新系统

yum makecache fast
yum update

2、安装apache

yum install httpd

3、安装数据库mariadb

yum install mariadb mariadb-server mariadb-devel

4、安装php和常用库

php php-devel php-common php-cli php-mbstring php-gd php-bcmath php-pdo php-pear php-xml php-xmlrpc php-mysqlnd

5、启动httpd、mysqld

systemctl start httpd.service
systemctl start mariadb.service

6、设置开机自启动服务

systemctl enable httpd.service
systemctl enable mariadb.service

7、配置apache

vim /etc/httpd/conf/httpd.conf

1)添加php支持
找到:

DirectoryIndex index.html

改为:

DirectoryIndex index.html index.php

找到:

AddType application/x-gzip .gz .tgz

在其下面加上以下内容:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

2)添加伪静态

<Directory "/home/live-in.org">
    AllowOverride All
    # Allow open access:
    Require all granted
</Directory>


3)在文件末尾添加虚拟主机配置

<VirtualHost *:80>
DocumentRoot "/home/live-in.org"
ServerName www.live-in.org
ErrorLog logs/live-in.org-error_log
CustomLog logs/live-in.org-access_log common
DeflateCompressionLevel 5
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/x-javascript
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName xxx.xxx.xxx.xxx
</VirtualHost>


PS:xxx.xxx.xxx.xxx填服务器IP

4)调整prefork进程数

<IfModule mpm_prefork_module>
    StartServers          2
    MinSpareServers       2
    MaxSpareServers       3
    MaxClients            4
    MaxRequestsPerChild  500
</IfModule>

Linux lsof命令

lsof命令是一个列出当前系统打开文件的工具,常用于从端口反查打开这个端口的应用程序。

在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口。

1、查找端口

[root@channel ~]# netstat -an | grep 22654
tcp        0      0 ::ffff:192.168.23.34:22654  ::ffff:192.168.23.33:61616  ESTABLISHED


2、通过端口查找进程号

[root@channel ~]# lsof -i:22654
COMMAND  PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    4345 root 1552u  IPv6 1467801      0t0  TCP channel.web.ips.local:22654->192.168.23.33:61616 (ESTABLISHED)


3、通过进程号查找应用程序

[root@channel ~]# ps -ef | grep 4345
root      2348  2283  0 14:31 pts/0    00:00:00 grep 4345
root      4345  4295  3 Dec07 pts/1    09:54:10 /opt/jrockit-jdk1.6.0_33/bin/java -jrockit -Xms2560m -Xmx2560m -Dweblogic.Name=pbcs -Djava.security.policy=/bea/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Dweblogic.security.SSL.trustedCAKeyStore=/bea/Oracle/Middleware/wlserver_10.3/server/lib/cacerts -da -Dplatform.home=/bea/Oracle/Middleware/wlserver_10.3 -Dwls.home=/bea/Oracle/Middleware/wlserver_10.3/server -Dweblogic.home=/bea/Oracle/Middleware/wlserver_10.3/server -Dweblogic.management.discover=false -Dweblogic.management.server=http://192.168.23.34:9003 -Dwlw.iterativeDev=false -Dwlw.testConsole=false -Dwlw.logErrorsToConsole=false -Dweblogic.ext.dirs=/bea/Oracle/Middleware/patch_wls1033/profiles/default/sysext_manifest_classpath:/bea/Oracle/Middleware/patch_ocp353/profiles/default/sysext_manifest_classpath -Dweblogic.configuration.schemaValidationEnabled=false weblogic.Server

4、通过ll /proc/PID 命令查看进程所在的目录位置

CentOS7 systemctl命令初探

CentOS7 systemctl命令初探

CentOS7在系统结构上和CentOS5、6有了很大的区别,它用systemd代替了init作为用户的初始进程。systemctl命令是CentOS7下的管理命令。

1、用户启动进程类别
Linux系统主要有以下几种主流选择:
(1)以Ubuntu为代表的Linux发行版采用upstart。
(2)以7.0版本之前的CentOS为代表的System V init。
(3)CentOS7.0版本的systemd。
继续阅读CentOS7 systemctl命令初探

CentOS7修改ssh端口

CentOS7修改ssh端口

1、安装工具包

yum install -y policycoreutils-python

2、关闭SELinux

[root@server201 ~]# sestatus -v
SELinux status:                 enabled


修改配置:

vim /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled
重启机器生效。

3、修改ssh端口

vim /etc/ssh/sshd_config

将Port 22 改为一个大于1000的端口,比如12333。

4、修改防火墙策略
1)添加端口

[root@server201 ~]# firewall-cmd --zone=public --add-port=12333/tcp --permanent
success

2)重新加载配置

[root@server201 ~]# firewall-cmd --reload
success

3)查看端口是否被打开

[root@server201 ~]# firewall-cmd --permanent --query-port=12333/tcp
yes

5、重启SSH服务和防火墙

systemctl restart sshd.service
systemctl restart firewalld.service

参考资料:
http://blog.csdn.net/ausboyue/article/details/53691953
http://blog.csdn.net/u012486840/article/details/53161574

Linux进程后台运行方法

当用户注销(logout)或者网络断开时,登录的终端会收到HUP(hangup)信号从而关闭其所有子进程。我们可以使用3个命令来实现进程后台运行。

1、nohup
nohup的用途就是让提交的命令忽略hangup信号。

举例:

nohup ./startup.sh &

后台运行tomcat

2、setsid
setsid的作用是让运行的进程不属于接受HUP信号的终端的子进程。

举例:
比如bash登录上来ppid是10627

UID        PID  PPID  C STIME TTY          TIME CMD
root       521     1  0 May21 ?        00:00:01 /usr/sbin/sshd
root     10625   521  0 00:56 ?        00:00:00 sshd: root@pts/0 
root     10627 10625  0 00:56 pts/0    00:00:00 -bash


这时ping一个网址

ping www.google.com

在另一个窗口查看

ps -ef | grep ping

UID        PID  PPID  C STIME TTY          TIME CMD
root     10664 10627  0 00:57 pts/0    00:00:00 ping www.google.com


用setsid后PPID变为1(init进程ID),不会接受HUP信号

setsid ping www.google.com
ps -ef | grep ping

UID        PID  PPID  C STIME TTY          TIME CMD
root     10668     1  0 00:58 ?        00:00:00 ping www.google.com


3、screen
screen可以在后台创建会话,从而让进程在后台运行。

screen常用命令:
screen:开一个窗口
screen -r:恢复进入窗口
screen -r -D:强行进入窗口
在screen窗口内:Ctrl + A D 窗口后台运行
screen -ls:查看全部session列表
screen -d -r:连接一个screen进程,如果该进程是attached,就先踢掉远端用户再连接。
screen -D -r:连接一个screen进程,如果该进程是attached,就先踢掉远端用户并让他logout再连接