基础命令

/etc/init.d/sendmail start                   # 启动服务
/etc/init.d/sendmail stop                    # 关闭服务
/etc/init.d/sendmail status                  # 查看服务当前状态
/date/mysql/bin/mysqld_safe --user=mysql &   # 启动mysql后台运行
/bin/systemctl restart  mysqld.service       # centos7启动服务
vi /etc/rc.d/rc.local                        # 开机启动执行  可用于开机启动脚本
/etc/rc.d/rc3.d/S55sshd                      # 开机启动和关机关闭服务连接    # S开机start  K关机stop  55级别 后跟服务名
ln -s -f /date/httpd/bin/apachectl /etc/rc.d/rc3.d/S15httpd   # 将启动程序脚本连接到开机启动目录
ipvsadm -ln                                  # lvs查看后端负载机并发
ipvsadm -C                                   # lvs清除规则
xm list                                      # 查看xen虚拟主机列表
virsh                                        # 虚拟化(xen\kvm)管理工具  yum groupinstall Virtual*
./bin/httpd -M                               # 查看httpd加载模块
httpd -t -D DUMP_MODULES                     # rpm包httpd查看加载模块
echo 内容| /bin/mail -s "标题" 收件箱 -f 发件人       # 发送邮件
"`echo "内容"|iconv -f utf8 -t gbk`" | /bin/mail -s "`echo "标题"|iconv -f utf8 -t gbk`" 收件箱     # 解决邮件乱码
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg   # 检测nagios配置文件

chkconfig

chkconfig service on|off|set             # 设置非独立服务启状态
chkconfig --level 35   httpd   off       # 让服务不自动启动
chkconfig --level 35   httpd   on        # 让服务自动启动 35指的是运行级别
chkconfig --list                         # 查看所有服务的启动状态
chkconfig --list |grep httpd             # 查看某个服务的启动状态
chkconfig –-list [service]               # 查看服务的状态

systemctl

systemctl is-active *.service      # 查看服务是否运行
systemctl is-enabled *.service     # 查询服务是否开机启动
systemctl mask *.service           # 注销指定服务
systemctl unmask cups.service      # 取消注销cups服务
systemctl enable *.service         # 开机运行服务
systemctl disable *.service        # 取消开机运行
systemctl start *.service          # 启动服务
systemctl stop *.service           # 停止服务
systemctl restart *.service        # 重启服务
systemctl reload *.service         # 重新加载服务配置文件
systemctl status *.service         # 查询服务运行状态
systemctl --failed                 # 显示启动失败的服务
systemctl poweroff                 # 系统关机
systemctl reboot                   # 重新启动
systemctl rescue                   # 强制进入救援模式
systemctl emergency                # 强制进入紧急救援模式
systemctl list-dependencies        # 查看当前运行级别target(mult-user)启动了哪些服务
systemctl list-unit-files          # 查看开机启动的状态
journalctl -r -u elasticsearch.service  # 查看日志 r倒序 u服务名
/etc/systemd/system/falcon-agent.service
[Unit]
Description=This is zuiyou monitor agent
After=network.target remote-fs.target nss-lookup.target

[Service]
User= root
Type=simple
PIDFile=/opt/falcon-agent/var/app.pid
ExecStartPre=/usr/bin/rm -f /opt/falcon-agent/var/app.pid
ExecStart=/opt/falcon-agent/control start
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true
Restart=always
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

systemctl daemon-reload           # 加载配置

nginx

yum install -y make gcc  openssl-devel pcre-devel  bzip2-devel libxml2 libxml2-devel curl-devel libmcrypt-devel libjpeg libjpeg-devel libpng libpng-devel openssl

groupadd nginx
useradd nginx -g nginx -M -s /sbin/nologin

mkdir -p /opt/nginx-tmp

wget http://labs.frickle.com/files/ngx_cache_purge-1.6.tar.gz
tar fxz ngx_cache_purge-1.6.tar.gz
# ngx_cache_purge 清除指定url缓存
# 假设一个URLhttp://192.168.12.133/test.txt
# 通过访问      http://192.168.12.133/purge/test.txt  就可以清除该URL的缓存。

tar zxvpf nginx-1.4.4.tar.gz
cd nginx-1.4.4

# ./configure --help
# --with                 # 默认不加载 需指定编译此参数才使用
# --without              # 默认加载,可用此参数禁用
# --add-module=path      # 添加模块的路径
# --add-module=/opt/ngx_module_upstream_check \         # nginx 代理状态页面
# ngx_module_upstream_check  编译前需要打对应版本补丁 patch -p1 < /opt/nginx_upstream_check_module/check_1.2.6+.patch
# --add-module=/opt/ngx_module_memc \                   # 将请求页面数据存放在 memcached中
# --add-module=/opt/ngx_module_lua \                    # 支持lua脚本 yum install lua-devel lua

./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--add-module=/opt/ngx_cache_purge-1.6 \
--http-client-body-temp-path=/opt/nginx-tmp/client \
--http-proxy-temp-path=/opt/nginx-tmp/proxy \
--http-fastcgi-temp-path=/opt/nginx-tmp/fastcgi \
--http-uwsgi-temp-path=/opt/nginx-tmp/uwsgi \
--http-scgi-temp-path=/opt/nginx-tmp/scgi

make && make install

/usr/local/nginx/sbin/nginx –t             # 检查Nginx配置文件 但并不执行
/usr/local/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf  # 检查Nginx配置文件
/usr/local/nginx/sbin/nginx                # 启动nginx
/usr/local/nginx/sbin/nginx -s reload      # 重载配置
/usr/local/nginx/sbin/nginx -s stop        # 关闭nginx服务

elasticsearch

vim /etc/sysctl.conf
vm.max_map_count = 262144

vim /etc/security/limits.conf
* soft memlock unlimited
* hard memlock unlimited
sysctl -p

curl 'localhost:9200/_cat/health?v'                    # 健康检查
curl 'localhost:9200/_cat/nodes?v'                     # 获取集群的节点列表
curl 'localhost:9200/_cat/indices?v'                   # 列出所有索引
curl 127.0.0.1:9200/indexname -XDELETE                 # 删除索引
curl -XGET http://localhost:9200/_cat/shards           # 查看分片
curl '127.0.0.1:9200/_cat/indices'                     # 查分片同步  unassigned_shards  # 没同步完成

mysql常用命令

# mysql 可视化工具 MySQL Workbench

mysqlcheck -uroot -p -S mysql.sock --optimize --databases account       # 检查、修复、优化MyISAM表
mysqlbinlog slave-relay-bin.000001              # 查看二进制日志
mysqladmin -h myhost -u root -p create dbname   # 创建数据库

flush privileges;             # 刷新
show databases;               # 显示所有数据库
use dbname;                   # 打开数据库
show tables;                  # 显示选中数据库中所有的表
desc tables;                  # 查看表结构
drop database name;           # 删除数据库
drop table name;              # 删除表
create database name;         # 创建数据库
select column from table;     # 查询
show processlist;             # 查看mysql进程
show full processlist;        # 显示进程全的语句
select user();                # 查看所有用户
show slave status\G;          # 查看主从状态
show variables;               # 查看所有参数变量
show status;                  # 运行状态
show table status             # 查看表的引擎状态
show grants for user@'%'                                    # 查看用户权限
drop table if exists user                                   # 表存在就删除
create table if not exists user                             # 表不存在就创建
select host,user,password from user;                        # 查询用户权限 先use mysql
create table ka(ka_id varchar(6),qianshu int);              # 创建表
show variables like 'character_set_%';                      # 查看系统的字符集和排序方式的设定
show variables like '%timeout%';                            # 查看超时相关参数
delete from user where user='';                             # 删除空用户
delete from user where user='sss' and host='localhost' ;    # 删除用户
drop user 'sss'@'localhost';                                # 使用此方法删除用户更为靠谱
ALTER TABLE mytable ENGINE = MyISAM ;                       # 改变现有的表使用的存储引擎
SHOW TABLE STATUS from  dbname  where Name='tablename';     # 查询表引擎
mysql -uroot -p -A -ss -h10.10.10.5 -e "show databases;"    # shell中获取数据不带表格 -ss参数
CREATE TABLE innodb (id int, title char(20)) ENGINE = INNODB                     # 创建表指定存储引擎的类型(MyISAM或INNODB)
grant replication slave on *.* to 'user'@'%' identified by 'pwd';                # 创建主从复制用户
ALTER TABLE player ADD INDEX weekcredit_faction_index (weekcredit, faction);     # 添加索引
alter table name add column accountid(column)  int(