Repository: judasn/Linux-Tutorial
Branch: master
Commit: 80109268d5b7
Files: 184
Total size: 908.8 KB
Directory structure:
gitextract_cj_47536/
├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── SUMMARY.md
├── TOC.md
├── centos-settings/
│ ├── CentOS-Extra-Packages.md
│ ├── CentOS-Network-Settings.md
│ ├── Clear-Cache.md
│ ├── Clear-Tmp-Directory.md
│ ├── Close-XWindow.md
│ └── centos-settings-toc.md
├── config.json
├── favorite-file/
│ ├── Keepalived-Settings/
│ │ └── nginx_check.sh
│ ├── MySQL-Settings/
│ │ └── MySQL-5.6/
│ │ ├── 1G-Memory-Machine/
│ │ │ ├── my-for-comprehensive.cnf
│ │ │ ├── my-for-master.cnf
│ │ │ └── my-for-salve.cnf
│ │ ├── 8G-Memory-Machine/
│ │ │ └── my.cnf
│ │ └── developer/
│ │ └── my-Windows-8G-开发机.ini
│ ├── Nginx-Settings/
│ │ ├── nginx
│ │ └── nginx-front.conf
│ ├── Tomcat-Settings/
│ │ └── server.xml
│ ├── gravitee-docker-compose/
│ │ ├── README.md
│ │ ├── environments/
│ │ │ ├── ci/
│ │ │ │ └── docker-compose.yml
│ │ │ ├── demo/
│ │ │ │ ├── common.yml
│ │ │ │ ├── docker-compose-local.yml
│ │ │ │ ├── docker-compose-traefik-latest.yml
│ │ │ │ ├── docker-compose-traefik-nightly.yml
│ │ │ │ └── launch.sh
│ │ │ └── sample-apis/
│ │ │ └── docker-compose-sample-apis.yml
│ │ └── platform/
│ │ ├── docker-compose.yml
│ │ ├── mongo/
│ │ │ └── docker-entrypoint-initdb.d/
│ │ │ └── create-index.js
│ │ ├── nginx/
│ │ │ ├── nginx.conf
│ │ │ └── ssl/
│ │ │ ├── gio-selfsigned.crt
│ │ │ ├── gio-selfsigned.key
│ │ │ └── gio.pem
│ │ └── prometheus.yml
│ ├── redis/
│ │ └── redis
│ ├── shell/
│ │ ├── crontab-redis-restart.sh
│ │ ├── crontab-test.sh
│ │ ├── install_common_tool_CentOS.sh
│ │ ├── install_common_tool_ubuntu.sh
│ │ ├── install_common_vim.sh
│ │ ├── install_common_vim_zsh.sh
│ │ ├── install_docker_centos7.sh
│ │ ├── install_docker_disable_firewalld_centos7-aliyun.sh
│ │ ├── install_docker_disable_firewalld_centos7.sh
│ │ ├── install_docker_k8s_disable_firewalld_centos7-aliyun.sh
│ │ ├── install_jdk_offline_to_bash.sh
│ │ ├── install_jdk_offline_to_zsh.sh
│ │ ├── install_jdk_online.sh
│ │ ├── install_maven_offline_to_bash.sh
│ │ ├── install_maven_offline_to_zsh.sh
│ │ ├── install_mycat_offline.sh
│ │ ├── install_mysql5.6_offline_centos6.sh
│ │ ├── install_mysql5.6_offline_centos7.sh
│ │ ├── install_mysql5.7_offline_centos7.sh
│ │ ├── install_nginx_centos6.sh
│ │ ├── install_nginx_centos7.sh
│ │ ├── install_redis_centos6.sh
│ │ ├── install_redis_centos7.sh
│ │ ├── install_tomcat_centos6.sh
│ │ ├── install_tomcat_centos7.sh
│ │ ├── install_tomcat_offline_centos7.sh
│ │ ├── mysql_backup.sh
│ │ ├── repo_install_centos6.sh
│ │ ├── shell-for.sh
│ │ └── shell-with-param-demo.sh
│ └── zsh/
│ └── .zshrc
└── markdown-file/
├── Alfresco-Install-And-Usage.md
├── Ansible-Install-And-Settings.md
├── Bash-Other-Bash.md
├── Bash.md
├── CI-Install-And-Usage.md
├── CentOS-7-Install.md
├── CentOS-Install.md
├── CentOS-Virtual-Machine-Copy-Settings.md
├── CentOS.md
├── CentOS6-and-CentOS7.md
├── Confluence-Install-And-Settings.md
├── Crontab.md
├── Daemontools.md
├── Docker-Install-And-Usage.md
├── Dubbo-Install-And-Settings.md
├── ELK-Install-And-Settings.md
├── Elasticsearch-Base.md
├── FTP.md
├── FastDFS-Install-And-Settings.md
├── FastDFS-Nginx-Lua-GraphicsMagick.md
├── File-Extract-Compress.md
├── Flink-Install-And-Settings.md
├── Gitlab-Install-And-Settings.md
├── Glances-Install-And-Settings.md
├── GoAccess-Install-And-Settings.md
├── Grafana-Install-And-Settings.md
├── Hadoop-Install-And-Settings.md
├── Harbor-Install-And-Usage.md
├── Hsk-Install.md
├── Influxdb-Install-And-Settings.md
├── Iptables.md
├── JDK-Install.md
├── JMeter-Install-And-Settings.md
├── Java-bin.md
├── Jenkins-Install-And-Settings.md
├── Jira-Install-And-Settings.md
├── K8S-Install-And-Usage.md
├── Kafka-Install-And-Settings.md
├── Kibana-Base.md
├── Kubernetes-Install-And-Usage.md
├── LDAP-Install-And-Settings.md
├── Linux.md
├── Logstash-Base.md
├── Maven-Install-And-Settings.md
├── MongoDB-Install-And-Settings.md
├── Mycat-Install-And-Settings.md
├── Mysql-Install-And-Settings.md
├── Mysql-Optimize.md
├── Mysql-Test.md
├── Mysql-Tutorial.md
├── NFS.md
├── NTP.md
├── Nexus-Install-And-Settings.md
├── Nginx-Install-And-Settings.md
├── Nginx-Keepalived-Install-And-Settings.md
├── Nmon.md
├── Node-Install-And-Usage.md
├── Off-line-Yum-Install.md
├── Openfire-Install-And-Settings.md
├── PXC-Install-And-Settings.md
├── Portainer-Install-And-Settings.md
├── PostgreSQL-Install-And-Settings.md
├── Prometheus-Install-And-Settings.md
├── Python-Ubuntu.md
├── RabbitMQ-Install-And-Settings.md
├── Rap-Install-And-Settings.md
├── Redis-Install-And-Settings.md
├── SSH-login-without-password.md
├── SSH.md
├── SSR-Client-Ubuntu.md
├── SVN-Install-And-Settings.md
├── Samba.md
├── Sed.md
├── Shell.md
├── Showdoc-Install-And-Settings.md
├── SkyWalking-Install-And-Settings.md
├── Solr-Install-And-Settings.md
├── SonarQube-Install-And-Usage.md
├── Spark-Install-And-Settings.md
├── TeamCity-Install-And-Settings.md
├── Thrift-Install-And-Usage.md
├── Tmux-Install-And-Settings.md
├── Tomcat-Install-And-Settings.md
├── Ubuntu-Install-VMware.md
├── Ubuntu-Install.md
├── Ubuntu-Popular-Software.md
├── Ubuntu-Specific-Command.md
├── Ubuntu.md
├── VPN.md
├── Vim-Install-And-Settings.md
├── Was-Hacked.md
├── WordPress-Install-And-Settings.md
├── Wormhole-Install-And-Settings.md
├── YApi-Install-And-Settings.md
├── Zabbix-Install-And-Settings.md
├── Zookeeper-Install.md
├── Zsh.md
├── kali-linux-settings/
│ ├── kali-linux-basic-settings.md
│ ├── kali-linux-install.md
│ ├── kali-linux-penetration-test.md
│ ├── kali-linux-social-engineering.md
│ ├── kali-linux-sql-injection.md
│ └── kali-linux-toc.md
├── maintenance.md
├── monitor.md
├── other.md
├── shell-safe-rm.md
├── speedtest.md
├── ubuntu-settings/
│ ├── Network-Settings.md
│ ├── Ubuntu-Create-Desktop.md
│ ├── Ubuntu-Extra-Packages.md
│ ├── Ubuntu-Popular-Settings.md
│ ├── Ubuntu-UI.md
│ └── ubuntu-settings-toc.md
└── wrk-Install-And-Settings.md
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# http://editorconfig.org
# 官网首页有介绍:IntelliJ IDEA,VS Code 默认就支持,无需额外安装插件
root = true
# 空格替代Tab缩进在各种编辑工具下效果一致
[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 200
[*.java]
indent_style = tab
[*.{json,yml}]
indent_size = 2
[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
================================================
FILE: .gitignore
================================================
build/
out/
log/
logs/
public/
target/
node_modules/
classes/
.deploy*/
.gradle
*.log.*
*.log
.DS_Store
Thumbs.db
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
================================================
FILE: README.md
================================================
## 作者新方向,感谢支持
- [从开公司到开发全平台产品(文字版)](https://github.com/cdk8s/cdk8s-team-style/blob/master/full-stack/README.md)
- [从开公司到开发全平台产品(视频版)](https://space.bilibili.com/1765486559/channel/seriesdetail?sid=2359281)
## 初衷(Original Intention)
- 整理下自己所学。**但是比较随意,所以很多地方不够严谨,所以请带着批评的思维阅读。**
- 带动更多的人进入 Linux 世界,特别是做 Java 开发的人
- Github 项目地址,欢迎 `Fork`、`Star`:
- 文章中用到的一些安装包归纳整理:
- Gitbook 在线阅读地址:
- **学得越多越是明白一个人的力量是不够的,我只是起了一个引子,希望你能一起参与,真心希望!!!(鞠躬)**
## 优秀同行推荐
- [Linux工具快速教程](http://linuxtools-rst.readthedocs.io/zh_CN/latest/base/index.html)
## 目录(Contents)
- [Linux 介绍](markdown-file/Linux.md)
- [Ubuntu 介绍](markdown-file/Ubuntu.md)
- [Ubuntu 安装](markdown-file/Ubuntu-Install.md)
- [Ubuntu 设置(目录)](markdown-file/ubuntu-settings/ubuntu-settings-toc.md)
- [Kali Linux 介绍和设置(目录)](markdown-file/kali-linux-settings/kali-linux-toc.md)
- [CentOS 介绍](markdown-file/CentOS.md)
- [CentOS 6 安装](markdown-file/CentOS-Install.md)
- [CentOS 7 安装](markdown-file/CentOS-7-Install.md)
- [CentOS 6 和 CentOS 7 差异](markdown-file/CentOS6-and-CentOS7.md)
- [CentOS 设置(目录)](markdown-file/centos-settings/centos-settings-toc.md)
- [Ubuntu 安装 VMware](markdown-file/Ubuntu-Install-VMware.md)
- [VMware 克隆 CentOS 后网卡信息修改](markdown-file/CentOS-Virtual-Machine-Copy-Settings.md)
- [Vim 安装、配置、快捷键列表](markdown-file/Vim-Install-And-Settings.md)
- [SSH 免密登录](markdown-file/SSH-login-without-password.md)
- [Bash 命令](markdown-file/Bash.md)
- [Bash 其他常用命令](markdown-file/Bash-Other-Bash.md)
- [安装的 rm(删除)](markdown-file/shell-safe-rm.md)
- [Sed 命令](markdown-file/Sed.md)
- [Linux 下常用压缩文件的解压、压缩](markdown-file/File-Extract-Compress.md)
- [Yum 下载安装包及对应依赖包](markdown-file/Off-line-Yum-Install.md)
- [Zsh 入门](markdown-file/Zsh.md)
================================================
FILE: SUMMARY.md
================================================
# Java 程序员眼中的 Linux
* [Linux 介绍](markdown-file/Linux.md)
* [Ubuntu 介绍](markdown-file/Ubuntu.md)
* [Ubuntu 安装](markdown-file/Ubuntu-Install.md)
* [Ubuntu 设置(目录)](markdown-file/ubuntu-settings/ubuntu-settings-toc.md)
* [Kali Linux 介绍和设置(目录)](markdown-file/kali-linux-settings/kali-linux-toc.md)
* [CentOS 介绍](markdown-file/CentOS.md)
* [CentOS 6 安装](markdown-file/CentOS-Install.md)
* [CentOS 7 安装](markdown-file/CentOS-7-Install.md)
* [CentOS 6 和 CentOS 7 差异](markdown-file/CentOS6-and-CentOS7.md)
* [CentOS 设置(目录)](markdown-file/centos-settings/centos-settings-toc.md)
* [Ubuntu 安装 VMware](markdown-file/Ubuntu-Install-VMware.md)
* [VMware 克隆 CentOS 后网卡信息修改](markdown-file/CentOS-Virtual-Machine-Copy-Settings.md)
* [Vim 安装、配置、快捷键列表](markdown-file/Vim-Install-And-Settings.md)
* [SSH 免密登录](markdown-file/SSH-login-without-password.md)
* [Bash 命令](markdown-file/Bash.md)
* [Bash 其他常用命令](markdown-file/Bash-Other-Bash.md)
* [安装的 rm(删除)](markdown-file/shell-safe-rm.md)
* [Sed 命令](markdown-file/Sed.md)
* [Linux 下常用压缩文件的解压、压缩](markdown-file/File-Extract-Compress.md)
* [Yum 下载安装包及对应依赖包](markdown-file/Off-line-Yum-Install.md)
* [Zsh 入门](markdown-file/Zsh.md)
* [终端测速](markdown-file/speedtest.md)
* [日常维护](markdown-file/maintenance.md)
* [日常监控](markdown-file/monitor.md)
* [nmon 系统性能监控工具](markdown-file/Nmon.md)
* [Glances 安装和配置](markdown-file/Glances-Install-And-Settings.md)
* [SSH(Secure Shell)介绍](markdown-file/SSH.md)
* [FTP(File Transfer Protocol)介绍](markdown-file/FTP.md)
* [VPN(Virtual Private Network)介绍](markdown-file/VPN.md)
* [NFS(Network FileSystem)介绍](markdown-file/NFS.md)
* [NTP(Network Time Protocol)介绍](markdown-file/NTP.md)
* [Samba 介绍](markdown-file/Samba.md)
* [Crontab 介绍](markdown-file/Crontab.md)
* [Iptables 介绍](markdown-file/Iptables.md)
* [花生壳-安装介绍](markdown-file/Hsk-Install.md)
* [JDK 安装](markdown-file/JDK-Install.md)
* [Java bin 目录下的工具](markdown-file/Java-bin.md)
* [SVN 安装和配置](markdown-file/SVN-Install-And-Settings.md)
* [Tomcat 安装和配置、优化](markdown-file/Tomcat-Install-And-Settings.md)
* [Jenkins 安装和配置](markdown-file/Jenkins-Install-And-Settings.md)
* [Maven 安装和配置](markdown-file/Maven-Install-And-Settings.md)
* [Nexus 安装和配置](markdown-file/Nexus-Install-And-Settings.md)
* [PostgreSQL 安装和配置](markdown-file/PostgreSQL-Install-And-Settings.md)
* [MySQL 安装和配置](markdown-file/Mysql-Install-And-Settings.md)
* [MySQL 优化](markdown-file/Mysql-Optimize.md)
* [MySQL 测试](markdown-file/Mysql-Test.md)
* [MySQL 教程](markdown-file/Mysql-Tutorial.md)
* [Percona XtraDB Cluster(PXC)安装和配置](markdown-file/PXC-Install-And-Settings.md)
* [Redis 安装和配置](markdown-file/Redis-Install-And-Settings.md)
* [MongoDB 安装和配置](markdown-file/MongoDB-Install-And-Settings.md)
* [Solr 安装和配置](markdown-file/Solr-Install-And-Settings.md)
* [Jira 安装和配置](markdown-file/Jira-Install-And-Settings.md)
* [Confluence 安装和配置](markdown-file/Confluence-Install-And-Settings.md)
* [Jenkins 安装和配置](markdown-file/Jenkins-Install-And-Settings.md)
* [TeamCity 安装和配置](markdown-file/TeamCity-Install-And-Settings.md)
* [Nginx 安装和配置](markdown-file/Nginx-Install-And-Settings.md)
* [wrk 安装和配置](markdown-file/wrk-Install-And-Settings.md)
* [FastDFS 安装和配置](markdown-file/FastDFS-Install-And-Settings.md)
* [FastDFS 结合 GraphicsMagick](markdown-file/FastDFS-Nginx-Lua-GraphicsMagick.md)
* [RabbitMQ 安装和配置](markdown-file/RabbitMQ-Install-And-Settings.md)
* [Openfire 安装和配置](markdown-file/Openfire-Install-And-Settings.md)
* [Rap 安装和配置](markdown-file/Rap-Install-And-Settings.md)
* [Nginx + Keepalived 高可用](markdown-file/Nginx-Keepalived-Install-And-Settings.md)
* [黑客入侵检查](markdown-file/Was-Hacked.md)
* [Shadowsocks 安装和配置](markdown-file/http://code.youmeek.com/2016/08/19/2016/08/VPS/)
* [Mycat 安装和配置](markdown-file/Mycat-Install-And-Settings.md)
* [Zookeeper 安装和配置](markdown-file/Zookeeper-Install.md)
* [Daemontools 工具介绍](markdown-file/Daemontools.md)
* [Tmux 安装和配置](markdown-file/Tmux-Install-And-Settings.md)
* [ELK 日志收集系统安装和配置](markdown-file/ELK-Install-And-Settings.md)
* [Dubbo 安装和配置](markdown-file/Dubbo-Install-And-Settings.md)
* [GitLab 安装和配置](markdown-file/Gitlab-Install-And-Settings.md)
* [JMeter 安装和配置](markdown-file/JMeter-Install-And-Settings.md)
* [Docker 安装和使用](markdown-file/Docker-Install-And-Usage.md)
* [Harbor 安装和配置](markdown-file/Harbor-Install-And-Usage.md)
* [LDAP 安装和使用](markdown-file/LDAP-Install-And-Settings.md)
* [Alfresco 安装和使用](markdown-file/Alfresco-Install-And-Usage.md)
* [Apache Thrift 安装和使用](markdown-file/Thrift-Install-And-Usage.md)
* [Node.js 安装和使用](markdown-file/Node-Install-And-Usage.md)
* [CI 整套服务安装和使用](markdown-file/CI-Install-And-Usage.md)
* [YApi 安装和配置](markdown-file/YApi-Install-And-Settings.md)
* [Kafka 安装和配置](markdown-file/Kafka-Install-And-Settings.md)
* [Hadoop 安装和配置](markdown-file/Hadoop-Install-And-Settings.md)
* [Showdoc 安装和配置](markdown-file/Showdoc-Install-And-Settings.md)
* [WordPress 安装和配置](markdown-file/WordPress-Install-And-Settings.md)
* [GoAccess 安装和配置](markdown-file/GoAccess-Install-And-Settings.md)
* [Portainer 安装和配置](markdown-file/Portainer-Install-And-Settings.md)
* [Influxdb 安装和配置](markdown-file/Influxdb-Install-And-Settings.md)
* [Prometheus 安装和配置](markdown-file/Prometheus-Install-And-Settings.md)
* [Grafana 安装和配置](markdown-file/Grafana-Install-And-Settings.md)
* [Ansible 安装和配置](markdown-file/Ansible-Install-And-Settings.md)
* [Wormhole + Flink 安装和配置](markdown-file/Wormhole-Install-And-Settings.md)
* [SkyWalking 安装和配置](markdown-file/SkyWalking-Install-And-Settings.md)
================================================
FILE: TOC.md
================================================
- [Linux 介绍](markdown-file/Linux.md)
- [Ubuntu 介绍](markdown-file/Ubuntu.md)
- [Ubuntu 安装](markdown-file/Ubuntu-Install.md)
- [Ubuntu 设置(目录)](markdown-file/ubuntu-settings/ubuntu-settings-toc.md)
- [Kali Linux 介绍和设置(目录)](markdown-file/kali-linux-settings/kali-linux-toc.md)
- [CentOS 介绍](markdown-file/CentOS.md)
- [CentOS 6 安装](markdown-file/CentOS-Install.md)
- [CentOS 7 安装](markdown-file/CentOS-7-Install.md)
- [CentOS 6 和 CentOS 7 差异](markdown-file/CentOS6-and-CentOS7.md)
- [CentOS 设置(目录)](markdown-file/centos-settings/centos-settings-toc.md)
- [Ubuntu 安装 VMware](markdown-file/Ubuntu-Install-VMware.md)
- [VMware 克隆 CentOS 后网卡信息修改](markdown-file/CentOS-Virtual-Machine-Copy-Settings.md)
- [Vim 安装、配置、快捷键列表](markdown-file/Vim-Install-And-Settings.md)
- [SSH 免密登录](markdown-file/SSH-login-without-password.md)
- [Bash 命令](markdown-file/Bash.md)
- [Bash 其他常用命令](markdown-file/Bash-Other-Bash.md)
- [安装的 rm(删除)](markdown-file/shell-safe-rm.md)
- [Sed 命令](markdown-file/Sed.md)
- [Linux 下常用压缩文件的解压、压缩](markdown-file/File-Extract-Compress.md)
- [Yum 下载安装包及对应依赖包](markdown-file/Off-line-Yum-Install.md)
- [Zsh 入门](markdown-file/Zsh.md)
- [终端测速](markdown-file/speedtest.md)
- [日常维护](markdown-file/maintenance.md)
- [日常监控](markdown-file/monitor.md)
- [nmon 系统性能监控工具](markdown-file/Nmon.md)
- [Glances 安装和配置](markdown-file/Glances-Install-And-Settings.md)
- [SSH(Secure Shell)介绍](markdown-file/SSH.md)
- [FTP(File Transfer Protocol)介绍](markdown-file/FTP.md)
- [VPN(Virtual Private Network)介绍](markdown-file/VPN.md)
- [NFS(Network FileSystem)介绍](markdown-file/NFS.md)
- [NTP(Network Time Protocol)介绍](markdown-file/NTP.md)
- [Samba 介绍](markdown-file/Samba.md)
- [Crontab 介绍](markdown-file/Crontab.md)
- [Iptables 介绍](markdown-file/Iptables.md)
- [花生壳-安装介绍](markdown-file/Hsk-Install.md)
- [JDK 安装](markdown-file/JDK-Install.md)
- [Java bin 目录下的工具](markdown-file/Java-bin.md)
- [SVN 安装和配置](markdown-file/SVN-Install-And-Settings.md)
- [Tomcat 安装和配置、优化](markdown-file/Tomcat-Install-And-Settings.md)
- [Jenkins 安装和配置](markdown-file/Jenkins-Install-And-Settings.md)
- [Maven 安装和配置](markdown-file/Maven-Install-And-Settings.md)
- [Nexus 安装和配置](markdown-file/Nexus-Install-And-Settings.md)
- [PostgreSQL 安装和配置](markdown-file/PostgreSQL-Install-And-Settings.md)
- [MySQL 安装和配置](markdown-file/Mysql-Install-And-Settings.md)
- [MySQL 优化](markdown-file/Mysql-Optimize.md)
- [MySQL 测试](markdown-file/Mysql-Test.md)
- [MySQL 教程](markdown-file/Mysql-Tutorial.md)
- [Percona XtraDB Cluster(PXC)安装和配置](markdown-file/PXC-Install-And-Settings.md)
- [Redis 安装和配置](markdown-file/Redis-Install-And-Settings.md)
- [MongoDB 安装和配置](markdown-file/MongoDB-Install-And-Settings.md)
- [Solr 安装和配置](markdown-file/Solr-Install-And-Settings.md)
- [Jira 安装和配置](markdown-file/Jira-Install-And-Settings.md)
- [Confluence 安装和配置](markdown-file/Confluence-Install-And-Settings.md)
- [Jenkins 安装和配置](markdown-file/Jenkins-Install-And-Settings.md)
- [TeamCity 安装和配置](markdown-file/TeamCity-Install-And-Settings.md)
- [Nginx 安装和配置](markdown-file/Nginx-Install-And-Settings.md)
- [wrk 安装和配置](markdown-file/wrk-Install-And-Settings.md)
- [FastDFS 安装和配置](markdown-file/FastDFS-Install-And-Settings.md)
- [FastDFS 结合 GraphicsMagick](markdown-file/FastDFS-Nginx-Lua-GraphicsMagick.md)
- [RabbitMQ 安装和配置](markdown-file/RabbitMQ-Install-And-Settings.md)
- [Openfire 安装和配置](markdown-file/Openfire-Install-And-Settings.md)
- [Rap 安装和配置](markdown-file/Rap-Install-And-Settings.md)
- [Nginx + Keepalived 高可用](markdown-file/Nginx-Keepalived-Install-And-Settings.md)
- [黑客入侵检查](markdown-file/Was-Hacked.md)
- [Shadowsocks 安装和配置](markdown-file/http://code.youmeek.com/2016/08/19/2016/08/VPS/)
- [Mycat 安装和配置](markdown-file/Mycat-Install-And-Settings.md)
- [Zookeeper 安装和配置](markdown-file/Zookeeper-Install.md)
- [Daemontools 工具介绍](markdown-file/Daemontools.md)
- [Tmux 安装和配置](markdown-file/Tmux-Install-And-Settings.md)
- [ELK 日志收集系统安装和配置](markdown-file/ELK-Install-And-Settings.md)
- [Dubbo 安装和配置](markdown-file/Dubbo-Install-And-Settings.md)
- [GitLab 安装和配置](markdown-file/Gitlab-Install-And-Settings.md)
- [JMeter 安装和配置](markdown-file/JMeter-Install-And-Settings.md)
- [Docker 安装和使用](markdown-file/Docker-Install-And-Usage.md)
- [Harbor 安装和配置](markdown-file/Harbor-Install-And-Usage.md)
- [LDAP 安装和使用](markdown-file/LDAP-Install-And-Settings.md)
- [Alfresco 安装和使用](markdown-file/Alfresco-Install-And-Usage.md)
- [Apache Thrift 安装和使用](markdown-file/Thrift-Install-And-Usage.md)
- [Node.js 安装和使用](markdown-file/Node-Install-And-Usage.md)
- [YApi 安装和配置](markdown-file/YApi-Install-And-Settings.md)
- [Kafka 安装和配置](markdown-file/Kafka-Install-And-Settings.md)
- [Hadoop 安装和配置](markdown-file/Hadoop-Install-And-Settings.md)
- [Showdoc 安装和配置](markdown-file/Showdoc-Install-And-Settings.md)
- [WordPress 安装和配置](markdown-file/WordPress-Install-And-Settings.md)
- [GoAccess 安装和配置](markdown-file/GoAccess-Install-And-Settings.md)
- [Portainer 安装和配置](markdown-file/Portainer-Install-And-Settings.md)
- [Influxdb 安装和配置](markdown-file/Influxdb-Install-And-Settings.md)
- [Prometheus 安装和配置](markdown-file/Prometheus-Install-And-Settings.md)
- [Grafana 安装和配置](markdown-file/Grafana-Install-And-Settings.md)
- [Ansible 安装和配置](markdown-file/Ansible-Install-And-Settings.md)
- [Wormhole + Flink 安装和配置](markdown-file/Wormhole-Install-And-Settings.md)
- [SkyWalking 安装和配置](markdown-file/SkyWalking-Install-And-Settings.md)
================================================
FILE: centos-settings/CentOS-Extra-Packages.md
================================================
# CentOS 源设置
## 修改官方源
- 下面内容的一个简易集合版本脚本:
## 修改官方源
> 国内常用源配置方法(该源和官方源是一样的,只是因为服务器在国内会起到加速作用而已):
- 163 源:
- 阿里源:
- sohu:
> CentOS 6 替换过程(这里以 163 源为例):
- 备份官网源:`sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.20151219.backup`
- `cd /etc/yum.repos.d/`
- 下载对应版本 repo 文件, 放入 **/etc/yum.repos.d/**
- 下载源文件:
- CentOS6:`sudo wget http://mirrors.163.com/.help/CentOS6-Base-163.repo`
- `sudo mv CentOS6-Base-163.repo CentOS-Base.repo`
- 导入key:`rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6`
- `sudo yum clean all`
- `sudo yum makecache`
- `sudo yum update -y`
> CentOS 7 替换过程(这里以 163 源为例):
- 备份官网源:`sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.20170219.backup`
- `cd /etc/yum.repos.d/`
- 下载对应版本 repo 文件, 放入 **/etc/yum.repos.d/**
- 下载源文件:
- CentOS7:`sudo wget http://mirrors.163.com/.help/CentOS7-Base-163.repo`
- `sudo mv CentOS7-Base-163.repo CentOS-Base.repo`
- 导入key:`rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7`
- `sudo yum clean all`
- `sudo yum makecache`
- `sudo yum update -y`
## 第三方源
> 加入第三方源主要是为了 yum 下载到官方没有提供的软件,在其他社区、第三方源里面有很多的软件包,有些软件是很好用的。CentOS 可以加入多个源,所以就存在一个源的优先级问题了,设置优先级的可以使用 yum-plugin-priorities 工具。一般我是建议官方的优先级是最高的,然后才是第三方的。
- 安装 yum-plugin-priorities:
- CentOS 4 或 CentOS 6:`sudo yum install -y yum-plugin-priorities`
- CentOS 5:`sudo yum install -y yum-priorities`
- 安装完 yum-plugin-priorities 插件后,默认是开启的,如果要关闭可以这样设置:
- `sudo vim /etc/yum/pluginconf.d/priorities.conf`
- 把 enabled=1 改为 enabled=0 即可
- 设置默认源的优先级:
- 一般默认的源配置里面 [base], [updates], [extras],[centosplus] 的 priority=1, [contrib] 的 priority=2,其他第三的软件源为:priority=N (推荐 N > 10,N 可以为1到99的正整数,数值越小越优先)
- `sudo vim /etc/yum.repos.d/CentOS-Base.repo`
- 配置内容如下图
- 
- 安装 EPEL 源:
- 官网中文材料:
- 安装命令:`sudo yum install -y epel-release`
- CentOS 6 导入 KEY:`rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6`
- CentOS 7 导入 KEY:`rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7`
- 设置 EPEL 源的级别:`vim /etc/yum.repos.d/epel.repo`,追加:priority=11
- 卸载 EPEL 源
- 如果你暂时不想使用 EPEL 源的话,把 epel.repo 里的 enabled=1 改成 enabled=0 即可,如果你完全不需要了,那就直接卸载掉 `sudo rpm -e epel-release`
- 安装 RepoForge 源:(旧的名字为 rpmforge)
- 官网下载 RPM包:
- 我是 CentOS 6.7 64 位,所以下载 EL 6 x86_64,下载 RMP 安装文件大小:12.3 KB
- 下载命令:`wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm`(我这边 wget 不下来,需要开 VPN,所以你最好有这个心理准备)
- 安装 RPM 文件:`sudo rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm`
- 导入 KEY:`sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag`
- 设置 RepoForge 源的级别:`vim /etc/yum.repos.d/rpmforge.repo`,设置如下图
- 
- 更新包信息:
- `sudo yum clean all`
- `sudo yum makecache`
- `sudo yum update -y`
- 测试:
- 命令:`sudo yum check-update`
- 看到显示的结果中包括 rpmforge 和 epel 的列表表示成功。
- `sudo yum install -y htop`(htop 官方源是没有的,所以如果能下载下来就表示已经使用了第三方源)
### 禁用源
- 编辑:`vim /etc/yum.repos.d/elasticsearch.repo`
- 把 enabled=1 改为 enabled=0
```
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
> 资料:
-
-
-
-
-
-
================================================
FILE: centos-settings/CentOS-Network-Settings.md
================================================
# CentOS 网络设置
- 由于前面虚拟机中安装 CentOS 使用的是桥接模式,为了让虚拟机中的系统能上网,我们需要进行网络设置。
## CentOS 6
### 界面化下设置网络(新手推荐使用这种)
- 
- 选择上图箭头所示
- 
- 如上图标注 3 所示:选择 `手动` 模式
- 如上图标注 4 所示:填写自己局域网内的子网掩码、默认网关,以及你要分配的内网 IP 地址。这三个参数你可以参考你当前使用的主机信息,在 Windows 系统上使用:`cmd --- ipconfig`,查看你当前连接的网卡信息。如果你是无线网卡则读取对应的无线网卡信息,如果你是本地连接,则读取对应的本地连接信息。
- 如上图标注 5 所示:填写你当前地区合适的 DNS 地址,我这边地区使用 360 测试出来的结果显示 114 的适合我,所以我这里填写该值
### 命令行下设置网络
- 编辑网卡信息:
- 备份:`cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0-20160205Back`
- 把备份文件移动到其他目录:`mv /etc/sysconfig/network-scripts/ifcfg-eth0-20160205Back /opt/myBack`
- 编辑网卡文件:`vim /etc/sysconfig/network-scripts/ifcfg-eth0`
- 把网卡中信息改为下面对应内容:
```
DEVICE=eth0 (系统默认值)
TYPE=Ethernet (系统默认值)
UUID=a2c17f0c-a224-43d5-a203-48af1f0d9113 (系统默认值)
ONBOOT=yes (系统默认值是 no,我改为 yes)
NM_CONTROLLED=yes (系统默认值)
BOOTPROTO=none (系统默认值是 dhcp,我改为 none,代表手动)
USERCTL=no (自己补充的)
IPV6INIT=no (自己补充的)
NETMASK=255.255.255.0 (自己补充的)
IPADDR=192.168.0.110 (自己补充的)
GATEWAY=192.168.0.1 (自己补充的)
DNS1=114.114.114.114 (自己补充的)
PREFIX=24 (使用图形界面设置后生成的)
DEFROUTE=yes (使用图形界面设置后生成的)
IPV4_FAILURE_FATAL=yes (使用图形界面设置后生成的)
NAME="System eth0" (使用图形界面设置后生成的)
HWADDR=00:0C:29:A9:37:D4 (使用图形界面设置后生成的)
LAST_CONNECT=1454626679 (使用图形界面设置后生成的)
```
- 重启网络配置:`service network restart`
## CentOS 7.x
### 命令行下设置网络
- 查看系统下有哪些网卡:`ls /etc/sysconfig/network-scripts/`,新版本不叫 eth0 这类格式了,比如我当前这个叫做:ifcfg-ens33(你的肯定跟我不一样,但是格式类似)
- 先备份:`cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak`
- 编辑该文件:`vim /etc/sysconfig/network-scripts/ifcfg-ens33`,改为如下信息:(IP 段自己改为自己的网络情况)
``` ini
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.0.127
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DNS1=114.114.114.114
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=b9f01b7d-4ebf-4d3a-a4ec-ae203425bb11
DEVICE=ens33
ONBOOT=yes
```
- 修改后,重启网络服务:`systemctl restart network.service`
================================================
FILE: centos-settings/Clear-Cache.md
================================================
## 清除系统缓存
## 初衷
- 本身 Linux 有比较成熟的内存管理机制,但是不免也是会抽风的,有些程序在被 kill 掉之后系统内存依然没有大的变化,这时候就需要手动清除。
## 清除缓存
- 官网说明:
- 先查看目前系统内存使用情况:`free -m`
- 同步缓存数据到硬盘:`sync`
- 开始清理:`echo 3 > /proc/sys/vm/drop_caches`
- 0:不清除
- 1:清除页缓存
- 2:清除目录项缓存与文件结点缓存
- 3:清除所有缓存(常用)
- 再查看清除后效果:`free -m`
================================================
FILE: centos-settings/Clear-Tmp-Directory.md
================================================
## 修改定时清理 /tmp 目录下的文件
## 初衷
- 默认系统是超过 30 天不访问的文件自动清除的,但是有时候硬盘用得紧可以考虑修改周期
## 设置方法
- 编辑配置文件:`vim /etc/cron.daily/tmpwatch`
``` nginx
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
```
- 上面这句话:`/usr/sbin/tmpwatch "$flags" -f 30d "$d"`,其中 **30d** 表示 30 天表示要备删除的周期文件,该值最低为 1。
- 一般数据建议不要放在这个目录下,以免被系统误删
================================================
FILE: centos-settings/Close-XWindow.md
================================================
## CentOS 图形界面的关闭与开启
## 初衷
- 本地开多个虚拟机搞集群测试,为了节省资源,关掉图形界面更好点
## CentOS 6 设置方法
- 编辑配置文件:`vim /etc/inittab`
- 把默认值:`id:5:initdefault:`,改为:`id:3:initdefault:`
- 重启系统:`reboot`,重启后就只有 shell 界面了。
- 在 shell 界面中如果你还希望临时开启图形界面可以输入:`init 5`
- 在图形界面中如果你希望临时关闭图形界面可以输入:`init 3`
## CentOS 7 设置方法 1
- 开机以命令模式启动,执行:
- systemctl set-default multi-user.target
- 开机以图形界面启动,执行:
- systemctl set-default graphical.target
## CentOS 7 设置方法 2
- 关闭图形
- `mv /etc/systemd/system/default.target /etc/systemd/system/default.target.bak` (改名备份)
- `ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target` (重新软连接文本界面为启动默认值界面)
- `systemctl reboot` (重启)
- 恢复图形界面
- `rm -rf /etc/systemd/system/default.target` (移除当前配置链接)
- `mv /etc/systemd/system/default.target.bak /etc/systemd/system/default.target` (恢复备份配置链接)
- `systemctl reboot`
================================================
FILE: centos-settings/centos-settings-toc.md
================================================
- [CentOS 网络设置](CentOS-Network-Settings.md)
- [CentOS 源设置](CentOS-Extra-Packages.md)
- [CentOS 图形界面的关闭与开启](Close-XWindow.md)
- [清除系统缓存](Clear-Cache.md)
- [修改定时清理 /tmp 目录下的文件](Clear-Tmp-Directory.md)
================================================
FILE: config.json
================================================
{
"name": "Java 程序员眼中的 Linux",
"introduction": "笔者从 Java 开发角度,全方位讲解各种环境搭建及常用工具详解,是一部适合程序员的百科全书。"
}
================================================
FILE: favorite-file/Keepalived-Settings/nginx_check.sh
================================================
#!/bin/bash
# 如果进程中没有nginx则将keepalived进程kill掉
A=`ps -C nginx --no-header |wc -l` ## 查看是否有 nginx进程 把值赋给变量A
if [ $A -eq 0 ];then ## 如果没有进程值得为 零
service keepalived stop ## 则结束 keepalived 进程
fi
================================================
FILE: favorite-file/MySQL-Settings/MySQL-5.6/1G-Memory-Machine/my-for-comprehensive.cnf
================================================
# 适用于 Mysql 5.6
# 该配置适合 1G 内存左右的机子,储存类型为 InnoDB
# 官网配置说明:http://dev.mysql.com/doc/refman/5.6/en/mysqld-option-tables.html
# 官网状态值说明:http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html
# 官网环境变量说明:http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html
# 在线生成配置工具:http://tools.percona.com(只是起到一个参考作用,生成的配置文件里面的参数名有的是用符号:-,而官网是用:_,所以这个也要注意改掉。)
# 资料参考:https://blog.linuxeye.com/379.html
# 注释内容为注释行下面的配置的解释
# 这是一个综合配置,不是单独为主库或是从库考虑
# 如果你需要主、从配置可以看:
# 主的配置可以看:https://github.com/judasn/Linux-Tutorial/blob/master/MySQL-Settings/MySQL-5.6/1G-Memory-Machine/my-for-master.cnf
# 从的配置可以看:https://github.com/judasn/Linux-Tutorial/blob/master/MySQL-Settings/MySQL-5.6/1G-Memory-Machine/my-for-salve.cnf
# ============================================================================================================
# 客户端设置
[mysql]
port = 3306
socket = /usr/program/mysql/data/mysql.sock
default-character-set = utf8
# ============================================================================================================
# 服务端设置
[mysqld]
user = mysql
port = 3306
default-storage-engine = InnoDB
socket = /usr/program/mysql/data/mysql.sock
pid-file = /usr/program/mysql/data/mysql.pid
collation-server = utf8_general_ci
init_connect = 'SET NAMES utf8'
character-set-server = utf8
basedir = /usr/program/mysql
datadir = /usr/program/mysql/data
log-error = /usr/program/mysql/data/mysql-error.log
# (重点修改)表示是本机的序号为1,一般配合设置主从的时候一定要修改的地方
server-id = 1
# back_log 值指出在 MySQL 暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。如果 MySQL 的连接数据达到 max_connections 时,新来的请求将会被存在堆栈中,以等待某一连接释放资源,该堆栈的数量即 back_log,如果等待连接的数量超过 back_log,将不被授予连接资源。
# 另外,这值(back_log)限于您的操作系统对到来的 TCP/IP 连接的侦听队列的大小。你的操作系统在这个队列大小上有它自己的限制(可以检查你的 OS 文档找出这个变量的最大值),试图设定 back_log 高于你的操作系统的限制将是无效的。
back_log = 512
# MySQL 的最大并发连接数
max_connections = 1000
# 网络传输中一次小心传输量的最大值(最大值为 1G);增加该变量的值十分安全,这是因为仅当需要时才会分配额外内存。例如,仅当你发出长查询或 MySQL 必须返回大的结果行时 MySQL 才会分配更多内存。该变量之所以取较小默认值是一种预防措施,以捕获客户端和服务器之间的错误信息包,并确保不会因偶然使用大的信息包而导致内存溢出。
max_allowed_packet = 16M
# (这个参数有疑问)对于同一主机,如果有超出该参数值个数的中断错误连接,则该主机将被禁止连接。如需对该主机进行解禁,执行 Mysql 命令:FLUSH HOST。
max_connect_errors = 1000000
# 禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求
skip-name-resolve
# MySQL打开的文件描述符限制
open_files_limit = 65535
# MySQL 每打开一个表,都会读入一些数据到 table_open_cache 缓存中,当 MySQL 在这个缓存中找不到相应信息时,才会去磁盘上读取。默认值 400,最大值:524288。假定系统有 200 个并发连接,则需将此参数设置为 200*N (N 为每个连接所需的文件描述符数目);当把 table_open_cache 设置为很大时,如果系统处理不了那么多文件描述符,那么就会出现客户端失效,连接不上
table_open_cache = 2048
# 一个事务,在没有提交的时候,产生的日志,记录到 Cache 中;等到事务提交需要提交的时候,则把日志持久化到磁盘。默认 binlog_cache_size 大小32K
binlog_cache_size = 1M
# 定义了用户可以创建的内存表(memory table)的大小。这个值用来计算内存表的最大行数值。这个变量支持动态改变
max_heap_table_size = 32M
# MySQL的heap(堆积)表缓冲大小。如果超过该值,则会将临时表写入磁盘。其范围值:1KB~4GB
tmp_table_size = 32M
# MySQL读入缓冲区大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
read_buffer_size = 2M
# MySQL的随机读缓冲区大小。
read_rnd_buffer_size = 8M
# MySQL执行排序使用的缓冲大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
sort_buffer_size = 2M
# 联合查询操作所能使用的缓冲区大小,和sort_buffer_size一样,该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X4M=400M,所以4G内存的服务器,建议该值是6~8M
join_buffer_size = 4M
# 指定用于索引的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写),对于4GB内存的服务器,该参数可以设置为:256M或384M
key_buffer_size = 64M
# 这个值(默认8)表示可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,
# 根据物理内存设置规则如下:
# 1G —> 8
# 2G —> 16
# 3G —> 32
# 大于3G —> 64
thread_cache_size = 8
# 每个线程的堆栈大小,值范围:128K ~ 4GB,默认是192KB
thread_stack = 256k
# 0是关闭高速缓存,1是开启高速缓存
query_cache_type = 1
# 查询缓冲区的大小,如果是4G内存建议设置为64M。具体设置值还要根据运行环境来判断,你可以执行这个SQL语句:show status like 'Qcache%';
# 从SQL语句查询的结果中,查看Qcache_lowmem_prunes的值非常大表示查询缓冲不够,你应该增加该设置值
query_cache_size = 8M
query_cache_limit = 2M
# 分词词汇最小长度,默认4
ft_min_word_len = 4
log-bin = /usr/program/mysql/data/mysql-bin
binlog-format = mixed
expire_logs_days = 30
# 该参数的说明:http://blog.csdn.net/wulantian/article/details/9965905
sync_binlog = 0
# 是否开启慢查询记录,1表示开启,0表示关闭,如果是主从环境下,主库不要开启,从库开启
slow_query_log = 1
# 慢查询时间 超过3秒则为慢查询
long_query_time = 3
slow_query_log_file = /usr/program/mysql/data/mysql-slow.log
performance_schema = 0
# 改参数的说明:http://www.cnblogs.com/digdeep/p/4727715.html
explicit_defaults_for_timestamp = true
# 数据库库名/表名是否区分大小写,0:区分大小写,1:不区分大小写
lower_case_table_names = 1
# MySQL选项以避免外部锁定,减少出错几率,增强稳定性
skip_external_locking
# 在网络上不允许TCP/IP连接到MySQL。所有到MySQL的连接必须经由Unix socket进行。如果要允许TCP/IP连接,则注释当前行即可
# skip-networking
table_definition_cache = 1024
# 该设置值取值为:服务器机子的逻辑CPU数量X2,比如你的服务器机子是 Linux 系统你可以执行:grep 'processor' /proc/cpuinfo | sort -u | wc -l,可以查看到逻辑CPU数量值,比如我取到的值是24,那我这里应该设置为:24X2=48
thread_concurrency = 2
# 强制为 innodb类型
innodb = FORCE
innodb_file_per_table = 1
# 限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。这个值默认是300
innodb_open_files = 500
# InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM.
# 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少.
# 在一个独立使用的数据库服务器上,你可以设置这个变量到服务器物理内存大小的70%左右
# 不要设置过大,否则,由于物理内存的竞争可能导致操作系统的换页颠簸.
innodb_buffer_pool_size = 592M
# innodb使用后台线程处理数据页上的读写 I/O(输入输出)请求,根据你的 CPU 核数来更改,默认是4
# 注:这两个参数不支持动态改变,需要把该参数加入到my.cnf里,修改完后重启MySQL服务,允许值的范围从 1-64
innodb_write_io_threads = 4
innodb_read_io_threads = 4
# 默认设置为 0,表示不限制并发数,这里推荐设置为0,更好去发挥CPU多核处理能力,提高并发量
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 64M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_additional_mem_pool_size = 2M
bulk_insert_buffer_size = 8M
# 用于设置在 REPAIR TABLE 和 CREATE INDEX 创建索引或 ALTER TABLE 的过程中排序索引所分配的缓冲区大小,可设置范围:4MB~4GB,默认8MB,4G内存的服务器可以设置为32M~64M
myisam_sort_buffer_size = 8M
# 32位系统默认值是2147483648=2G,64位系统,默认值是9223372036854775807,单位是bytes.
myisam_max_sort_file_size = 100G
myisam_repair_threads = 1
# 服务器关闭交互式连接前等待活动的秒数。单位秒
interactive_timeout = 28800
# 服务器关闭非交互连接之前等待活动的秒数。单位秒。通过show processlist命令查看当前系统的连接状态,如果发现有大量的sleep状态的连接进程,则说明该参数设置的过大。默认值:28800
wait_timeout = 3600
# ============================================================================================================
[mysqldump]
quick
# 服务器发送和接受的最大包长度
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
================================================
FILE: favorite-file/MySQL-Settings/MySQL-5.6/1G-Memory-Machine/my-for-master.cnf
================================================
# 适用于 Mysql 5.6
# 该配置适合 1G 内存左右的机子,储存类型为 InnoDB
# 官网配置说明:http://dev.mysql.com/doc/refman/5.6/en/mysqld-option-tables.html
# 官网状态值说明:http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html
# 官网环境变量说明:http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html
# 在线生成配置工具:http://tools.percona.com(只是起到一个参考作用,生成的配置文件里面的参数名有的是用符号:-,而官网是用:_,所以这个也要注意改掉。)
# 资料参考:https://blog.linuxeye.com/379.html
# 注释内容为注释行下面的配置的解释
# 这是一个综合配置,不是单独为主库或是从库考虑
# ============================================================================================================
# 客户端设置
[mysql]
port = 3306
socket = /usr/program/mysql/data/mysql.sock
default-character-set = utf8
# ============================================================================================================
# 服务端设置
[mysqld]
user = mysql
port = 3306
default-storage-engine = InnoDB
socket = /usr/program/mysql/data/mysql.sock
pid-file = /usr/program/mysql/data/mysql.pid
collation-server = utf8_general_ci
init_connect = 'SET NAMES utf8'
character-set-server = utf8
basedir = /usr/program/mysql
datadir = /usr/program/mysql/data
log-error = /usr/program/mysql/data/mysql-error.log
# (重点修改)表示是本机的序号为1,一般配合设置主从的时候一定要修改的地方
server-id = 1
# back_log 值指出在 MySQL 暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。如果 MySQL 的连接数据达到 max_connections 时,新来的请求将会被存在堆栈中,以等待某一连接释放资源,该堆栈的数量即 back_log,如果等待连接的数量超过 back_log,将不被授予连接资源。
# 另外,这值(back_log)限于您的操作系统对到来的 TCP/IP 连接的侦听队列的大小。你的操作系统在这个队列大小上有它自己的限制(可以检查你的 OS 文档找出这个变量的最大值),试图设定 back_log 高于你的操作系统的限制将是无效的。
back_log = 512
# MySQL 的最大并发连接数
max_connections = 1000
# 网络传输中一次小心传输量的最大值(最大值为 1G);增加该变量的值十分安全,这是因为仅当需要时才会分配额外内存。例如,仅当你发出长查询或 MySQL 必须返回大的结果行时 MySQL 才会分配更多内存。该变量之所以取较小默认值是一种预防措施,以捕获客户端和服务器之间的错误信息包,并确保不会因偶然使用大的信息包而导致内存溢出。
max_allowed_packet = 16M
# 对于同一主机,如果有超出该参数值个数的中断错误连接,则该主机将被禁止连接。如需对该主机进行解禁,执行 Mysql 命令:FLUSH HOST。
max_connect_errors = 1000000
# 禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求
skip-name-resolve
# MySQL打开的文件描述符限制
open_files_limit = 65535
# MySQL 每打开一个表,都会读入一些数据到 table_open_cache 缓存中,当 MySQL 在这个缓存中找不到相应信息时,才会去磁盘上读取。默认值 400,最大值:524288。假定系统有 200 个并发连接,则需将此参数设置为 200*N (N 为每个连接所需的文件描述符数目);当把 table_open_cache 设置为很大时,如果系统处理不了那么多文件描述符,那么就会出现客户端失效,连接不上
table_open_cache = 2048
# 一个事务,在没有提交的时候,产生的日志,记录到 Cache 中;等到事务提交需要提交的时候,则把日志持久化到磁盘。默认 binlog_cache_size 大小32K
binlog_cache_size = 1M
# 定义了用户可以创建的内存表(memory table)的大小。这个值用来计算内存表的最大行数值。这个变量支持动态改变
max_heap_table_size = 32M
# MySQL的heap(堆积)表缓冲大小。如果超过该值,则会将临时表写入磁盘。其范围值:1KB~4GB
tmp_table_size = 32M
# MySQL读入缓冲区大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
read_buffer_size = 2M
# MySQL的随机读缓冲区大小。
read_rnd_buffer_size = 8M
# MySQL执行排序使用的缓冲大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
sort_buffer_size = 2M
# 联合查询操作所能使用的缓冲区大小,和sort_buffer_size一样,该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X4M=400M,所以4G内存的服务器,建议该值是6~8M
join_buffer_size = 4M
# 指定用于索引的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写),对于4GB内存的服务器,该参数可以设置为:256M或384M
key_buffer_size = 64M
# 这个值(默认8)表示可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,
# 根据物理内存设置规则如下:
# 1G —> 8
# 2G —> 16
# 3G —> 32
# 大于3G —> 64
thread_cache_size = 8
# 每个线程的堆栈大小,值范围:128K ~ 4GB,默认是192KB
thread_stack = 256k
# 0是关闭高速缓存,1是开启高速缓存
query_cache_type = 0
# 查询缓冲区的大小,如果是4G内存建议设置为64M。具体设置值还要根据运行环境来判断,你可以执行这个SQL语句:show status like 'Qcache%';
# 从SQL语句查询的结果中,查看Qcache_lowmem_prunes的值非常大表示查询缓冲不够,你应该增加该设置值
query_cache_size = 0
query_cache_limit = 2M
# 分词词汇最小长度,默认4
ft_min_word_len = 4
log-bin = /usr/program/mysql/data/mysql-bin
binlog-format = mixed
expire_logs_days = 30
# 该参数的说明:http://blog.csdn.net/wulantian/article/details/9965905
sync_binlog = 1
# 是否开启慢查询记录,1表示开启,0表示关闭,如果是主从环境下,主库不要开启,从库开启
slow_query_log = 0
# 慢查询时间 超过3秒则为慢查询
long_query_time = 3
slow_query_log_file = /usr/program/mysql/data/mysql-slow.log
performance_schema = 0
# 改参数的说明:http://www.cnblogs.com/digdeep/p/4727715.html
explicit_defaults_for_timestamp = true
# 数据库库名/表名是否区分大小写,0:区分大小写,1:不区分大小写
lower_case_table_names = 1
# MySQL选项以避免外部锁定,减少出错几率,增强稳定性
skip_external_locking
# 在网络上不允许TCP/IP连接到MySQL。所有到MySQL的连接必须经由Unix socket进行。如果要允许TCP/IP连接,则注释当前行即可
# skip-networking
table_definition_cache = 1024
# 该设置值取值为:服务器机子的逻辑CPU数量X2,比如你的服务器机子是 Linux 系统你可以执行:grep 'processor' /proc/cpuinfo | sort -u | wc -l,可以查看到逻辑CPU数量值,比如我取到的值是24,那我这里应该设置为:24X2=48
thread_concurrency = 2
# 强制为 innodb类型
innodb = FORCE
innodb_file_per_table = 1
# 限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。这个值默认是300
innodb_open_files = 500
# InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM.
# 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少.
# 在一个独立使用的数据库服务器上,你可以设置这个变量到服务器物理内存大小的70%左右
# 不要设置过大,否则,由于物理内存的竞争可能导致操作系统的换页颠簸.
innodb_buffer_pool_size = 592M
# innodb使用后台线程处理数据页上的读写 I/O(输入输出)请求,根据你的 CPU 核数来更改,默认是4
# 注:这两个参数不支持动态改变,需要把该参数加入到my.cnf里,修改完后重启MySQL服务,允许值的范围从 1-64
innodb_write_io_threads = 4
innodb_read_io_threads = 4
# 默认设置为 0,表示不限制并发数,这里推荐设置为0,更好去发挥CPU多核处理能力,提高并发量
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 64M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_additional_mem_pool_size = 2M
bulk_insert_buffer_size = 8M
# 用于设置在 REPAIR TABLE 和 CREATE INDEX 创建索引或 ALTER TABLE 的过程中排序索引所分配的缓冲区大小,可设置范围:4MB~4GB,默认8MB,4G内存的服务器可以设置为32M~64M
myisam_sort_buffer_size = 8M
# 32位系统默认值是2147483648=2G,64位系统,默认值是9223372036854775807,单位是bytes.
myisam_max_sort_file_size = 100G
myisam_repair_threads = 1
# 服务器关闭交互式连接前等待活动的秒数。单位秒
interactive_timeout = 28800
# 服务器关闭非交互连接之前等待活动的秒数。单位秒。通过show processlist命令查看当前系统的连接状态,如果发现有大量的sleep状态的连接进程,则说明该参数设置的过大。默认值:28800
wait_timeout = 3600
# ============================================================================================================
[mysqldump]
quick
# 服务器发送和接受的最大包长度
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
================================================
FILE: favorite-file/MySQL-Settings/MySQL-5.6/1G-Memory-Machine/my-for-salve.cnf
================================================
# 适用于 Mysql 5.6
# 该配置适合 1G 内存左右的机子,储存类型为 InnoDB
# 官网配置说明:http://dev.mysql.com/doc/refman/5.6/en/mysqld-option-tables.html
# 官网状态值说明:http://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html
# 官网环境变量说明:http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html
# 在线生成配置工具:http://tools.percona.com(只是起到一个参考作用,生成的配置文件里面的参数名有的是用符号:-,而官网是用:_,所以这个也要注意改掉。)
# 资料参考:https://blog.linuxeye.com/379.html
# 注释内容为注释行下面的配置的解释
# 这是一个综合配置,不是单独为主库或是从库考虑
# ============================================================================================================
# 客户端设置
[mysql]
port = 3306
socket = /usr/program/mysql/data/mysql.sock
default-character-set = utf8
# ============================================================================================================
# 服务端设置
[mysqld]
user = mysql
port = 3306
default-storage-engine = InnoDB
socket = /usr/program/mysql/data/mysql.sock
pid-file = /usr/program/mysql/data/mysql.pid
collation-server = utf8_general_ci
init_connect = 'SET NAMES utf8'
character-set-server = utf8
basedir = /usr/program/mysql
datadir = /usr/program/mysql/data
log-error = /usr/program/mysql/data/mysql-error.log
# (重点修改)表示是本机的序号为1,一般配合设置主从的时候一定要修改的地方
server-id = 1
# 从库特有的设置 start
read_only = true
# 从库不自动开启主从设置,需要使用命令:START SLAVE;
skip-slave-start = true
log-slave-updates = true
relay-log = /usr/program/mysql/data/relay-bin
# 单位秒
slave-net-timeout = 60
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
# 从库特有的设置 end
# back_log 值指出在 MySQL 暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。如果 MySQL 的连接数据达到 max_connections 时,新来的请求将会被存在堆栈中,以等待某一连接释放资源,该堆栈的数量即 back_log,如果等待连接的数量超过 back_log,将不被授予连接资源。
# 另外,这值(back_log)限于您的操作系统对到来的 TCP/IP 连接的侦听队列的大小。你的操作系统在这个队列大小上有它自己的限制(可以检查你的 OS 文档找出这个变量的最大值),试图设定 back_log 高于你的操作系统的限制将是无效的。
back_log = 512
# MySQL 的最大并发连接数
max_connections = 1000
# 网络传输中一次小心传输量的最大值(最大值为 1G);增加该变量的值十分安全,这是因为仅当需要时才会分配额外内存。例如,仅当你发出长查询或 MySQL 必须返回大的结果行时 MySQL 才会分配更多内存。该变量之所以取较小默认值是一种预防措施,以捕获客户端和服务器之间的错误信息包,并确保不会因偶然使用大的信息包而导致内存溢出。
max_allowed_packet = 16M
# 对于同一主机,如果有超出该参数值个数的中断错误连接,则该主机将被禁止连接。如需对该主机进行解禁,执行 Mysql 命令:FLUSH HOST。
max_connect_errors = 1000000
# 禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求
skip-name-resolve
# MySQL打开的文件描述符限制
open_files_limit = 65535
# MySQL 每打开一个表,都会读入一些数据到 table_open_cache 缓存中,当 MySQL 在这个缓存中找不到相应信息时,才会去磁盘上读取。默认值 400,最大值:524288。假定系统有 200 个并发连接,则需将此参数设置为 200*N (N 为每个连接所需的文件描述符数目);当把 table_open_cache 设置为很大时,如果系统处理不了那么多文件描述符,那么就会出现客户端失效,连接不上
table_open_cache = 2048
# 一个事务,在没有提交的时候,产生的日志,记录到 Cache 中;等到事务提交需要提交的时候,则把日志持久化到磁盘。默认 binlog_cache_size 大小32K
binlog_cache_size = 1M
# 定义了用户可以创建的内存表(memory table)的大小。这个值用来计算内存表的最大行数值。这个变量支持动态改变
max_heap_table_size = 32M
# MySQL的heap(堆积)表缓冲大小。如果超过该值,则会将临时表写入磁盘。其范围值:1KB~4GB
tmp_table_size = 32M
# MySQL读入缓冲区大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
read_buffer_size = 2M
# MySQL的随机读缓冲区大小。
read_rnd_buffer_size = 8M
# MySQL执行排序使用的缓冲大小。该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X2M=200M,所以4G内存的服务器,建议该值是6~8M
sort_buffer_size = 2M
# 联合查询操作所能使用的缓冲区大小,和sort_buffer_size一样,该参数对应的分配内存也是每连接独享,所以,如果有100连接,那占用的内存是:100X4M=400M,所以4G内存的服务器,建议该值是6~8M
join_buffer_size = 4M
# 指定用于索引的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写),对于4GB内存的服务器,该参数可以设置为:256M或384M
key_buffer_size = 64M
# 这个值(默认8)表示可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,
# 根据物理内存设置规则如下:
# 1G —> 8
# 2G —> 16
# 3G —> 32
# 大于3G —> 64
thread_cache_size = 8
# 每个线程的堆栈大小,值范围:128K ~ 4GB,默认是192KB
thread_stack = 256k
# 0是关闭高速缓存,1是开启高速缓存
query_cache_type = 1
# 查询缓冲区的大小,如果是4G内存建议设置为64M。具体设置值还要根据运行环境来判断,你可以执行这个SQL语句:show status like 'Qcache%';
# 从SQL语句查询的结果中,查看Qcache_lowmem_prunes的值非常大表示查询缓冲不够,你应该增加该设置值
query_cache_size = 8M
query_cache_limit = 2M
# 分词词汇最小长度,默认4
ft_min_word_len = 4
log-bin = /usr/program/mysql/data/mysql-bin
binlog-format = mixed
expire_logs_days = 30
# 该参数的说明:http://blog.csdn.net/wulantian/article/details/9965905
sync_binlog = 0
# 是否开启慢查询记录,1表示开启,0表示关闭,如果是主从环境下,主库不要开启,从库开启
slow_query_log = 1
# 慢查询时间 超过3秒则为慢查询
long_query_time = 3
slow_query_log_file = /usr/program/mysql/data/mysql-slow.log
performance_schema = 0
# 改参数的说明:http://www.cnblogs.com/digdeep/p/4727715.html
explicit_defaults_for_timestamp = true
# 数据库库名/表名是否区分大小写,0:区分大小写,1:不区分大小写
lower_case_table_names = 1
# MySQL选项以避免外部锁定,减少出错几率,增强稳定性
skip_external_locking
# 在网络上不允许TCP/IP连接到MySQL。所有到MySQL的连接必须经由Unix socket进行。如果要允许TCP/IP连接,则注释当前行即可
# skip-networking
table_definition_cache = 1024
# 该设置值取值为:服务器机子的逻辑CPU数量X2,比如你的服务器机子是 Linux 系统你可以执行:grep 'processor' /proc/cpuinfo | sort -u | wc -l,可以查看到逻辑CPU数量值,比如我取到的值是24,那我这里应该设置为:24X2=48
thread_concurrency = 2
# 强制为 innodb类型
innodb = FORCE
innodb_file_per_table = 1
# 限制Innodb能打开的表的数据,如果库里的表特别多的情况,请增加这个。这个值默认是300
innodb_open_files = 500
# InnoDB使用一个缓冲池来保存索引和原始数据, 不像MyISAM.
# 这里你设置越大,你在存取表里面数据时所需要的磁盘I/O越少.
# 在一个独立使用的数据库服务器上,你可以设置这个变量到服务器物理内存大小的70%左右
# 不要设置过大,否则,由于物理内存的竞争可能导致操作系统的换页颠簸.
innodb_buffer_pool_size = 592M
# innodb使用后台线程处理数据页上的读写 I/O(输入输出)请求,根据你的 CPU 核数来更改,默认是4
# 注:这两个参数不支持动态改变,需要把该参数加入到my.cnf里,修改完后重启MySQL服务,允许值的范围从 1-64
innodb_write_io_threads = 4
innodb_read_io_threads = 4
# 默认设置为 0,表示不限制并发数,这里推荐设置为0,更好去发挥CPU多核处理能力,提高并发量
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 2M
innodb_log_file_size = 64M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_additional_mem_pool_size = 2M
bulk_insert_buffer_size = 8M
# 用于设置在 REPAIR TABLE 和 CREATE INDEX 创建索引或 ALTER TABLE 的过程中排序索引所分配的缓冲区大小,可设置范围:4MB~4GB,默认8MB,4G内存的服务器可以设置为32M~64M
myisam_sort_buffer_size = 8M
# 32位系统默认值是2147483648=2G,64位系统,默认值是9223372036854775807,单位是bytes.
myisam_max_sort_file_size = 100G
myisam_repair_threads = 1
# 服务器关闭交互式连接前等待活动的秒数。单位秒
interactive_timeout = 28800
# 服务器关闭非交互连接之前等待活动的秒数。单位秒。通过show processlist命令查看当前系统的连接状态,如果发现有大量的sleep状态的连接进程,则说明该参数设置的过大。默认值:28800
wait_timeout = 3600
# ============================================================================================================
[mysqldump]
quick
# 服务器发送和接受的最大包长度
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
================================================
FILE: favorite-file/MySQL-Settings/MySQL-5.6/8G-Memory-Machine/my.cnf
================================================
[mysql]
port = 3306
socket = /usr/program/mysql/data/mysql.sock
default-character-set = utf8
[mysqld]
user = mysql
port = 3306
server-id = 100866
default-storage-engine = InnoDB
socket = /usr/program/mysql/data/mysql.sock
pid-file = /usr/program/mysql/data/mysql.pid
collation-server = utf8_general_ci
init_connect = 'SET NAMES utf8'
character-set-server = utf8
basedir = /usr/program/mysql
datadir = /usr/program/mysql/data
log-error = /usr/program/mysql/data/mysql-error.log
back_log = 512
max_connections = 1000
max_allowed_packet = 120M
max_connect_errors = 1000000
skip-name-resolve
open_files_limit = 65535
table_open_cache = 2048
binlog_cache_size = 20M
max_heap_table_size = 40M
tmp_table_size = 64M
read_buffer_size = 20M
read_rnd_buffer_size = 20M
sort_buffer_size = 20M
join_buffer_size = 20M
key_buffer_size = 40M
thread_cache_size = 100
thread_stack = 20M
# 5.6.8之后这个不再建议开启了,所以要关掉
query_cache_type = 0
query_cache_size = 40M
query_cache_limit = 10M
ft_min_word_len = 4
log-bin = /usr/program/mysql/data/mysql-bin
binlog-format = mixed
expire_logs_days = 14
sync_binlog = 0
log-queries-not-using-indexes = 1
slow_query_log = 0
long_query_time = 3
slow_query_log_file = /usr/program/mysql/data/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp = true
lower_case_table_names = 1
skip_external_locking
table_definition_cache = 1024
thread_concurrency = 2
innodb = FORCE
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_open_files = 500
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 20M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_lock_wait_timeout = 120
innodb_additional_mem_pool_size = 20M
innodb_buffer_pool_size = 3G
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_io_capacity = 2000
innodb_max_dirty_pages_pct = 90
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 3600
[mysqldump]
quick
max_allowed_packet = 120M
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 20M
write_buffer = 20M
================================================
FILE: favorite-file/MySQL-Settings/MySQL-5.6/developer/my-Windows-8G-开发机.ini
================================================
[client]
no-beep
port=3306
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir="C:/Program Files/MySQL/MySQL Server 5.6/"
datadir="C:/ProgramData/MySQL/MySQL Server 5.6/data\"
character-set-server=utf8
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-output=NONE
general-log=0
general_log_file="AJBC-1540.log"
slow-query-log=0
slow_query_log_file="AJBC-1540-slow.log"
long_query_time=10
log-error="AJBC-1540.err"
max_connections=1000
query_cache_size=10M
table_open_cache=2000
tmp_table_size=37M
thread_cache_size=32
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=72M
key_buffer_size=256M
read_buffer_size=6M
read_rnd_buffer_size=8M
sort_buffer_size=2M
innodb_additional_mem_pool_size=5M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=3M
innodb_buffer_pool_size=592M
innodb_log_file_size=64M
innodb_thread_concurrency=9
innodb_autoextend_increment=64M
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=500
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=512
flush_time=0
join_buffer_size=4M
max_allowed_packet=50M
max_connect_errors=1000000
open_files_limit=65535
query_cache_type=1
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 1
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
max_heap_table_size = 32M
thread_stack = 256k
ft_min_word_len = 4
performance_schema = 0
explicit_defaults_for_timestamp = true
skip_external_locking
bulk_insert_buffer_size = 8M
wait_timeout = 3600
interactive_timeout = 28800
myisam_repair_threads = 1
query_cache_limit = 5M
================================================
FILE: favorite-file/Nginx-Settings/nginx
================================================
#!/bin/bash
#nginx执行程序路径需要修改
nginxd=/usr/local/nginx/sbin/nginx
# nginx配置文件路径需要修改
nginx_config=/usr/local/nginx/conf/nginx.conf
# pid 地址需要修改
nginx_pid=/var/local/nginx/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
# pid 地址需要修改
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/local/nginx/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
================================================
FILE: favorite-file/Nginx-Settings/nginx-front.conf
================================================
user root;
worker_processes auto;
pid /run/nginx.pid;
events {
use epoll;
multi_accept on;
worker_connections 1024;
}
http {
# 必须加这两个,不然 CSS 无法正常加载
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
gzip on;
gzip_buffers 8 16k;
gzip_min_length 512;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_http_version 1.1;
gzip_types text/plain text/css application/javascript application/x-javascript application/json application/xml;
server {
listen 8001;
server_name localhost 127.0.0.1 139.159.190.24 platform.gitnavi.com;
location / {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
index index.html index.htm;
try_files $uri /index.html;
}
## 二级目录方式,记得 package.json 添加:"homepage": "cdk8s-markdown",
location ^~ /cdk8s-markdown {
root /root/.jenkins/workspace;
index index.html;
try_files $uri /cdk8s-markdown/index.html;
}
location ^~ /platform/ {
proxy_pass http://127.0.0.1:28081;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(js|css)?$ {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|woff|woff2|ttf|eot|txt|svg)$ {
root /root/.jenkins/workspace/nestle-platform-front-test/dist;
}
error_page 404 /404.html;
location = /usr/share/nginx/html/40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /usr/share/nginx/html/50x.html {
}
}
server {
listen 8002;
server_name localhost 127.0.0.1 139.159.190.24 store.gitnavi.com;
location / {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
index index.html index.htm;
try_files $uri /index.html;
}
location ^~ /store/ {
proxy_pass http://127.0.0.1:28082;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(js|css)?$ {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico|woff|woff2|ttf|eot|txt|svg)$ {
root /root/.jenkins/workspace/nestle-store-front-test/dist;
}
error_page 404 /404.html;
location = /usr/share/nginx/html/40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /usr/share/nginx/html/50x.html {
}
}
}
================================================
FILE: favorite-file/Tomcat-Settings/server.xml
================================================
================================================
FILE: favorite-file/gravitee-docker-compose/README.md
================================================
# graviteeio api gateway docker-compose running
fork from graviteeio project && change some deps image
-
-
## how to run
```code
cd platform && docker-compose up -d
```
## manager ui
* api portal
```code
open https://localhost/apim/portal
```
* access manager ui
```code
open https://localhost/am/ui/
```
## Note:
- environments directory has some demos with ci && traefik gateway
- portal account admin amdin
- access manager ui account admin adminadmin
================================================
FILE: favorite-file/gravitee-docker-compose/environments/ci/docker-compose.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
services:
ci:
image: graviteeio/jenkins:latest
container_name: ci
network_mode: "bridge"
expose:
- 50022
ports:
- "50022:50022"
labels:
- "traefik.frontend.rule=Host:ci.gravitee.io"
- "traefik.port=8080"
volumes:
- /var/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
links:
- redis-test
- qa
redis-test:
image: redis:3
container_name: redis-test
network_mode: "bridge"
qa:
image: sonarqube:alpine
container_name: qa
network_mode: "bridge"
environment:
- SONARQUBE_JDBC_URL=jdbc:postgresql://sonarqube-db:5432/sonar
labels:
- "traefik.frontend.rule=Host:qa.gravitee.io"
volumes:
- /opt/sonarqube/conf:/opt/sonarqube/conf
- /opt/sonarqube/data:/opt/sonarqube/data
- /opt/sonarqube/extensions:/opt/sonarqube/extensions
- /opt/sonarqube/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
links:
- sonarqube-db
sonarqube-db:
image: postgres:alpine
network_mode: "bridge"
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- /opt/sonarqube/postgresql/data:/var/lib/postgresql/data
================================================
FILE: favorite-file/gravitee-docker-compose/environments/demo/common.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
volumes:
datamongo: {}
dataelasticsearch: {}
services:
elasticsearch:
hostname: demo-elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
volumes:
- dataelasticsearch:/usr/share/elasticsearch/data
environment:
- http.host=0.0.0.0
- transport.host=0.0.0.0
- xpack.security.enabled=false
- xpack.monitoring.enabled=false
- cluster.name=elasticsearch
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile: 65536
mongodb:
hostname: demo-mongodb
image: mongo:3.4
volumes:
- datamongo:/data/db
gateway:
hostname: demo-gateway
image: graviteeio/gateway:latest
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://elasticsearch:9200
managementui:
hostname: demo-managementui
image: graviteeio/management-ui:latest
managementapi:
hostname: demo-managementapi
image: graviteeio/management-api:latest
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://elasticsearch:9200
================================================
FILE: favorite-file/gravitee-docker-compose/environments/demo/docker-compose-local.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
volumes:
local_datamongo: {}
local_dataelasticsearch: {}
services:
local_elasticsearch:
extends:
file: common.yml
service: elasticsearch
volumes:
- local_dataelasticsearch:/usr/share/elasticsearch/data
- ./logs/elasticsearch:/var/log/elasticsearch
local_mongodb:
extends:
file: common.yml
service: mongodb
volumes:
- local_datamongo:/data/db
- ./logs/mongodb:/var/log/mongodb
local_gateway:
extends:
file: common.yml
service: gateway
links:
- "local_mongodb:demo-mongodb"
- "local_elasticsearch:demo-elasticsearch"
ports:
- "8000:8082"
volumes:
- ./logs/gateway:/etc/gravitee.io/log
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
local_managementui:
extends:
file: common.yml
service: managementui
ports:
- "8002:80"
volumes:
- ./logs/management-ui:/var/log/httpd
environment:
- MGMT_API_URL=http:\/\/localhost:8005\/management\/
local_managementapi:
extends:
file: common.yml
service: managementapi
ports:
- "8005:8083"
volumes:
- ./logs/management-api:/home/gravitee/logs
links:
- "local_mongodb:demo-mongodb"
- "local_elasticsearch:demo-elasticsearch"
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
================================================
FILE: favorite-file/gravitee-docker-compose/environments/demo/docker-compose-traefik-latest.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
volumes:
latest_datamongo: {}
latest_dataelasticsearch: {}
services:
latest_elasticsearch:
network_mode: "bridge"
extends:
file: common.yml
service: elasticsearch
volumes:
- latest_dataelasticsearch:/usr/share/elasticsearch/data
latest_mongodb:
network_mode: "bridge"
extends:
file: common.yml
service: mongodb
volumes:
- latest_datamongo:/data/db
latest_gateway:
network_mode: "bridge"
extends:
file: common.yml
service: gateway
links:
- latest_mongodb
- latest_elasticsearch
labels:
- "traefik.backend=graviteeio-gateway"
- "traefik.frontend.rule=Host:demo.gravitee.io;PathPrefixStrip:/gateway"
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
latest_managementui:
network_mode: "bridge"
extends:
file: common.yml
service: managementui
labels:
- "traefik.backend=graviteeio-managementui"
- "traefik.frontend.rule=Host:demo.gravitee.io"
environment:
- MGMT_API_URL=https:\/\/demo.gravitee.io\/management\/
latest_managementapi:
network_mode: "bridge"
extends:
file: common.yml
service: managementapi
labels:
- "traefik.backend=graviteeio-managementapi"
- "traefik.frontend.rule=Host:demo.gravitee.io;PathPrefix:/management"
links:
- latest_mongodb
- latest_elasticsearch
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
================================================
FILE: favorite-file/gravitee-docker-compose/environments/demo/docker-compose-traefik-nightly.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
volumes:
nightly_datamongo: {}
nightly_dataelasticsearch: {}
services:
nightly_elasticsearch:
network_mode: "bridge"
extends:
file: common.yml
service: elasticsearch
volumes:
- nightly_dataelasticsearch:/usr/share/elasticsearch/data
nightly_mongodb:
network_mode: "bridge"
extends:
file: common.yml
service: mongodb
volumes:
- nightly_datamongo:/data/db
nightly_gateway:
image: graviteeio/gateway:nightly
network_mode: "bridge"
extends:
file: common.yml
service: gateway
links:
- nightly_mongodb
- nightly_elasticsearch
labels:
- "traefik.backend=nightly-graviteeio-gateway"
- "traefik.frontend.rule=Host:nightly.gravitee.io;PathPrefixStrip:/gateway"
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
nightly_managementui:
image: graviteeio/management-ui:nightly
network_mode: "bridge"
extends:
file: common.yml
service: managementui
labels:
- "traefik.backend=nightly-graviteeio-managementui"
- "traefik.frontend.rule=Host:nightly.gravitee.io"
environment:
- MGMT_API_URL=https:\/\/nightly.gravitee.io\/management\/
nightly_managementapi:
image: graviteeio/management-api:nightly
network_mode: "bridge"
extends:
file: common.yml
service: managementapi
labels:
- "traefik.backend=nightly-graviteeio-managementapi"
- "traefik.frontend.rule=Host:nightly.gravitee.io;PathPrefix:/management"
links:
- nightly_mongodb
- nightly_elasticsearch
environment:
- gravitee_management_mongodb_uri=mongodb://demo-mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://demo-elasticsearch:9200
================================================
FILE: favorite-file/gravitee-docker-compose/environments/demo/launch.sh
================================================
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
readonly WORKDIR="$HOME/graviteeio-demo"
readonly DIRNAME=`dirname $0`
readonly PROGNAME=`basename $0`
readonly color_title='\033[32m'
readonly color_text='\033[1;36m'
# OS specific support (must be 'true' or 'false').
declare cygwin=false
declare darwin=false
declare linux=false
declare dc_exec="docker-compose -f docker-compose-local.yml up"
welcome() {
echo
echo -e " ${color_title} _____ _____ __ _______ _______ ______ ______ _____ ____ \033[0m"
echo -e " ${color_title} / ____| __ \ /\ \ / /_ _|__ __| ____| ____| |_ _/ __ \ \033[0m"
echo -e " ${color_title}| | __| |__) | / \ \ / / | | | | | |__ | |__ | || | | | \033[0m"
echo -e " ${color_title}| | |_ | _ / / /\ \ \/ / | | | | | __| | __| | || | | | \033[0m"
echo -e " ${color_title}| |__| | | \ \ / ____ \ / _| |_ | | | |____| |____ _ _| || |__| | \033[0m"
echo -e " ${color_title} \_____|_| \_\/_/ \_\/ |_____| |_| |______|______(_)_____\____/ \033[0m"
echo -e " ${color_title} | | \033[0m${color_text}http://gravitee.io\033[0m"
echo -e " ${color_title} __| | ___ _ __ ___ ___ \033[0m"
echo -e " ${color_title} / _\` |/ _ \ '_ \` _ \ / _ \ \033[0m"
echo -e " ${color_title}| (_| | __/ | | | | | (_) | \033[0m"
echo -e " ${color_title} \__,_|\___|_| |_| |_|\___/ \033[0m"
echo
}
init_env() {
local dockergrp
# define env
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
Linux)
linux=true
;;
esac
# test if docker must be run with sudo
dockergrp=$(groups | grep -c docker)
if [[ $darwin == false && $dockergrp == 0 ]]; then
dc_exec="sudo $dc_exec";
fi
}
init_dirs() {
echo "Init log directory in $WORKDIR ..."
mkdir -p "$WORKDIR/logs/"
echo
}
main() {
welcome
init_env
if [[ $? != 0 ]]; then
exit 1
fi
set -e
init_dirs
pushd $WORKDIR > /dev/null
echo "Download docker compose files ..."
curl -L https://raw.githubusercontent.com/gravitee-io/gravitee-docker/master/environments/demo/common.yml -o "common.yml"
curl -L https://raw.githubusercontent.com/gravitee-io/gravitee-docker/master/environments/demo/docker-compose-local.yml -o "docker-compose-local.yml"
echo
echo "Launch GraviteeIO demo ..."
$dc_exec
popd > /dev/null
}
main
================================================
FILE: favorite-file/gravitee-docker-compose/environments/sample-apis/docker-compose-sample-apis.yml
================================================
#-------------------------------------------------------------------------------
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-------------------------------------------------------------------------------
version: '2'
services:
sample-api-index:
image: graviteeio/gravitee-sample-index:latest
network_mode: "bridge"
labels:
- "traefik.backend=gravitee-sample-index"
- "traefik.frontend.rule=Host:api.gravitee.io"
- "traefik.frontend.entryPoints=https"
sample-api-echo:
image: graviteeio/gravitee-echo-api:nightly
network_mode: "bridge"
labels:
- "traefik.backend=gravitee-echo-api"
- "traefik.frontend.rule=Host:api.gravitee.io;PathPrefix:/echo"
- "traefik.frontend.entryPoints=https"
sample-api-whoami:
image: graviteeio/gravitee-whoami-api:latest
network_mode: "bridge"
labels:
- "traefik.backend=gravitee-whoami-api"
- "traefik.frontend.rule=Host:api.gravitee.io;PathPrefix:/whoami"
- "traefik.frontend.entryPoints=https"
sample-api-whattimeisit:
image: graviteeio/gravitee-whattimeisit-api:latest
network_mode: "bridge"
labels:
- "traefik.backend=gravitee-whattimeisit-api"
- "traefik.frontend.rule=Host:api.gravitee.io;PathPrefix:/whattimeisit"
- "traefik.frontend.entryPoints=https"
================================================
FILE: favorite-file/gravitee-docker-compose/platform/docker-compose.yml
================================================
version: '3'
networks:
default:
services:
nginx:
image: nginx:1.15-alpine
container_name: gio_platform_nginx
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/ssl/gio-selfsigned.crt:/etc/ssl/certs/gio-selfsigned.crt
- ./nginx/ssl/gio-selfsigned.key:/etc/ssl/private/gio-selfsigned.key
- ./nginx/ssl/gio.pem:/etc/ssl/certs/gio.pem
ports:
- "80:80"
- "443:443"
depends_on:
- apim_gateway
- apim_portal
- apim_management
- am_gateway
- am_management
- am_webui
mongodb:
image: mongo:3.4
container_name: gio_platform_mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_DATABASE=gravitee
volumes:
- ./mongo/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- ./data/mongo:/data/db
- ./logs/mongodb:/var/log/mongodb
elasticsearch:
image: elasticsearch:6.4.0
container_name: gio_platform_elasticsearch
ports:
- 9200:9200
environment:
- http.host=0.0.0.0
- transport.host=0.0.0.0
- xpack.security.enabled=false
- xpack.monitoring.enabled=false
- cluster.name=elasticsearch
ulimits:
nofile: 65536
volumes:
- ./data/elasticsearch:/usr/share/elasticsearch/data
- ./logs/elasticsearch:/var/log/elasticsearch
apim_gateway:
image: graviteeio/gateway:latest
container_name: gio_platform_apim_gateway
volumes:
- ./logs/apim-gateway:/opt/graviteeio-gateway/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_reporters_elasticsearch_endpoints_0=http://elasticsearch:9200
- gravitee_services_metrics_enabled=true
- gravitee_services_metrics_prometheus.enabled=true
depends_on:
- mongodb
- elasticsearch
apim_portal:
image: graviteeio/management-ui:latest
container_name: gio_platform_apim_portal
environment:
- MGMT_API_URL=https:\/\/localhost\/apim\/management\/
depends_on:
- apim_management
apim_management:
image: graviteeio/management-api:latest
container_name: gio_platform_apim_mgmt_api
volumes:
- ./logs/apim-management-api:/opt/graviteeio-management-api/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_ratelimit_mongodb_uri=mongodb://mongodb:27017/gravitee?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_analytics_elasticsearch_endpoints_0=http://elasticsearch:9200
- gravitee_jwt_cookiepath=/apim/management
- gravitee_jwt_cookiesecure=true
depends_on:
- mongodb
- elasticsearch
am_gateway:
image: graviteeio/am-gateway:2
container_name: gio_platform_am_gateway
volumes:
- ./logs/am-gateway:/opt/graviteeio-am-gateway/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
depends_on:
- mongodb
am_management:
image: graviteeio/am-management-api:2
container_name: gio_platform_am_management
volumes:
- ./logs/am-management-api:/opt/graviteeio-am-management-api/logs
environment:
- gravitee_management_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_oauth2_mongodb_uri=mongodb://mongodb:27017/gravitee-am?serverSelectionTimeoutMS=5000&connectTimeoutMS=5000&socketTimeoutMS=5000
- gravitee_jwt_cookiepath=/am/management
- gravitee_jwt_cookiesecure=true
depends_on:
- mongodb
grafana:
image: grafana/grafana
ports:
- "3000:3000"
prometheus:
image: prom/prometheus
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
am_webui:
image: graviteeio/am-management-ui:2
container_name: gio_platform_am_webui
environment:
- MGMT_API_URL=https:\/\/localhost\/am\/
- MGMT_UI_URL=https:\/\/localhost\/am\/ui\/
volumes:
- ./logs/am-webui:/var/log/nginx
depends_on:
- am_management
================================================
FILE: favorite-file/gravitee-docker-compose/platform/mongo/docker-entrypoint-initdb.d/create-index.js
================================================
// "apis" collection
db.apis.dropIndexes();
db.apis.createIndex( { "visibility" : 1 } );
db.apis.createIndex( { "group" : 1 } );
db.apis.reIndex();
// "applications" collection
db.applications.dropIndexes();
db.applications.createIndex( { "group" : 1 } );
db.applications.createIndex( { "name" : 1 } );
db.applications.createIndex( { "status" : 1 } );
db.applications.reIndex();
// "events" collection
db.events.dropIndexes();
db.events.createIndex( { "type" : 1 } );
db.events.createIndex( { "updatedAt" : 1 } );
db.events.createIndex( { "properties.api_id" : 1 } );
db.events.createIndex( { "properties.api_id":1, "type":1} );
db.events.reIndex();
// "plans" collection
db.plans.dropIndexes();
db.plans.createIndex( { "apis" : 1 } );
db.plans.reIndex();
// "subscriptions" collection
db.subscriptions.dropIndexes();
db.subscriptions.createIndex( { "plan" : 1 } );
db.subscriptions.createIndex( { "application" : 1 } );
db.subscriptions.reIndex();
// "keys" collection
db.keys.dropIndexes();
db.keys.createIndex( { "plan" : 1 } );
db.keys.createIndex( { "application" : 1 } );
db.keys.createIndex( { "updatedAt" : 1 } );
db.keys.createIndex( { "revoked" : 1 } );
db.keys.createIndex( { "plan" : 1 , "revoked" : 1, "updatedAt" : 1 } );
db.keys.reIndex();
// "pages" collection
db.pages.dropIndexes();
db.pages.createIndex( { "api" : 1 } );
db.pages.reIndex();
// "memberships" collection
db.memberships.dropIndexes();
db.memberships.createIndex( {"_id.userId":1, "_id.referenceId":1, "_id.referenceType":1}, { unique: true } );
db.memberships.createIndex( {"_id.referenceId":1, "_id.referenceType":1} );
db.memberships.createIndex( {"_id.referenceId":1, "_id.referenceType":1, "roles":1} );
db.memberships.createIndex( {"_id.userId":1, "_id.referenceType":1} );
db.memberships.createIndex( {"_id.userId":1, "_id.referenceType":1, "roles":1} );
db.memberships.reIndex();
// "roles" collection
db.roles.dropIndexes();
db.roles.createIndex( {"_id.scope": 1 } );
db.roles.reIndex();
// "audits" collection
db.audits.dropIndexes();
db.audits.createIndex( { "referenceType": 1, "referenceId": 1 } );
db.audits.createIndex( { "createdAt": 1 } );
db.audits.reIndex();
// "rating" collection
db.rating.dropIndexes();
db.rating.createIndex( { "api" : 1 } );
db.rating.reIndex();
// "ratingAnswers" collection
db.ratingAnswers.dropIndexes();
db.ratingAnswers.createIndex( { "rating" : 1 } );
// "portalnotifications" collection
db.portalnotifications.dropIndexes();
db.portalnotifications.createIndex( { "user" : 1 } );
db.portalnotifications.reIndex();
// "portalnotificationconfigs" collection
db.portalnotificationconfigs.dropIndexes();
db.portalnotificationconfigs.createIndex( {"_id.user":1, "_id.referenceId":1, "_id.referenceType":1}, { unique: true } );
db.portalnotificationconfigs.createIndex( {"_id.referenceId":1, "_id.referenceType":1, "hooks":1});
db.portalnotificationconfigs.reIndex();
// "genericnotificationconfigs" collection
db.genericnotificationconfigs.dropIndexes();
db.genericnotificationconfigs.createIndex( {"referenceId":1, "referenceType":1, "hooks":1});
db.genericnotificationconfigs.createIndex( {"referenceId":1, "referenceType":1});
db.genericnotificationconfigs.reIndex();
================================================
FILE: favorite-file/gravitee-docker-compose/platform/nginx/nginx.conf
================================================
worker_processes 4;
events { worker_connections 1024; }
http {
include /etc/nginx/mime.types;
resolver 127.0.0.11 ipv6=off;
upstream apim_management {
server apim_management:8083;
}
upstream apim_gateway {
server apim_gateway:8082;
}
upstream apim_portal {
server apim_portal:80;
}
upstream am_management {
server am_management:8093;
}
upstream am_gateway {
server am_gateway:8092;
}
upstream am_webui {
server am_webui:80;
}
server {
listen 80;
server_name localhost;
return 301 https://$server_name$request_uri; #Redirection
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name localhost;
ssl_certificate /etc/ssl/certs/gio-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/gio-selfsigned.key;
ssl_dhparam /etc/ssl/certs/gio.pem;
error_page 500 502 503 504 /50x.html;
location /apim/portal/ {
proxy_pass http://apim_portal/;
proxy_redirect $scheme://$host:$server_port/ $scheme://$http_host/apim/portal/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /apim/management/ {
proxy_pass http://apim_management/management/;
proxy_redirect $scheme://$host:$server_port/management/ /apim/management/;
sub_filter "/management/" "/apim/management/";
sub_filter_types application/json;
sub_filter_once off;
proxy_cookie_path /management /apim/management;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /apim/ {
proxy_pass http://apim_gateway/;
proxy_cookie_path / /apim;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
location /am/ui/ {
proxy_pass http://am_webui/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
sub_filter '/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart| reload|orce-reload}"
exit 2
esac
================================================
FILE: favorite-file/shell/crontab-redis-restart.sh
================================================
#!/bin/sh
redis-cli -h 127.0.0.1 -p 6379 -a 123456789 shutdown
sleep 5s
/usr/local/bin/redis-server /etc/redis.conf
================================================
FILE: favorite-file/shell/crontab-test.sh
================================================
#!/bin/sh
time1=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time1}" >> /opt/1.txt
sleep 5s
time2=$(date "+%Y-%m-%d %H:%M:%S")
echo "${time2}" >> /opt/1.txt
================================================
FILE: favorite-file/shell/install_common_tool_CentOS.sh
================================================
#!/bin/sh
echo "开始常用工具安装"
yum install -y zip unzip lrzsz git epel-release wget htop deltarpm
echo "开始常用工具结束"
================================================
FILE: favorite-file/shell/install_common_tool_ubuntu.sh
================================================
#!/bin/sh
echo "开始常用工具安装"
sudo apt-get install -y zip unzip unrar lrzsz git wget htop
echo "开始常用工具结束"
================================================
FILE: favorite-file/shell/install_common_vim.sh
================================================
#!/bin/sh
echo "-----------------------------------------开始常用工具安装"
yum install -y zip unzip lrzsz git epel-release
echo "-----------------------------------------开始安装 vim"
yum install -y vim
echo "-----------------------------------------设置 vim 配置"
curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
================================================
FILE: favorite-file/shell/install_common_vim_zsh.sh
================================================
#!/bin/sh
echo "-----------------------------------------禁用防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
echo "-----------------------------------------开始常用工具安装"
yum install -y zip unzip lrzsz git epel-release
echo "-----------------------------------------开始常用工具结束"
echo "-----------------------------------------开始安装 zsh"
yum install -y zsh
echo "-----------------------------------------开始安装 oh-my-zsh"
wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
echo "-----------------------------------------设置默认终端为 oh-my-zsh"
chsh -s /bin/zsh root
echo "-----------------------------------------开始安装 vim"
yum install -y vim
echo "-----------------------------------------设置 vim 配置"
curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
================================================
FILE: favorite-file/shell/install_docker_centos7.sh
================================================
#!/bin/sh
echo "安装 docker 所需环境"
yum install -y yum-utils device-mapper-persistent-data lvm2
echo "添加 repo(可能网络会很慢,有时候会报:Timeout,所以要多试几次)"
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
echo "开始安装 docker"
yum install -y docker-ce
echo "启动 Docker"
systemctl start docker.service
echo "安装结束"
echo "运行 hello world 镜像"
docker run hello-world
echo "安装 docker compose"
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "输出 docker compose 版本号"
docker-compose --version
systemctl restart docker.service
systemctl enable docker.service
================================================
FILE: favorite-file/shell/install_docker_disable_firewalld_centos7-aliyun.sh
================================================
#!/bin/sh
echo "-----------------------------------------禁用防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
echo "-----------------------------------------安装 docker 所需环境"
yum install -y yum-utils device-mapper-persistent-data lvm2
echo "-----------------------------------------添加 repo(可能网络会很慢,有时候会报:Timeout,所以要多试几次)"
echo "-----------------------------------------官网的地址 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
echo "-----------------------------------------这里用阿里云进行加速,不然可能会出现无法安装,阿里云官网说明:https://help.aliyun.com/document_detail/60742.html"
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
echo "-----------------------------------------开始安装 docker"
yum install -y docker-ce
echo "-----------------------------------------启动 Docker"
systemctl start docker.service
echo "-----------------------------------------安装结束"
echo "-----------------------------------------docker 加速"
touch /etc/docker/daemon.json
cat << EOF >> /etc/docker/daemon.json
{
"registry-mirrors": ["https://ldhc17y9.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
echo "-----------------------------------------运行 hello world 镜像"
docker run hello-world
echo "-----------------------------------------安装 docker compose"
echo "docker compose 的版本检查:https://docs.docker.com/compose/install/#install-compose"
curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "-----------------------------------------输出 docker compose 版本号"
docker-compose --version
================================================
FILE: favorite-file/shell/install_docker_disable_firewalld_centos7.sh
================================================
#!/bin/sh
echo "-----------------------------------------禁用防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
echo "-----------------------------------------安装 docker 所需环境"
yum install -y yum-utils device-mapper-persistent-data lvm2
echo "-----------------------------------------添加 repo(可能网络会很慢,有时候会报:Timeout,所以要多试几次)"
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
echo "-----------------------------------------开始安装 docker"
yum install -y docker-ce
echo "-----------------------------------------启动 Docker"
systemctl start docker.service
echo "-----------------------------------------安装结束"
echo "-----------------------------------------运行 hello world 镜像"
docker run hello-world
echo "-----------------------------------------安装 docker compose"
echo "docker compose 的版本检查:https://docs.docker.com/compose/install/#install-compose"
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "-----------------------------------------输出 docker compose 版本号"
docker-compose --version
systemctl restart docker.service
systemctl enable docker.service
================================================
FILE: favorite-file/shell/install_docker_k8s_disable_firewalld_centos7-aliyun.sh
================================================
#!/bin/sh
echo "-----------------------------------------禁用防火墙"
systemctl stop firewalld.service
systemctl disable firewalld.service
echo "-----------------------------------------安装 docker 所需环境"
yum install -y yum-utils device-mapper-persistent-data lvm2
echo "-----------------------------------------添加 repo(可能网络会很慢,有时候会报:Timeout,所以要多试几次)"
echo "-----------------------------------------官网的地址 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
echo "-----------------------------------------这里用阿里云进行加速,不然可能会出现无法安装,阿里云官网说明:https://help.aliyun.com/document_detail/60742.html"
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
echo "-----------------------------------------开始安装 docker"
yum install -y docker-ce-18.06.1.ce-3.el7
echo "-----------------------------------------启动 Docker"
systemctl start docker.service
systemctl enable docker.service
echo "-----------------------------------------安装结束"
echo "-----------------------------------------docker 加速"
touch /etc/docker/daemon.json
cat << EOF >> /etc/docker/daemon.json
{
"registry-mirrors": ["https://ldhc17y9.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
echo "-----------------------------------------运行 hello world 镜像"
docker run hello-world
================================================
FILE: favorite-file/shell/install_jdk_offline_to_bash.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 JDK 压缩包是否存在"
if [ ! -f "/opt/setups/jdk-8u181-linux-x64.tar.gz" ]; then
echo "JDK 压缩包不存在"
exit 1
fi
echo "开始解压 JDK"
cd /opt/setups ; tar -zxf jdk-8u181-linux-x64.tar.gz
if [ ! -d "/opt/setups/jdk1.8.0_181" ]; then
echo "JDK 解压失败,结束脚本"
exit 1
fi
echo "JDK 解压包移到 /usr/local/ 目录下"
mv jdk1.8.0_181/ /usr/local/
echo "JDK 写入系统变量到 profile"
cat << EOF >> /etc/profile
# JDK
JAVA_HOME=/usr/local/jdk1.8.0_181
JRE_HOME=\$JAVA_HOME/jre
PATH=\$PATH:\$JAVA_HOME/bin
CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
EOF
echo "JDK 设置完成,需要你手动设置:source /etc/profile"
================================================
FILE: favorite-file/shell/install_jdk_offline_to_zsh.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 JDK 压缩包是否存在"
if [ ! -f "/opt/setups/jdk-8u191-linux-x64.tar.gz" ]; then
echo "JDK 压缩包不存在"
exit 1
fi
echo "开始解压 JDK"
cd /opt/setups ; tar -zxf jdk-8u191-linux-x64.tar.gz
if [ ! -d "/opt/setups/jdk1.8.0_191" ]; then
echo "JDK 解压失败,结束脚本"
exit 1
fi
echo "JDK 解压包移到 /usr/local/ 目录下"
mv jdk1.8.0_191/ /usr/local/
echo "JDK 写入系统变量到 zshrc"
cat << EOF >> ~/.zshrc
# JDK
JAVA_HOME=/usr/local/jdk1.8.0_191
JRE_HOME=\$JAVA_HOME/jre
PATH=\$PATH:\$JAVA_HOME/bin
CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
EOF
echo "JDK 设置完成,需要你手动设置:source ~/.zshrc"
================================================
FILE: favorite-file/shell/install_jdk_online.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
if [ ! -d "/usr/program" ]; then
mkdir /usr/program
fi
echo "下载 JDK"
cd /opt/setups
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz
if [ ! -f "/opt/setups/jdk-8u151-linux-x64.tar.gz" ]; then
echo "JDK 下载失败,结束脚本"
exit 1
fi
echo "JDK 下载成功,开始解压 JDK"
tar -zxf jdk-8u151-linux-x64.tar.gz
if [ ! -d "/opt/setups/jdk1.8.0_151" ]; then
echo "JDK 解压失败,结束脚本"
exit 1
fi
echo "JDK 解压包移到 /usr/program/ 目录下"
mv jdk1.8.0_151/ /usr/program/
echo "JDK 写入系统变量到 zshrc"
cat << EOF >> ~/.zshrc
# JDK
JAVA_HOME=/usr/local/jdk1.8.0_151
JRE_HOME=\$JAVA_HOME/jre
PATH=\$PATH:\$JAVA_HOME/bin
CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
EOF
echo "JDK 设置完成,需要你手动设置:source ~/.zshrc"
================================================
FILE: favorite-file/shell/install_maven_offline_to_bash.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 Maven 压缩包是否存在"
if [ ! -f "/opt/setups/apache-maven-3.5.4-bin.tar.gz" ]; then
echo "Maven 压缩包不存在"
exit 1
fi
echo "开始解压 Maven"
cd /opt/setups ; tar -zxf apache-maven-3.5.4-bin.tar.gz
if [ ! -d "/opt/setups/apache-maven-3.5.4" ]; then
echo "Maven 解压失败,结束脚本"
exit 1
fi
echo "Maven 解压包移到 /usr/local/ 目录下"
mv apache-maven-3.5.4/ /usr/local/
echo "Maven 写入系统变量到 profile"
cat << EOF >> /etc/profile
# Maven
M3_HOME=/usr/local/apache-maven-3.5.4
MAVEN_HOME=/usr/local/apache-maven-3.5.4
PATH=\$PATH:\$M3_HOME/bin
MAVEN_OPTS="-Xms256m -Xmx356m"
export M3_HOME
export MAVEN_HOME
export PATH
export MAVEN_OPTS
EOF
echo "Maven 设置完成,需要你手动设置:source /etc/profile"
================================================
FILE: favorite-file/shell/install_maven_offline_to_zsh.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 Maven 压缩包是否存在"
if [ ! -f "/opt/setups/apache-maven-3.5.4-bin.tar.gz" ]; then
echo "Maven 压缩包不存在"
exit 1
fi
echo "开始解压 Maven"
cd /opt/setups ; tar -zxf apache-maven-3.5.4-bin.tar.gz
if [ ! -d "/opt/setups/apache-maven-3.5.4" ]; then
echo "Maven 解压失败,结束脚本"
exit 1
fi
echo "Maven 解压包移到 /usr/local/ 目录下"
mv apache-maven-3.5.4/ /usr/local/
echo "Maven 写入系统变量到 zshrc"
cat << EOF >> ~/.zshrc
# Maven
M3_HOME=/usr/local/apache-maven-3.5.4
MAVEN_HOME=/usr/local/apache-maven-3.5.4
PATH=\$PATH:\$M3_HOME/bin
MAVEN_OPTS="-Xms256m -Xmx356m"
export M3_HOME
export MAVEN_HOME
export PATH
export MAVEN_OPTS
EOF
echo "Maven 设置完成,需要你手动设置:source ~/.zshrc"
================================================
FILE: favorite-file/shell/install_mycat_offline.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断是否有 JDK 环境"
if [ -z $JAVA_HOME ];then
echo "没有 JAVA_HOME 环境变量"
exit 1
fi
echo "判断 /opt 目录下 mycat 压缩包是否存在"
if [ ! -f "/opt/setups/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz" ]; then
echo "mycat 压缩包是否存在不存在"
exit 1
fi
echo "解压压缩包"
cd /opt/setups ; tar -zxf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
echo "把解压后目录移到 /usr/local/ 目录下"
mv /opt/setups/mycat /usr/local/
echo "写入系统变量到 zshrc"
echo 'MYCAT_HOME=/usr/local/mycat' >> ~/.zshrc
echo 'PATH=$PATH:$MYCAT_HOME/bin' >> ~/.zshrc
echo 'export MYCAT_HOME' >> ~/.zshrc
echo 'export PATH' >> ~/.zshrc
echo "mycat 设置完成,需要你手动设置:source ~/.zshrc"
================================================
FILE: favorite-file/shell/install_mysql5.6_offline_centos6.sh
================================================
#!/bin/sh
echo "安装 mysql 开始"
cd /opt/setups
tar zxvf mysql-5.6.35.tar.gz
mv /opt/setups/mysql-5.6.35 /usr/program/
yum install -y make gcc-c++ cmake bison-devel ncurses-devel
cd /usr/program/mysql-5.6.35/
mkdir -p /usr/program/mysql/data
cmake -DCMAKE_INSTALL_PREFIX=/usr/program/mysql -DMYSQL_DATADIR=/usr/program/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1
make
make install
cp /usr/program/mysql-5.6.35/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig mysql on
cp /usr/program/mysql-5.6.35/support-files/my-default.cnf /etc/my.cnf
rm -rf /usr/program/mysql-5.6.35/
groupadd mysql
useradd -g mysql mysql -s /bin/false
chown -R mysql:mysql /usr/program/mysql/data
/usr/program/mysql/scripts/mysql_install_db --basedir=/usr/program/mysql --datadir=/usr/program/mysql/data --skip-name-resolve --user=mysql
ln -s /usr/program/mysql/bin/mysql /usr/bin
ln -s /usr/program/mysql/bin/mysqladmin /usr/bin
ln -s /usr/program/mysql/bin/mysqldump /usr/bin
ln -s /usr/program/mysql/bin/mysqlslap /usr/bin
iptables -I INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
service iptables save
service iptables restart
echo "安装 mysql 结束,现在需要手动设置防火墙和禁用 selinux."
================================================
FILE: favorite-file/shell/install_mysql5.6_offline_centos7.sh
================================================
#!/bin/sh
echo "安装 mysql 开始"
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 JDK 压缩包是否存在"
if [ ! -f "/opt/setups/mysql-5.6.35.tar.gz" ]; then
echo "mysql 压缩包不存在"
exit 1
fi
cd /opt/setups
tar zxvf mysql-5.6.35.tar.gz
mv /opt/setups/mysql-5.6.35 /usr/local/
yum install -y make gcc-c++ cmake bison-devel ncurses-devel autoconf
cd /usr/local/mysql-5.6.35/
mkdir -p /usr/local/mysql/data
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1
make
make install
cp /usr/local/mysql-5.6.35/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig mysql on
cp /usr/local/mysql-5.6.35/support-files/my-default.cnf /etc/my.cnf
rm -rf /usr/local/mysql-5.6.35/
groupadd mysql
useradd -g mysql mysql -s /bin/false
chown -R mysql:mysql /usr/local/mysql/data
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --skip-name-resolve --user=mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
ln -s /usr/local/mysql/bin/mysqldump /usr/bin
ln -s /usr/local/mysql/bin/mysqlslap /usr/bin
echo "防火墙放行 3306 端口"
systemctl restart firewalld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
systemctl stop firewalld.service
echo "安装 mysql 结束,现在需要手动设置防火墙和禁用 selinux."
================================================
FILE: favorite-file/shell/install_mysql5.7_offline_centos7.sh
================================================
#!/bin/sh
echo "安装 mysql 开始"
echo "必须准备两个文件:mysql-5.7.21.tar.gz 和 boost_1_59_0.tar.gz"
echo "mysql 5.7 依赖 boost,官网说明:https://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.7/en/source-installation.html"
echo "boost 下载地址(79M):http://www.boost.org/users/history/version_1_59_0.html"
if [ ! -f "/opt/setups/mysql-5.7.21.tar.gz" ]; then
echo "缺少 mysql-5.7.21.tar.gz 文件,结束脚本"
exit 1
fi
if [ ! -f "/opt/setups/boost_1_59_0.tar.gz" ]; then
echo "缺少 boost_1_59_0.tar.gz 文件,结束脚本"
exit 1
fi
cd /opt/setups
tar zxvf mysql-5.7.21.tar.gz
mv /opt/setups/mysql-5.7.21 /usr/local/
tar zxvf boost_1_59_0.tar.gz
mv /opt/setups/boost_1_59_0 /usr/local/
yum install -y make gcc-c++ cmake bison-devel ncurses-devel
cd /usr/local/mysql-5.7.21/
mkdir -p /usr/local/mysql/data
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost_1_59_0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1
make
make install
cp /usr/local/mysql-5.7.21/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig mysql on
echo "mysql 5.7 这个文件没了,需要自己创建一个"
cp /usr/local/mysql-5.7.21/support-files/my-default.cnf /etc/my.cnf
rm -rf /usr/local/mysql-5.7.21/
groupadd mysql
useradd -g mysql mysql -s /bin/false
chown -R mysql:mysql /usr/local/mysql/data
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --skip-name-resolve --user=mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
ln -s /usr/local/mysql/bin/mysqldump /usr/bin
ln -s /usr/local/mysql/bin/mysqlslap /usr/bin
echo "防火墙放行 3306 端口"
systemctl restart firewalld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
systemctl stop firewalld.service
echo "安装 mysql 结束,现在需要手动设置防火墙和禁用 selinux."
================================================
FILE: favorite-file/shell/install_nginx_centos6.sh
================================================
#!/bin/sh
echo "安装 nginx"
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
if [ ! -d "/usr/program" ]; then
mkdir /usr/program
fi
if [ ! -d "/usr/local/nginx" ]; then
mkdir -p /usr/local/nginx
fi
if [ ! -d "/var/log/nginx" ]; then
mkdir -p /var/log/nginx
fi
if [ ! -d "/var/temp/nginx" ]; then
mkdir -p /var/temp/nginx
fi
if [ ! -d "/var/lock/nginx" ]; then
mkdir -p /var/lock/nginx
fi
echo "下载 Nginx"
cd /opt/setups
wget https://nginx.org/download/nginx-1.12.2.tar.gz
if [ ! -f "/opt/setups/nginx-1.12.2.tar.gz" ]; then
echo "Nginx 下载失败,结束脚本"
exit 1
fi
echo "Nginx 下载成功,开始解压 Nginx"
tar -zxf nginx-1.12.2.tar.gz
if [ ! -d "/opt/setups/nginx-1.12.2" ]; then
echo "Nginx 解压失败,结束脚本"
exit 1
fi
echo "安装源码安装依赖"
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
echo "开始安装 Nginx"
cd nginx-1.12.2/
./configure --prefix=/usr/local/nginx --pid-path=/var/local/nginx/nginx.pid --lock-path=/var/lock/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --with-http_ssl_module --http-scgi-temp-path=/var/temp/nginx/scgi
make
make install
echo "防火墙放行 80 端口"
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart
echo "启动 Nginx"
/usr/local/nginx/sbin/nginx
================================================
FILE: favorite-file/shell/install_nginx_centos7.sh
================================================
#!/bin/sh
echo "安装 nginx"
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
if [ ! -d "/usr/local/nginx" ]; then
mkdir -p /usr/local/nginx
fi
if [ ! -d "/var/log/nginx" ]; then
mkdir -p /var/log/nginx
fi
if [ ! -d "/var/temp/nginx" ]; then
mkdir -p /var/temp/nginx
fi
if [ ! -d "/var/lock/nginx" ]; then
mkdir -p /var/lock/nginx
fi
echo "下载 Nginx"
cd /opt/setups
wget https://nginx.org/download/nginx-1.14.0.tar.gz
if [ ! -f "/opt/setups/nginx-1.14.0.tar.gz" ]; then
echo "Nginx 下载失败,结束脚本"
exit 1
fi
echo "Nginx 下载成功,开始解压 Nginx"
tar -zxf nginx-1.14.0.tar.gz
if [ ! -d "/opt/setups/nginx-1.14.0" ]; then
echo "Nginx 解压失败,结束脚本"
exit 1
fi
echo "安装源码安装依赖"
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
echo "开始安装 Nginx"
cd nginx-1.14.0/
./configure --prefix=/usr/local/nginx --pid-path=/var/local/nginx/nginx.pid --lock-path=/var/lock/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --with-http_ssl_module --http-scgi-temp-path=/var/temp/nginx/scgi
make
make install
echo "防火墙放行 80 端口"
systemctl restart firewalld.service
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld.service
echo "启动 Nginx"
/usr/local/nginx/sbin/nginx
================================================
FILE: favorite-file/shell/install_redis_centos6.sh
================================================
#!/bin/sh
echo "安装 redis"
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
if [ ! -d "/usr/program" ]; then
mkdir /usr/program
fi
echo "下载 redis"
cd /opt/setups
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
if [ ! -f "/opt/setups/redis-4.0.6.tar.gz" ]; then
echo "redis 下载失败,结束脚本"
exit 1
fi
echo "reids 下载成功"
echo "安装开始"
yum install -y gcc-c++ tcl
cd /opt/setups
tar zxvf redis-4.0.6.tar.gz
if [ ! -d "/opt/setups/redis-4.0.6" ]; then
echo "redis 解压失败,结束脚本"
exit 1
fi
mv redis-4.0.6/ /usr/program/
cd /usr/program/redis-4.0.6
make
make install
cp /usr/program/redis-4.0.6/redis.conf /etc/
sed -i 's/daemonize no/daemonize yes/g' /etc/redis.conf
echo "/usr/local/bin/redis-server /etc/redis.conf" >> /etc/rc.local
iptables -I INPUT -p tcp -m tcp --dport 6379 -j ACCEPT
service iptables save
service iptables restart
rm -rf /usr/program/redis-4.0.6
echo "安装结束"
================================================
FILE: favorite-file/shell/install_redis_centos7.sh
================================================
#!/bin/sh
echo "安装 redis"
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "下载 redis"
cd /opt/setups
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
if [ ! -f "/opt/setups/redis-4.0.6.tar.gz" ]; then
echo "redis 下载失败,结束脚本"
exit 1
fi
echo "reids 下载成功"
echo "安装开始"
yum install -y gcc-c++ tcl
cd /opt/setups
tar zxvf redis-4.0.6.tar.gz
if [ ! -d "/opt/setups/redis-4.0.6" ]; then
echo "redis 解压失败,结束脚本"
exit 1
fi
mv redis-4.0.6/ /usr/local/
cd /usr/local/redis-4.0.6
make
make install
cp /usr/local/redis-4.0.6/redis.conf /etc/
sed -i 's/daemonize no/daemonize yes/g' /etc/redis.conf
echo "/usr/local/bin/redis-server /etc/redis.conf" >> /etc/rc.local
echo "防火墙放行 6379 端口"
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
rm -rf /usr/local/redis-4.0.6
echo "安装结束"
================================================
FILE: favorite-file/shell/install_tomcat_centos6.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
if [ ! -d "/usr/program" ]; then
mkdir /usr/program
fi
echo "下载 Tomcat"
cd /opt/setups
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.47/bin/apache-tomcat-8.0.47.tar.gz
if [ ! -f "/opt/setups/apache-tomcat-8.0.47.tar.gz" ]; then
echo "Tomcat 下载失败,结束脚本"
exit 1
fi
echo "Tomcat 下载成功,开始解压 Tomcat"
tar -zxf apache-tomcat-8.0.47.tar.gz
if [ ! -d "/opt/setups/apache-tomcat-8.0.47" ]; then
echo "Tomcat 解压失败,结束脚本"
exit 1
fi
echo "Tomcat 解压包移到 /usr/program/ 目录下"
mv apache-tomcat-8.0.47/ /usr/program/
mv /usr/program/apache-tomcat-8.0.47/ /usr/program/tomcat8/
echo "防火墙放行 8080 端口"
iptables -I INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
service iptables save
service iptables restart
echo "运行 Tomcat"
sh /usr/program/tomcat8/bin/startup.sh ; tail -200f /usr/program/tomcat8/logs/catalina.out
================================================
FILE: favorite-file/shell/install_tomcat_centos7.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "下载 Tomcat"
cd /opt/setups
wget http://apache.fayea.com/tomcat/tomcat-8/v8.0.46/bin/apache-tomcat-8.0.46.tar.gz
if [ ! -f "/opt/setups/apache-tomcat-8.0.46.tar.gz" ]; then
echo "Tomcat 下载失败,结束脚本"
exit 1
fi
echo "Tomcat 下载成功,开始解压 Tomcat"
tar -zxf apache-tomcat-8.0.46.tar.gz
if [ ! -d "/opt/setups/apache-tomcat-8.0.46" ]; then
echo "Tomcat 解压失败,结束脚本"
exit 1
fi
echo "Tomcat 解压包移到 /usr/local/ 目录下"
mv apache-tomcat-8.0.46/ /usr/local/
mv /usr/local/apache-tomcat-8.0.46/ /usr/local/tomcat8/
echo "防火墙放行 8080 端口"
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
echo "运行 Tomcat"
sh /usr/local/tomcat8/bin/startup.sh ; tail -200f /usr/local/tomcat8/logs/catalina.out
================================================
FILE: favorite-file/shell/install_tomcat_offline_centos7.sh
================================================
#!/bin/sh
echo "判断常见的文件夹是否存在"
if [ ! -d "/opt/setups" ]; then
mkdir /opt/setups
fi
echo "判断 tomcat 压缩包是否存在"
if [ ! -f "/opt/setups/apache-tomcat-8.0.46.tar.gz" ]; then
echo "JDK 压缩包不存在"
exit 1
fi
cd /opt/setups
echo "开始解压 Tomcat"
tar -zxf apache-tomcat-8.0.46.tar.gz
if [ ! -d "/opt/setups/apache-tomcat-8.0.46" ]; then
echo "Tomcat 解压失败,结束脚本"
exit 1
fi
echo "Tomcat 解压包移到 /usr/local/ 目录下"
mv apache-tomcat-8.0.46/ /usr/local/
mv /usr/local/apache-tomcat-8.0.46/ /usr/local/tomcat8/
echo "防火墙放行 8080 端口"
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
echo "运行 Tomcat"
sh /usr/local/tomcat8/bin/startup.sh ; tail -200f /usr/local/tomcat8/logs/catalina.out
================================================
FILE: favorite-file/shell/mysql_backup.sh
================================================
#!/bin/bash
backupDatetime=$1
if [ "$backupDatetime" = "" ];
then
echo -e "\033[0;31m 请输入备份日期 \033[0m"
exit 1
fi
echo "备份日期 = $backupDatetime"
/usr/bin/mysqldump -u root --password=123456 数据库名 > /opt/mydb-"$backupDatetime".sql
================================================
FILE: favorite-file/shell/repo_install_centos6.sh
================================================
#!/bin/sh
# 本文原内容来自:https://github.com/judasn/Linux-Tutorial/blob/master/CentOS-Extra-Packages.md
echo "源设置开始"
echo "备份默认源设置"
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
cd /etc/yum.repos.d/
echo "下载网易 centos6 源"
sudo wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
echo "安装网易 centos6 源"
sudo mv CentOS6-Base-163.repo CentOS-Base.repo
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
echo "清除缓存后更新程序"
sudo yum clean all
sudo yum makecache
sudo yum update -y
echo "使用第三方源"
echo "安装 EPEL 源"
sudo yum install -y epel-release
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
echo "安装 RepoForge 源"
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
sudo rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
echo "清除缓存后更新程序"
sudo yum clean all
sudo yum makecache
sudo yum update -y
echo "测试安装 htop"
sudo yum install -y htop
echo "完成源设置"
================================================
FILE: favorite-file/shell/shell-for.sh
================================================
#!/bin/bash
# 循环总次数
totalDegree=$1
# 如果没有传参,则默认值是 10
if [ "$totalDegree" = "" ];
then
totalDegree=10
fi
for((timeTemp = 0; timeTemp <= $totalDegree; timeTemp = timeTemp + 5))
do
echo "timeTemp=$timeTemp"
done
================================================
FILE: favorite-file/shell/shell-with-param-demo.sh
================================================
#!/bin/bash
methodParam=$1
SpringBoot=$2
SpringBootPath=$3
if [ "$methodParam" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$SpringBoot" = "" ];
then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi
if [ "$SpringBootPath" = "" ];
then
echo -e "\033[0;31m 未输入应用路径 \033[0m"
exit 1
fi
echo "操作名 = $methodParam"
echo "应用名 = $2"
echo "应用路径 = $3"
function start()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "Start $SpringBoot success..."
cd $SpringBootPath
BUILD_ID=dontKillMe nohup java -jar $SpringBoot > /opt/run-log.log 2>&1 &
fi
}
function stop()
{
echo "Stop $SpringBoot"
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
kill $boot_id
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
kill -9 $boot_id
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "$SpringBoot is not running..."
fi
}
case $methodParam in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
echo -e "\033[0;31m Usage: \033[0m \033[0;34m sh $0 {start|stop|restart|status} {SpringBootJarName} \033[0m\033[0;31m Example: \033[0m\033[0;33m sh $0 start esmart-test.jar \033[0m"
esac
================================================
FILE: favorite-file/zsh/.zshrc
================================================
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/root/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="avit"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
JAVA_HOME=/usr/program/jdk1.8.0_121
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
================================================
FILE: markdown-file/Alfresco-Install-And-Usage.md
================================================
# Alfresco 使用
## Alfresco 介绍
- 官网:
- 开源社区版下载:
- 官网文档说明:
- 开源社区版本安装说明:
- Linux 版本安装说明:
- 我的目的:用来管理公司发布的文档,比如:Word、Excel、记事本等这类,该系统支持在线预览文件。
## 环境说明
- CentOS 7.3 带有图形桌面(需要有)
- 下载下来的软件:**alfresco-community-installer-201704-linux-x64_3.bin**,大小:822M
- 安装包存放目录:/opt
## 开始安装:
- 使用 Linux 桌面方式进入系统,打开终端:
- 切换目录:`cd /opt`
- 赋予权限:`chmod +x alfresco-community-installer-201704-linux-x64_3.bin`
- `./alfresco-community-installer-201704-linux-x64_3.bin`
- 然后会出现如下图这种步骤引导安装界面,带有简体中文版,选择 `简单` 的基本流程安装方式,默认都是下一步下一步。其实选择 `高级` 也基本上是下一步下一步的,只是可以看到更多细节。
- 在设置管理员密码上,我是:123456(默认用户名是:admin)


- 安装完成后,可以选择开始启动程序。建议不勾选,我们来使用下面命令。
- 程序默认是安装在:**/opt/alfresco-community**
- 所以我们需要打开终端:
- 切换目录:`cd /opt/alfresco-community`
- 启动程序:`./alfresco.sh start`
- 停止程序:`./alfresco.sh stop`
- 启动完成后,用浏览器打开:(如果你 Linux 防火墙关闭了,也可以直接用其他机子直接访问,把这台机子当做服务器用),可以看到如下内容:


================================================
FILE: markdown-file/Ansible-Install-And-Settings.md
================================================
# Ansible 安装和配置
## Ansible 说明
- Ansible 官网:
- Ansible 官网 Github:
- Ansible 官网文档:
- 简单讲:它的作用就是把写 shell 这件事变成标准化、模块化。方便更好的自动化运维
## 安装
- 官网说明:
- CentOS:`sudo yum install -y ansible`
- 查看版本:`ansible --version`
-------------------------------------------------------------------
## 配置基本概念
#### Ansible 基本配置文件顺序
- Ansible 执行的时候会按照以下顺序查找配置项,所以修改的时候要特别注意改的是哪个文件
```
ANSIBLE_CONFIG (环境变量)
ansible.cfg (脚本所在当前目录下)
~/.ansible.cfg (用户家目录下,默认没有)
/etc/ansible/ansible.cfg(安装后会自动生成)
```
#### 配置远程主机地址 (Ansible 称这些地址为 Inventory)
- 假设我有 3 台机子:
- 192.168.0.223
- 192.168.0.70
- 192.168.0.103
- 官网对此的配置说明:
###### 给这三台机子设置免密登录的情况(一般推荐方式)
- 编辑 Ansible 配置文件:`vim /etc/ansible/hosts`
- 添加如下内容
```
[hadoop-host]
192.168.0.223
192.168.0.70
192.168.0.103
```
- 其中 `[hadoop-host]` 表示这些主机代表的一个组名
###### 如果不设置免密,直接采用账号密码(容易泄露信息)
- 编辑 Ansible 配置文件:`vim /etc/ansible/hosts`
- 添加如下内容
```
[hadoop-host]
hadoop-master ansible_host=192.168.0.223 ansible_user=root ansible_ssh_pass=123456
hadoop-node1 ansible_host=192.168.0.70 ansible_user=root ansible_ssh_pass=123456
hadoop-node2 ansible_host=192.168.0.103 ansible_user=root ansible_ssh_pass=123456
```
## 简单使用(`ad hoc`方式)
- ad hoc 官网:
##### 运行 Ansible
- 运行 Ansible 的 `ping` 命令,看看配置正确时输出如下:
```
sudo ansible --private-key ~/.ssh/id_rsa all -m ping
```
- 让远程所有主机都执行 `ps` 命令,输出如下
```
ansible all -a 'ps'
```
- 让远程所有 hadoop-host 组的主机都执行 `ps` 命令,输出如下
```
ansible hadoop-host -a 'ps'
```
-------------------------------------------------------------------
## Playbook 脚本方式
- 官网:
- 一些语法:
- playbook(剧本),顾名思义,就是需要定义一个脚本或者说配置文件,然后定义好要做什么。之后 ansible 就会根据 playbook 脚本对远程主机进行操作
#### 简单脚本
- 下面脚本让所有远程主机执行 `whoami` 命令,并把结果(当前用户名)输出到 `/opt/whoami.txt` 文件
- 创建脚本文件:`vim /opt/simple-playbook.yml`
```
- hosts: all
tasks:
- name: whoami
shell: 'whoami > /opt/whoami.txt'
```
- 执行命令:`ansible-playbook /opt/simple-playbook.yml`,结果如下,并且 opt 下也有文件生成
```
PLAY [all] **************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************
ok: [192.168.0.223]
ok: [192.168.0.103]
ok: [192.168.0.70]
TASK [whoami] ***********************************************************************************************************************
changed: [192.168.0.103]
changed: [192.168.0.223]
changed: [192.168.0.70]
PLAY RECAP **************************************************************************************************************************
192.168.0.103 : ok=2 changed=1 unreachable=0 failed=0
192.168.0.223 : ok=2 changed=1 unreachable=0 failed=0
192.168.0.70 : ok=2 changed=1 unreachable=0 failed=0
```
-------------------------------------------------------------------
## 平时用来测试
- 创建脚本文件:`vim /opt/test-playbook.yml`
```
- hosts: hadoop-test
remote_user: root
vars:
java_install_folder: /usr/local
tasks:
# 按行的方式写入
- name: Set JAVA_HOME 1
lineinfile:
dest=/etc/profile
line="JAVA_HOME={{ java_install_folder }}/jdk1.8.0_181"
# 按块的方式写入,#{mark} 会被自动替换成:begin 和 end 字符来包裹整块内容(我这里自己定义了词语)
- name: Set JAVA_HOME 2
blockinfile:
path: /etc/profile
marker: "#{mark} JDK ENV"
marker_begin: "开始"
marker_end: "结束"
block: |
export JAVA_HOME={{ java_install_folder }}/jdk1.8.0_181
export PATH=$PATH:$JAVA_HOME/bin
```
- 执行命令:`ansible-playbook /opt/test-playbook.yml`
-------------------------------------------------------------------
## 更多 playbook 实战
#### 禁用防火墙(CentOS 7.x)
- 创建脚本文件:`vim /opt/disable-firewalld-playbook.yml`
```
- hosts: all
remote_user: root
tasks:
- name: Disable SELinux at next reboot
selinux:
state: disabled
- name: disable firewalld
command: "{{ item }}"
with_items:
- systemctl stop firewalld
- systemctl disable firewalld
- setenforce 0
```
#### 基础环境(CentOS 7.x)
- 创建脚本文件:`vim /opt/install-basic-playbook.yml`
```
- hosts: all
remote_user: root
tasks:
- name: Disable SELinux at next reboot
selinux:
state: disabled
- name: disable firewalld
command: "{{ item }}"
with_items:
- systemctl stop firewalld
- systemctl disable firewalld
- setenforce 0
- name: install-basic
command: "{{ item }}"
with_items:
- yum install -y zip unzip lrzsz git epel-release wget htop deltarpm
- name: install-vim
shell: "{{ item }}"
with_items:
- yum install -y vim
- curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
- name: install-docker
shell: "{{ item }}"
with_items:
- yum install -y yum-utils device-mapper-persistent-data lvm2
- yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- yum makecache fast
- yum install -y docker-ce
- systemctl start docker.service
- docker run hello-world
- name: install-docker-compose
shell: "{{ item }}"
with_items:
- curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker-compose --version
- systemctl restart docker.service
- systemctl enable docker.service
```
- 执行命令:`ansible-playbook /opt/install-basic-playbook.yml`
#### 修改 hosts
- 创建脚本文件:`vim /opt/hosts-playbook.yml`
```
- hosts: all
remote_user: root
tasks:
- name: update hosts
blockinfile:
path: /etc/hosts
block: |
192.168.0.223 linux01
192.168.0.223 linux02
192.168.0.223 linux03
192.168.0.223 linux04
192.168.0.223 linux05
```
- 执行命令:`ansible-playbook /opt/hosts-playbook.yml`
#### 部署 JDK
- 创建脚本文件:`vim /opt/jdk8-playbook.yml`
```
- hosts: hadoop-host
remote_user: root
vars:
java_install_folder: /usr/local
tasks:
- name: copy jdk
copy: src=/opt/jdk-8u181-linux-x64.tar.gz dest={{ java_install_folder }}
- name: tar jdk
shell: chdir={{ java_install_folder }} tar zxf jdk-8u181-linux-x64.tar.gz
- name: set JAVA_HOME
blockinfile:
path: /etc/profile
marker: "#{mark} JDK ENV"
block: |
JAVA_HOME={{ java_install_folder }}/jdk1.8.0_181
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export JRE_HOME
export PATH
export CLASSPATH
- name: source profile
shell: source /etc/profile
```
- 执行命令:`ansible-playbook /opt/jdk8-playbook.yml`
#### 部署 Hadoop 集群
- 创建脚本文件:`vim /opt/hadoop-playbook.yml`
- 刚学 Ansible,不好动配置文件,所以就只保留环境部分的设置,其他部分自行手工~
```
- hosts: hadoop-host
remote_user: root
tasks:
- name: Creates directory
file:
path: /data/hadoop/hdfs/name
state: directory
- name: Creates directory
file:
path: /data/hadoop/hdfs/data
state: directory
- name: Creates directory
file:
path: /data/hadoop/hdfs/tmp
state: directory
- name: set HADOOP_HOME
blockinfile:
path: /etc/profile
marker: "#{mark} HADOOP ENV"
block: |
HADOOP_HOME=/usr/local/hadoop
PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export HADOOP_HOME
export PATH
- name: source profile
shell: source /etc/profile
```
- 执行命令:`ansible-playbook /opt/hadoop-playbook.yml`
-------------------------------------------------------------------
## 资料
- [ANSIBLE模块 - shell和command区别](https://www.jianshu.com/p/081139f73613)
-
-
-
================================================
FILE: markdown-file/Bash-Other-Bash.md
================================================
# Bash 其他常用命令
## 其他常用命令
- 编辑 hosts 文件:`vim /etc/hosts`,添加内容格式:`127.0.0.1 www.youmeek.com`
- RPM 文件操作命令:
- 安装
- `rpm -i example.rpm`,安装 example.rpm 包
- `rpm -iv example.rpm`,安装 example.rpm 包并在安装过程中显示正在安装的文件信息
- `rpm -ivh example.rpm`,安装 example.rpm 包并在安装过程中显示正在安装的文件信息及安装进度
- 查询
- `rpm -qa | grep jdk`,查看 jdk 是否被安装
- `rpm -ql jdk`,查看 jdk 是否被安装
- 卸载
- `rpm -e jdk`,卸载 jdk(一般卸载的时候都要先用 rpm -qa 看下整个软件的全名)
- YUM 软件管理:
- `yum install -y httpd`,安装 apache
- `yum remove -y httpd`,卸载 apache
- `yum info -y httpd`,查看 apache 版本信息
- `yum list --showduplicates httpd`,查看可以安装的版本
- `yum install httpd-查询到的版本号`,安装指定版本
- 更多命令可以看:
- 查看某个配置文件,排除掉里面以 # 开头的注释内容:
- `grep '^[^#]' /etc/openvpn/server.conf`
- 查看某个配置文件,排除掉里面以 # 开头和 ; 开头的注释内容:
- `grep '^[^#;]' /etc/openvpn/server.conf`
## 资料
-
================================================
FILE: markdown-file/Bash.md
================================================
# Bash 常用命令
## 基础常用命令
- `某个命令 --h`,对这个命令进行解释
- `某个命令 --help`,解释这个命令(更详细)
- `man某个命令`,文档式解释这个命令(更更详细)(执行该命令后,还可以按/+关键字进行查询结果的搜索)
- `Ctrl + c`,结束命令
- `TAB键`,自动补全命令(按一次自动补全,连续按两次,提示所有以输入开头字母的所有命令)
- `键盘上下键`,输入临近的历史命令
- `history`,查看所有的历史命令
- `Ctrl + r`,进入历史命令的搜索功能模式
- `clear`,清除屏幕里面的所有命令
- `pwd`,显示当前目录路径(常用)
- `firefox&`,最后后面的 **&** 符号,表示使用后台方式打开 Firefox,然后显示该进程的 PID 值
- `jobs`,查看后台运行的程序列表
- `ifconfig`,查看内网 IP 等信息(常用)
- `curl ifconfig.me`,查看外网 IP 信息
- `curl ip.cn`,查看外网 IP 信息
- `locate 搜索关键字`,快速搜索系统文件/文件夹(类似 Windows 上的 everything 索引式搜索)(常用)
- `updatedb`,配合上面的 locate,给 locate 的索引更新(locate 默认是一天更新一次索引)(常用)
- `date`,查看系统时间(常用)
- `date -s20080103`,设置日期(常用)
- `date -s18:24`,设置时间,如果要同时更改 BIOS 时间,再执行 `hwclock --systohc`(常用)
- `cal`,在终端中查看日历,肯定没有农历显示的
- `uptime`,查看系统已经运行了多久,当前有几个用户等信息(常用)
- `cat 文件路名`,显示文件内容(属于打印语句)
- `cat -n 文件名`,显示文件,并每一行内容都编号
- `more 文件名`,用分页的方式查看文件内容(按 space 翻下一页,按 *Ctrl + B* 返回上页)
- `less`文件名,用分页的方式查看文件内容(带上下翻页)
- 按 **j** 向下移动,按 **k** 向上移动
- 按 **/** 后,输入要查找的字符串内容,可以对文件进行向下查询,如果存在多个结果可以按 **n** 调到下一个结果出
- 按 **?** 后,输入要查找的字符串内容,可以对文件进行向上查询,如果存在多个结果可以按 **n** 调到下一个结果出
- `shutdown`
- `shutdown -hnow`,立即关机
- `shutdown -h+10`,10 分钟后关机
- `shutdown -h23:30`,23:30 关机
- `shutdown -rnew`,立即重启
- `poweroff`,立即关机(常用)
- `reboot`,立即重启(常用)
- `zip mytest.zip /opt/test/`,把 /opt 目录下的 test/ 目录进行压缩,压缩成一个名叫 mytest 的 zip 文件
- `unzip mytest.zip`,对 mytest.zip 这个文件进行解压,解压到当前所在目录
- `unzip mytest.zip -d /opt/setups/`,对 mytest.zip 这个文件进行解压,解压到 /opt/setups/ 目录下
- `tar -cvf mytest.tar mytest/`,对 mytest/ 目录进行归档处理(归档和压缩不一样)
- `tar -xvf mytest.tar`,释放 mytest.tar 这个归档文件,释放到当前目录
- `tar -xvf mytest.tar -C /opt/setups/`,释放 mytest.tar 这个归档文件,释放到 /opt/setups/ 目录下
- `last`,显示最近登录的帐户及时间
- `lastlog`,显示系统所有用户各自在最近登录的记录,如果没有登录过的用户会显示 **从未登陆过**
- `ls`,列出当前目录下的所有没有隐藏的文件 / 文件夹。
- `ls -a`,列出包括以.号开头的隐藏文件 / 文件夹(也就是所有文件)
- `ls -R`,显示出目录下以及其所有子目录的文件 / 文件夹(递归地方式,不显示隐藏的文件)
- `ls -a -R`,显示出目录下以及其所有子目录的文件 / 文件夹(递归地方式,显示隐藏的文件)
- `ls -al`,列出目录下所有文件(包含隐藏)的权限、所有者、文件大小、修改时间及名称(也就是显示详细信息)
- `ls -ld 目录名`,显示该目录的基本信息
- `ls -t`,依照文件最后修改时间的顺序列出文件名。
- `ls -F`,列出当前目录下的文件名及其类型。以 **/** 结尾表示为目录名,以 **\*** 结尾表示为可执行文件,以 **@** 结尾表示为符号连接
- `ls -lg`,同上,并显示出文件的所有者工作组名。
- `ls -lh`,查看文件夹类文件详细信息,文件大小,文件修改时间
- `ls /opt | head -5`,显示 opt 目录下前 5 条记录
- `ls -l | grep '.jar'`,查找当前目录下所有 jar 文件
- `ls -l /opt |grep "^-"|wc -l`,统计 opt 目录下文件的个数,不会递归统计
- `ls -lR /opt |grep "^-"|wc -l`,统计 opt 目录下文件的个数,会递归统计
- `ls -l /opt |grep "^d"|wc -l`,统计 opt 目录下目录的个数,不会递归统计
- `ls -lR /opt |grep "^d"|wc -l`,统计 opt 目录下目录的个数,会递归统计
- `ls -lR /opt |grep "js"|wc -l`,统计 opt 目录下 js 文件的个数,会递归统计
- `ls -l`,列出目录下所有文件的权限、所有者、文件大小、修改时间及名称(也就是显示详细信息,不显示隐藏文件)。显示出来的效果如下:
``` nginx
-rwxr-xr-x. 1 root root 4096 3月 26 10:57,其中最前面的 - 表示这是一个普通文件
lrwxrwxrwx. 1 root root 4096 3月 26 10:57,其中最前面的 l 表示这是一个链接文件,类似 Windows 的快捷方式
drwxr-xr-x. 5 root root 4096 3月 26 10:57,其中最前面的 d 表示这是一个目录
```
- `cd`,目录切换
- `cd ..`,改变目录位置至当前目录的父目录(上级目录)。
- `cd ~`,改变目录位置至用户登录时的工作目录。
- `cd 回车`,回到家目录
- `cd -`,上一个工作目录
- `cd dir1/`,改变目录位置至 dir1 目录下。
- `cd ~user`,改变目录位置至用户的工作目录。
- `cd ../user`,改变目录位置至相对路径user的目录下。
- `cd /../..`,改变目录位置至绝对路径的目录位置下。
- `cp 源文件 目标文件`,复制文件
- `cp -r 源文件夹 目标文件夹`,复制文件夹
- `cp -r -v 源文件夹 目标文件夹`,复制文件夹(显示详细信息,一般用于文件夹很大,需要查看复制进度的时候)
- `cp /usr/share/easy-rsa/2.0/keys/{ca.crt,server.{crt,key},dh2048.pem,ta.key} /etc/openvpn/keys/`,复制同目录下花括号中的文件
- `tar cpf - . | tar xpf - -C /opt`,复制当前所有文件到 /opt 目录下,一般如果文件夹文件多的情况下用这个更好,用 cp 比较容易出问题
- `mv 文件 目标文件夹`,移动文件到目标文件夹
- `mv 文件`,不指定目录重命名后的名字,用来重命名文件
- `touch 文件名`,创建一个空白文件/更新已有文件的时间(后者少用)
- `mkdir 文件夹名`,创建文件夹
- `mkdir -p /opt/setups/nginx/conf/`,创建一个名为 conf 文件夹,如果它的上级目录 nginx 没有也会跟着一起生成,如果有则跳过
- `rmdir 文件夹名`,删除文件夹(只能删除文件夹里面是没有东西的文件夹)
- `rm 文件`,删除文件
- `rm -r 文件夹`,删除文件夹
- `rm -r -i 文件夹`,在删除文件夹里的文件会提示(要的话,在提示后面输入yes)
- `rm -r -f 文件夹`,强制删除
- `rm -r -f 文件夹1/ 文件夹2/ 文件夹3/`删除多个
- `find`,高级查找
- `find . -name *lin*`,其中 . 代表在当前目录找,-name 表示匹配文件名 / 文件夹名,\*lin\* 用通配符搜索含有lin的文件或是文件夹
- `find . -iname *lin*`,其中 . 代表在当前目录找,-iname 表示匹配文件名 / 文件夹名(忽略大小写差异),\*lin\* 用通配符搜索含有lin的文件或是文件夹
- `find / -name *.conf`,其中 / 代表根目录查找,*.conf代表搜索后缀会.conf的文件
- `find /opt -name .oh-my-zsh`,其中 /opt 代表目录名,.oh-my-zsh 代表搜索的是隐藏文件 / 文件夹名字为 oh-my-zsh 的
- `find /opt -type f -iname .oh-my-zsh`,其中 /opt 代表目录名,-type f 代表只找文件,.oh-my-zsh 代表搜索的是隐藏文件名字为 oh-my-zsh 的
- `find /opt -type d -iname .oh-my-zsh`,其中 /opt 代表目录名,-type d 代表只找目录,.oh-my-zsh 代表搜索的是隐藏文件夹名字为 oh-my-zsh 的
- `find . -name "lin*" -exec ls -l {} \;`,当前目录搜索lin开头的文件,然后用其搜索后的结果集,再执行ls -l的命令(这个命令可变,其他命令也可以),其中 -exec 和 {} \; 都是固定格式
- `find /opt -type f -size +800M -print0 | xargs -0 du -h | sort -nr`,找出 /opt 目录下大于 800 M 的文件
- `find / -name "*tower*" -exec rm {} \;`,找到文件并删除
- `find / -name "*tower*" -exec mv {} /opt \;`,找到文件并移到 opt 目录
- `find . -name "*" |xargs grep "youmeek"`,递归查找当前文件夹下所有文件内容中包含 youmeek 的文件
- `find . -size 0 | xargs rm -f &`,删除当前目录下文件大小为0的文件
- `du -hm --max-depth=2 | sort -nr | head -12`,找出系统中占用容量最大的前 12 个目录
- `cat /etc/resolv.conf`,查看 DNS 设置
- `netstat -tlunp`,查看当前运行的服务,同时可以查看到:运行的程序已使用端口情况
- `env`,查看所有系统变量
- `export`,查看所有系统变量
- `echo`
- `echo $JAVA_HOME`,查看指定系统变量的值,这里查看的是自己配置的 JAVA_HOME。
- `echo "字符串内容"`,输出 "字符串内容"
- `echo > aa.txt`,清空 aa.txt 文件内容(类似的还有:`: > aa.txt`,其中 : 是一个占位符, 不产生任何输出)
- `unset $JAVA_HOME`,删除指定的环境变量
- `ln -s /opt/data /opt/logs/data`,表示给 /opt/logs 目录下创建一个名为 data 的软链接,该软链接指向到 /opt/data
- `grep`
- `shell grep -H '安装' *.sh`,查找当前目录下所有 sh 类型文件中,文件内容包含 `安装` 的当前行内容
- `grep 'test' java*`,显示当前目录下所有以 java 开头的文件中包含 test 的行
- `grep 'test' spring.ini docker.sh`,显示当前目录下 spring.ini docker.sh 两个文件中匹配 test 的行
- `ps`
- `ps –ef|grep java`,查看当前系统中有关 java 的所有进程
- `ps -ef|grep --color java`,高亮显示当前系统中有关 java 的所有进程
- `kill`
- `kill 1234`,结束 pid 为 1234 的进程
- `kill -9 1234`,强制结束 pid 为 1234 的进程(慎重)
- `killall java`,结束同一进程组内的所有为 java 进程
- `ps -ef|grep hadoop|grep -v grep|cut -c 9-15|xargs kill -9`,结束包含关键字 hadoop 的所有进程
- `head`
- `head -n 10 spring.ini`,查看当前文件的前 10 行内容
- `tail`
- `tail -n 10 spring.ini`,查看当前文件的后 10 行内容
- `tail -200f 文件名`,查看文件被更新的新内容尾 200 行,如果文件还有在新增可以动态查看到(一般用于查看日记文件)
## 用户、权限-相关命令
- 使用 pem 证书登录:`ssh -i /opt/mykey.pem root@192.168.0.70`
- 证书权限不能太大,不然无法使用:`chmod 600 mykey.pem`
- `hostname`,查看当前登陆用户全名
- `cat /etc/group`,查看所有组
- `cat /etc/passwd`,查看所有用户
- `groups youmeek`,查看 youmeek 用户属于哪个组
- `useradd youmeek -g judasn`,添加用户并绑定到 judasn 组下
- `userdel -r youmeek`,删除名字为 youmeek 的用户
- 参数:`-r`,表示删除用户的时候连同用户的家目录一起删除
- 修改普通用户 youmeek 的权限跟 root 权限一样:
- 常用方法(原理是把该用户加到可以直接使用 sudo 的一个权限状态而已):
- 编辑配置文件:`vim /etc/sudoers`
- 找到 98 行(预估),有一个:`root ALL=(ALL) ALL`,在这一行下面再增加一行,效果如下:
``` nginx
root ALL=(ALL) ALL
youmeek ALL=(ALL) ALL
```
- 另一种方法:
- 编辑系统用户的配置文件:`vim /etc/passwd`,找到 **root** 和 **youmeek** 各自开头的那一行,比如 root 是:`root:x:0:0:root:/root:/bin/zsh`,这个代表的含义为:*用户名:密码:UserId:GroupId:描述:家目录:登录使用的 shell*
- 通过这两行对比,我们可以直接修改 youmeek 所在行的 UserId 值 和 GroupId 值,都改为 0。
- `groupadd judasn`,添加一个名为 judasn 的用户组
- `groupdel judasn`,删除一个名为 judasn 的用户组(前提:先删除组下面的所有用户)
- `usermod 用户名 -g 组名`,把用户修改到其他组下
- `passwd youmeek`,修改 youmeek 用户的密码(前提:只有 root 用户才有修改其他用户的权限,其他用户只能修改自己的)
- `chmod 777 文件名/目录`,给指定文件增加最高权限,系统中的所有人都可以进行读写。
- linux 的权限分为 rwx。r 代表:可读,w 代表:可写,x 代表:可执行
- 这三个权限都可以转换成数值表示,r = 4,w = 2,x = 1,- = 0,所以总和是 7,也就是最大权限。第一个 7 是所属主(user)的权限,第二个 7 是所属组(group)的权限,最后一位 7 是非本群组用户(others)的权限。
- `chmod -R 777 目录` 表示递归目录下的所有文件夹,都赋予 777 权限
- `chown myUsername:myGroupName myFile` 表示修改文件所属用户、组
- `chown -R myUsername:myGroupName myFolder` 表示递归修改指定目录下的所有文件权限
- `su`:切换到 root 用户,终端目录还是原来的地方(常用)
- `su -`:切换到 root 用户,其中 **-** 号另起一个终端并切换账号
- `su 用户名`,切换指定用户帐号登陆,终端目录还是原来地方。
- `su - 用户名`,切换到指定用户帐号登陆,其中 **-** 号另起一个终端并切换账号
- `exit`,注销当前用户(常用)
- `sudo 某个命令`,使用管理员权限使用命令,使用 sudo 回车之后需要输入当前登录账号的密码。(常用)
- `passwd`,修改当前用户密码(常用)
- 添加临时账号,并指定用户根目录,并只有可读权限方法
- 添加账号并指定根目录(用户名 tempuser):`useradd -d /data/logs -m tempuser`
- 设置密码:`passwd tempuser` 回车设置密码
- 删除用户(该用户必须退出 SSH 才能删除成功),也会同时删除组:`userdel tempuser`
## 磁盘管理
- `df -h`,自动以合适的磁盘容量单位查看磁盘大小和使用空间
- `df -k`,以磁盘容量单位 K 为数值结果查看磁盘使用情况
- `df -m`,以磁盘容量单位 M 为数值结果查看磁盘使用情况
- `du -sh /opt`,查看 opt 这个文件夹大小 (h 的意思 human-readable 用人类可读性较好方式显示,系统会自动调节单位,显示合适大小的单位)
- `du -sh ./*`,查看当前目录下所有文件夹大小 (h 的意思 human-readable 用人类可读性较好方式显示,系统会自动调节单位,显示合适大小的单位)
- `du -sh /opt/setups/`,显示 /opt/setups/ 目录所占硬盘空间大小(s 表示 –summarize 仅显示总计,即当前目录的大小。h 表示 –human-readable 以 KB,MB,GB 为单位,提高信息的可读性)
- `mount /dev/sdb5 /newDir/`,把分区 sdb5 挂载在根目录下的一个名为 newDir 的空目录下,需要注意的是:这个目录最好为空,不然已有的那些文件将看不到,除非卸载挂载。
- 挂载好之后,通过:`df -h`,查看挂载情况。
- `umount /newDir/`,卸载挂载,用目录名
- 如果这样卸载不了可以使用:`umount -l /newDir/`
- `umount /dev/sdb5`,卸载挂载,用分区名
## wget 下载文件
- 常规下载:`wget http://www.gitnavi.com/index.html`
- 自动断点下载:`wget -c http://www.gitnavi.com/index.html`
- 后台下载:`wget -b http://www.gitnavi.com/index.html`
- 伪装代理名称下载:`wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" http://www.gitnavi.com/index.html`
- 限速下载:`wget --limit-rate=300k http://www.gitnavi.com/index.html`
- 批量下载:`wget -i /opt/download.txt`,一个下载地址一行
- 后台批量下载:`wget -b -c -i /opt/download.txt`,一个下载地址一行
## 资料
-
-
-
================================================
FILE: markdown-file/CI-Install-And-Usage.md
================================================
# CI 一整套服务
## 环境说明
- CentOS 7.3
- 两台机子(一台机子也是可以,内存至少要 8G)
- 一台:Gitlab + Redis + Postgresql
- 硬件推荐:内存 4G
- 端口安排
- Gitlab:10080
- 一台:Nexus + Jenkins + SonarQube + Postgresql
- 硬件推荐:内存 8G
- 端口安排
- SonarQube:19000
- Nexus:18081
- Jenkins:18080
## Gitlab + Redis + Postgresql
- 预计会使用内存:2G 左右
- 这套方案来自(部分内容根据自己情况进行了修改):
- 创建宿主机挂载目录:`mkdir -p /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql`
- 赋权(避免挂载的时候,一些程序需要容器中的用户的特定权限使用):`chmod -R 777 /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql`
- 这里使用 docker-compose 的启动方式,所以需要创建 docker-compose.yml 文件:
```yaml
version: '2'
services:
redis:
restart: always
image: sameersbn/redis:latest
command:
- --loglevel warning
volumes:
- /data/docker/gitlab/redis:/var/lib/redis:Z
postgresql:
restart: always
image: sameersbn/postgresql:9.6-2
volumes:
- /data/docker/gitlab/postgresql:/var/lib/postgresql:Z
environment:
- DB_USER=gitlab
- DB_PASS=password
- DB_NAME=gitlabhq_production
- DB_EXTENSION=pg_trgm
gitlab:
restart: always
image: sameersbn/gitlab:10.4.2-1
depends_on:
- redis
- postgresql
ports:
- "10080:80"
- "10022:22"
volumes:
- /data/docker/gitlab/gitlab:/home/git/data:Z
environment:
- DEBUG=false
- DB_ADAPTER=postgresql
- DB_HOST=postgresql
- DB_PORT=5432
- DB_USER=gitlab
- DB_PASS=password
- DB_NAME=gitlabhq_production
- REDIS_HOST=redis
- REDIS_PORT=6379
- TZ=Asia/Shanghai
- GITLAB_TIMEZONE=Beijing
- GITLAB_HTTPS=false
- SSL_SELF_SIGNED=false
- GITLAB_HOST=192.168.0.105
- GITLAB_PORT=10080
- GITLAB_SSH_PORT=10022
- GITLAB_RELATIVE_URL_ROOT=
- GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alphanumeric-string
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alphanumeric-string
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alphanumeric-string
- GITLAB_ROOT_PASSWORD=
- GITLAB_ROOT_EMAIL=
- GITLAB_NOTIFY_ON_BROKEN_BUILDS=true
- GITLAB_NOTIFY_PUSHER=false
- GITLAB_EMAIL=notifications@example.com
- GITLAB_EMAIL_REPLY_TO=noreply@example.com
- GITLAB_INCOMING_EMAIL_ADDRESS=reply@example.com
- GITLAB_BACKUP_SCHEDULE=daily
- GITLAB_BACKUP_TIME=01:00
- SMTP_ENABLED=false
- SMTP_DOMAIN=www.example.com
- SMTP_HOST=smtp.gmail.com
- SMTP_PORT=587
- SMTP_USER=mailer@example.com
- SMTP_PASS=password
- SMTP_STARTTLS=true
- SMTP_AUTHENTICATION=login
- IMAP_ENABLED=false
- IMAP_HOST=imap.gmail.com
- IMAP_PORT=993
- IMAP_USER=mailer@example.com
- IMAP_PASS=password
- IMAP_SSL=true
- IMAP_STARTTLS=false
- OAUTH_ENABLED=false
- OAUTH_AUTO_SIGN_IN_WITH_PROVIDER=
- OAUTH_ALLOW_SSO=
- OAUTH_BLOCK_AUTO_CREATED_USERS=true
- OAUTH_AUTO_LINK_LDAP_USER=false
- OAUTH_AUTO_LINK_SAML_USER=false
- OAUTH_EXTERNAL_PROVIDERS=
- OAUTH_CAS3_LABEL=cas3
- OAUTH_CAS3_SERVER=
- OAUTH_CAS3_DISABLE_SSL_VERIFICATION=false
- OAUTH_CAS3_LOGIN_URL=/cas/login
- OAUTH_CAS3_VALIDATE_URL=/cas/p3/serviceValidate
- OAUTH_CAS3_LOGOUT_URL=/cas/logout
- OAUTH_GOOGLE_API_KEY=
- OAUTH_GOOGLE_APP_SECRET=
- OAUTH_GOOGLE_RESTRICT_DOMAIN=
- OAUTH_FACEBOOK_API_KEY=
- OAUTH_FACEBOOK_APP_SECRET=
- OAUTH_TWITTER_API_KEY=
- OAUTH_TWITTER_APP_SECRET=
- OAUTH_GITHUB_API_KEY=
- OAUTH_GITHUB_APP_SECRET=
- OAUTH_GITHUB_URL=
- OAUTH_GITHUB_VERIFY_SSL=
- OAUTH_GITLAB_API_KEY=
- OAUTH_GITLAB_APP_SECRET=
- OAUTH_BITBUCKET_API_KEY=
- OAUTH_BITBUCKET_APP_SECRET=
- OAUTH_SAML_ASSERTION_CONSUMER_SERVICE_URL=
- OAUTH_SAML_IDP_CERT_FINGERPRINT=
- OAUTH_SAML_IDP_SSO_TARGET_URL=
- OAUTH_SAML_ISSUER=
- OAUTH_SAML_LABEL="Our SAML Provider"
- OAUTH_SAML_NAME_IDENTIFIER_FORMAT=urn:oasis:names:tc:SAML:2.0:nameid-format:transient
- OAUTH_SAML_GROUPS_ATTRIBUTE=
- OAUTH_SAML_EXTERNAL_GROUPS=
- OAUTH_SAML_ATTRIBUTE_STATEMENTS_EMAIL=
- OAUTH_SAML_ATTRIBUTE_STATEMENTS_NAME=
- OAUTH_SAML_ATTRIBUTE_STATEMENTS_FIRST_NAME=
- OAUTH_SAML_ATTRIBUTE_STATEMENTS_LAST_NAME=
- OAUTH_CROWD_SERVER_URL=
- OAUTH_CROWD_APP_NAME=
- OAUTH_CROWD_APP_PASSWORD=
- OAUTH_AUTH0_CLIENT_ID=
- OAUTH_AUTH0_CLIENT_SECRET=
- OAUTH_AUTH0_DOMAIN=
- OAUTH_AZURE_API_KEY=
- OAUTH_AZURE_API_SECRET=
- OAUTH_AZURE_TENANT_ID=
```
- 启动:`docker-compose up -d`,启动比较慢,等个 2 分钟左右。
- 浏览器访问 Gitlab:
- 默认用户是 root,密码首次访问必须重新设置,并且最小长度为 8 位,我习惯设置为:aa123456
- 添加 SSH key:
- Gitlab 的具体使用可以看另外文章:[Gitlab 的使用](Gitlab-Install-And-Settings.md)
## Nexus + Jenkins + SonarQube
- 预计会使用内存:4G 左右
- 创建宿主机挂载目录:`mkdir -p /data/docker/ci/nexus /data/docker/ci/jenkins /data/docker/ci/jenkins/lib /data/docker/ci/jenkins/home /data/docker/ci/sonarqube /data/docker/ci/postgresql /data/docker/ci/gatling/results`
- 赋权(避免挂载的时候,一些程序需要容器中的用户的特定权限使用):`chmod -R 777 /data/docker/ci/nexus /data/docker/ci/jenkins/lib /data/docker/ci/jenkins/home /data/docker/ci/sonarqube /data/docker/ci/postgresql /data/docker/ci/gatling/results`
- 下面有一个细节要特别注意:yml 里面不能有中文。还有就是 sonar 的挂载目录不能直接挂在 /opt/sonarqube 上,不然会启动不了。
- 这里使用 docker-compose 的启动方式,所以需要创建 docker-compose.yml 文件:
```yaml
version: '3'
networks:
prodnetwork:
driver: bridge
services:
sonardb:
image: postgres:9.6.6
restart: always
ports:
- "5433:5432"
networks:
- prodnetwork
volumes:
- /data/docker/ci/postgresql:/var/lib/postgresql
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
sonar:
image: sonarqube:6.7.1
restart: always
ports:
- "19000:9000"
- "19092:9092"
networks:
- prodnetwork
depends_on:
- sonardb
volumes:
- /data/docker/ci/sonarqube/conf:/opt/sonarqube/conf
- /data/docker/ci/sonarqube/data:/opt/sonarqube/data
- /data/docker/ci/sonarqube/extension:/opt/sonarqube/extensions
- /data/docker/ci/sonarqube/bundled-plugins:/opt/sonarqube/lib/bundled-plugins
environment:
- SONARQUBE_JDBC_URL=jdbc:postgresql://sonardb:5432/sonar
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=sonar
nexus:
image: sonatype/nexus3
restart: always
ports:
- "18081:8081"
networks:
- prodnetwork
volumes:
- /data/docker/ci/nexus:/nexus-data
jenkins:
image: wine6823/jenkins:1.1
restart: always
ports:
- "18080:8080"
networks:
- prodnetwork
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /etc/localtime:/etc/localtime:ro
- $HOME/.ssh:/root/.ssh
- /data/docker/ci/jenkins/lib:/var/lib/jenkins/
- /data/docker/ci/jenkins/home:/var/jenkins_home
depends_on:
- nexus
- sonar
environment:
- NEXUS_PORT=8081
- SONAR_PORT=9000
- SONAR_DB_PORT=5432
```
- 启动:`docker-compose up -d`,启动比较慢,等个 2 分钟左右。
- 浏览器访问 SonarQube:
- 默认用户名:admin
- 默认密码:admin
- 插件安装地址:
- 代码检查规范选择:
- 如果没有安装相关检查插件,默认是没有内容可以设置,建议现在插件市场安装 FindBugs,这样也可以帮你生成插件目录:`/extension/plugins`
- 如果你有其他额外插件,可以把 jar 放在 `${SONAR_HOME}/extension/plugins` 目录下,然后重启下 sonar
- 浏览器访问 Nexus:
- 默认用户名:admin
- 默认密码:admin123
- 浏览器访问 Jenkins:
- 首次进入 Jenkins 的 Web UI 界面是一个解锁页面 Unlock Jenkins,需要让你输入:Administrator password
- 这个密码放在:`/var/jenkins_home/secrets/initialAdminPassword`,你需要先:`docker exec -it ci_jenkins_1 /bin/bash`
- 然后:`cat /var/jenkins_home/secrets/initialAdminPassword`,找到初始化密码
---------------------------------
## 配置 Jenkins 拉取代码权限
- 因为 dockerfile 中我已经把宿主机的 .ssh 下的挂载在 Jenkins 的容器中
- 所以读取宿主机的 pub:`cat ~/.ssh/id_rsa.pub`,然后配置在 Gitlab 中:
- Jenkinsfile 中 Git URL 使用:ssh 协议,比如:`ssh://git@192.168.0.105:10022/gitnavi/spring-boot-ci-demo.git`
## Jenkins 特殊配置(减少权限问题,如果是内网的话)
- 访问:
- 去掉 `防止跨站点请求伪造`
- 勾选 `登录用户可以做任何事` 下面的:`Allow anonymous read access`
## 配置 Gitlab Webhook
- Jenkins 访问:
- 在 `Build Triggers` 勾选:`触发远程构建 (例如,使用脚本)`,在 `身份验证令牌` 输入框填写任意字符串,这个等下 Gitlab 会用到,假设我这里填写:112233
- Gitlab 访问:
- 在 `URL` 中填写:`http://192.168.0.105:18080/job/任务名/build?token=112233`
## 资料
-
================================================
FILE: markdown-file/CentOS-7-Install.md
================================================
# CentOS 7 安装
## 概括
- 本教程中主要演示了 VMware Workstation 下安装 `CentOS 7.3` 的过程。
- VMware 的使用细节可以看这篇:[CentOS 6 安装](CentOS-Install.md)
- 如果你是要安装到 PC 机中,你需要准备一个 U 盘,以及 Windows 下载这个软件:[USBWriter(提取码:5aa2)](https://pan.baidu.com/s/1gg83h9T)
- 如果你是要安装到 PC 机中,你需要准备一个 U 盘,以及 macOS 下载这个软件:[balenaEtcher(提取码:oqp9)](https://pan.baidu.com/s/1l5K48tfuCKdn0wR_62PjJA)
- USBWriter 的使用很简单,如下图即可制作一个 CentOS 系统盘

## VMware 下安装 CentOS 过程
- VMware Workstation 的介绍和下载
- 官网:
- wiki:
- 百度 wiki:
- 百度云下载(64 位):
- 官网下载:
- 安装细节开始:





- 如上图,默认是最小安装,点击进去,选择桌面安装。
- 如上图,默认是自动分区,如果懂得分区,点击进去,进行手动分区,CentOS 7 少了主分区,逻辑分区的选择了。

- 如上图,root 密码必须设置,我习惯测试的时候是:123456
- 我没有创建用户,喜欢用 root


- 如上图,许可证必须点击进去勾选同意相关协议。
- 如上图,网络可以稍后在设置,主机名可以现在先填写




- 如上图右上角,一般我们都选择跳过




- 到此完成,其他该做啥就做啥
================================================
FILE: markdown-file/CentOS-Install.md
================================================
# CentOS 安装
## 概括
- 本教程中主要演示了 VirtualBox 和 VMware Workstation 下安装 `CentOS 6.6` 的过程。
- VirtualBox 是免费开源,我个人在使用经历中遇到过很多次崩溃、安装有问题等,所以它不是我主推的虚拟机
- VMware Workstation 是商业软件,很好用,一些辅助功能也很到位,主推该虚拟机。
- 如果你是要安装到 PC 机中,你需要准备一个 U 盘,以及下载这个软件:[USBWriter(提取码:5aa2)](https://pan.baidu.com/s/1gg83h9T)
- USBWriter 的使用很简单,如下图即可制作一个 CentOS 系统盘

## VirtualBox 下安装 CentOS 过程
- VirtualBox 的介绍和下载
- 官网:
- wiki:
- 百度 wiki:
- 百度云下载(32 位和 64 位一体):
- 官网下载:
#### VirtualBox 安装细节开始:
- 
- 如上图标注 1 所示:点击 `新建` 一个虚拟机。
- 如上图标注 2 所示:在填写 `名称` 的时候,输入 `CentOS` 相关字眼的时候,下面的版本类型会跟着变化,自动识别为 `Red Hat`
- 
- 如上图标注 1 所示:我们装的是 64 位系统,如果你本机内存足够大,建议可以给 2 ~ 4 G 的容量
- 
- 
- 
- 
- 如上图所示,命名最好规范,最好要带上系统版本号,硬盘大小建议在 8 ~ 20 G
- 
- 如上图 gif 演示,当我们创建好虚拟机之后,需要选择模拟光驱进行系统镜像安装
- 
- 
- 如上图箭头所示,我们这里选择 `Skip`,跳过对镜像的检查,这个一般需要检查很久,而且我们用 iso 文件安装的,一般没这个必要
- 
- 
- 如上图标注 1 所示,建议 Linux 纯新手使用简体中文环境
- 
- 
- 
- 如上图标注 1 所示,因为我们是用全新的虚拟机,虚拟出来的硬盘都是空的,所以这里可以忽略所有数据
- 
- 
- 
- 再次强调下,root 账号也就是图上所说的 `根账号`,它是最顶级账号,密码最好别忘记了
- 
- 
- 如上图标注 1 所示,因为我们是用全新的虚拟机,所以这里选择 `使用所有空间` ,然后 CentOS 会按它默认的方式进行分区
- 
- 
- `Desktop` 代表:图形界面版,会默认安装很多软件,建议新手选择此模式,我后面其他文章的讲解都是基于此系统下,如果你不是此模式的系统可能在安装某些软件的时候会出现某些依赖包没有安装的情况
- `basic sever` 代表:命令行界面,有良好基础的基本都会喜欢这个
- 
- 上一步我选择的是 `Desktop` 所以有很多软件需要安装,这个过程大概需要 5 ~ 10 分钟
- 
- 安装完成
- 
- 安装完成后一定要把盘片删除,防止系统启动的时候去读盘,重新进入安装系统模式
## VMware 下安装 CentOS 过程
- VMware Workstation 的介绍和下载
- 官网:
- wiki:
- 百度 wiki:
- 百度云下载(64 位):
- 官网下载:
#### VMware 安装细节开始:
- 
- 
- 默认 VMware 选择的是 `典型` 我不推荐,我下面的步骤是选择 `自定义(高级)`。如果你非常了解 Linux 系统倒是可以考虑选择 `典型`,在它默认安装完的系统上可以很好地按你的需求进行修改
- 
- 
- 牢记:不要在这一步就选择镜像文件,不然也会直接进入 `典型` 模式,直接按它的规则进行系统安装
- 
- 
- 
- 
- 
- 桥接模式:(建议选择此模式)创建一个独立的虚拟主机,在桥接模式下的虚拟主机网络一般要为其配 IP 地址、子网掩码、默认网关(虚拟机ip地址要与主机ip地址处于同网段)
- NAT 模式:把物理主机作为路由器进行访问互联网,优势:联网简单,劣势:虚拟主机无法与物理主机通讯
- 主机模式:把虚拟主机网络与真实网络隔开,但是各个虚拟机之间可以互相连接,虚拟机和物理机也可以连接
- > 上面解释来源:
- 
- Buslogic 和 LSIlogic 都是虚拟硬盘 SCSI 设备的类型,旧版本的 OS 默认的是 Buslogic,LSIlogic 类型的硬盘改进了性能,对于小文件的读取速度有提高,支持非 SCSI 硬盘比较好。
- > 上面解释来源:
- 
- 
- 
- 强烈建议至少要给 20 G,不然装不了多少软件的
- 
- 
- 
- 如上图 gif 所示,在创建完虚拟机之后,我们要加载系统镜像,然后启动虚拟机进行安装,接下来的安装步骤跟上面使用 VirtualBox 安装细节基本一样,不一样的地方是我这里选择的是自定义分区,不再是选择默认分区方式
- 
- 如上图箭头所示,这里我们选择自定义分区方式
- 
- 如上图 gif 所示,我只把最基本的区分出来,如果你有自己的需求可以自己设置
- 简单分区方案:
- `/boot` == 500 M(主分区)
- `/swap` == 2 G(逻辑分区)一般大家的说法这个大小是跟你机子的内存大小相关的,也有说法内存大不需要这个,但是还是建议分,虚拟机内存 2 G,所以我分 2 G
- `/` == 剩余容量(逻辑分区)剩余的空间都给了根分区
- 
- 
- 
- 
- 
- 
- 
- 
- 
================================================
FILE: markdown-file/CentOS-Virtual-Machine-Copy-Settings.md
================================================
# VMware 克隆 CentOS 后网卡信息修改
## 概述
- 在我们需要多台 CentOS 虚拟机的时候,对已有虚拟机的系统进行克隆或是复制。但是这样做又有一个问题,克隆出来的虚拟机启动的时候你输入命令:`ifconfig`,eth0 网卡信息没了,只有一个 eth1。 对于处女座的人来讲这是不允许的。所以我们需要改动下。
- 复制虚拟机后,首次打开该会提示如下内容,一般选择 copy 这个配置。
- 
## CentOS 6 修改方法
- 设置 hostname:`hostnamectl --static set-hostname linux02`
- 命令:`sudo vim /etc/udev/rules.d/70-persistent-net.rules`
- 该文件中正常此时应该有两行信息
- 在文件中把 NAME="eth0″ 的这一行注释掉
- 对于另一行,把 NAME=”eth1″ 的这一行,把 NAME=”eth1″ 改为 NAME=”eth0″,并且把该行:ATTRS{address}=="00:0c:29:4c:46:01″ 这个属性信息记下来,每台机子都不一样,我这段信息只是例子,你不要直接复制我的。
- 命令:`sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0`
- 修改 IP 地址
- 把 HWADDR 的值改为上面要求记下来的:00:0c:29:4c:46:01
- 命令:`nmcli con > /opt/info.txt`
- 如果显示两行 UUID 的信息的话,复制不是 System eth0 的那个 UUID 值,下面有用。
- 编辑:`sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0`
- 把文件中的 UUID 值 改为上面要求复制的 UUID 值。
- 保存配置文件,重启系统,正常应该是可以了。
## CentOS 7 修改方法
- 在 VMware 15 Pro 的情况下,直接 copy 进行后,直接修改网卡配置即可
- 编辑该文件:`vim /etc/sysconfig/network-scripts/ifcfg-ens33`
- 把 ip 地址修改即可
================================================
FILE: markdown-file/CentOS.md
================================================
# CentOS 介绍
- CentOS Wiki:
- CentOS 百科:
- CentOS 官网:
- CentOS 的自我介绍:
- CentOS 官网下载:
- CentOS 官网下载(含有旧版本):
- CentOS 国内镜像下载:
- 版本更新记录:
# CentOS 原型系统:Red Hat Enterprise Linux
- Red Hat Enterprise Linux Wiki:
- Red Hat Enterprise Linux 百科:
- 衍生版本:
# Red Hat Enterprise Linux 后花园系统:Fedora
- Fedora Wiki:
- Fedora 百科:
- Fedora 官网:
- Fedora 官网桌面版下载:
- Fedora 官网文档:
================================================
FILE: markdown-file/CentOS6-and-CentOS7.md
================================================
# CentOS 6 和 CentOS 7 介绍
## 总体差异
- 
## 想装回过去的一些工具
- 安装:`yum install -y tree net-tools bind-utils tree sysstat vim-en* lrzsz NetworkManager-tui ntp ntpdate iftop tcpdump telnet traceroute`
## 查看版本号/主机名
- `cat /etc/redhat-release`
- `cat /etc/hostname`
## 常用配置差异
- [CentOS 网络配置](centos-settings/CentOS-Network-Settings.md)
- [CentOS 图形界面的关闭与开启](centos-settings/Close-XWindow.md)
## systemctl 的用法
- 相当于 CentOS 6 的:service nginx stop
- `systemctl is-enabled iptables.service` #查询服务是否开机启动
- `systemctl enable iptables.service` #开机运行服务
- `systemctl disable iptables.service` #取消开机运行
- `systemctl start iptables.service` #启动服务
- `systemctl stop iptables.service` #停止服务
- `systemctl restart iptables.service` #重启服务
- `systemctl reload iptables.service` #重新加载服务配置文件
- `systemctl status iptables.service` #查询服务运行状态
- `systemctl --failed` #显示启动失败的服务
- `systemctl list-units --type=service` #查看所有服务
- `systemctl is-enabled httpd` #查看httpd服务是否开机启动
- 对于启动脚本的存放位置,也不再是 `/etc/init.d/`(这个目录也是存在的),而是 `/usr/lib/systemd/system/`
### 开放端口
- 一般设置软件端口有一个原则:
- 0 ~ 1024 系统保留,一般不要用到
- 1024 ~ 65535(2^16) 可以随意用
- 添加单个端口:`firewall-cmd --zone=public --add-port=8883/tcp --permanent`
- 添加范围端口:`firewall-cmd --zone=public --add-port=8883-8885/tcp --permanent`
- 删除端口:`firewall-cmd --zone=public --remove-port=8883/tcp --permanent`
- 重启防火墙:`firewall-cmd --reload`
- 命令解释:
- `--zone` #作用域
- `--add-port=80/tcp` #添加端口,格式为:端口/通讯协议
- `--permanent` #永久生效,没有此参数重启后失效
- 列出所有端口列表:`firewall-cmd --list-all`
## 关闭 firewall 使用 iptables
- 关闭 firewall
- `systemctl stop firewalld.service` #停止firewall
- `systemctl disable firewalld.service` #禁止firewall开机启动
- 安装 iptables
- `yum install -y iptables-services`
- 启动 iptables
- `systemctl restart iptables.service` #最后重启防火墙使配置生效
- `systemctl enable iptables.service` #设置防火墙开机启动
- 其他使用照旧
## ifconfig 没有了
- 查看网络配置:`ip a`
- 装回 ifconfig:`yum install -y net-tools`
## 设置时区
- `timedatectl set-timezone Asia/Shanghai`
- `timedatectl status`
## 资料
-
-
-
-
================================================
FILE: markdown-file/Confluence-Install-And-Settings.md
================================================
# Confluence 安装和配置
## Confluence 6.15.4
- 最新 6.15.4 版本时间:2019-05
#### 数据库
```
docker run \
--name mysql-confluence \
--restart always \
-p 3316:3306 \
-e MYSQL_ROOT_PASSWORD=adg123456 \
-e MYSQL_DATABASE=confluence_db \
-e MYSQL_USER=confluence_user \
-e MYSQL_PASSWORD=confluence_123456 \
-d \
mysql:5.7
```
- 连上容器:`docker exec -it mysql-confluence /bin/bash`
- 连上 MySQL:`mysql -u root -p`
- 设置编码:
- **必须做这一步,不然配置过程会报错,confluence 的 DB 要求是 utf8,还不能是 utf8mb4**
- **并且排序规则还必须是:utf8_bin**
- **数据库必须使用'READ-COMMITTED'作为默认隔离级别**
```
SET NAMES 'utf8';
alter database confluence_db character set utf8 collate utf8_bin;
SET GLOBAL tx_isolation='READ-COMMITTED';
```
#### 安装
- 下载:
- 选择:linux64 类型下载
- 授权:`chmod +x atlassian-confluence-6.15.4-x64.bin`
```
./atlassian-confluence-6.15.4-x64.bin
开始提示:
Unpacking JRE ...
Starting Installer ...
This will install Confluence 6.9.0 on your computer.
OK [o, Enter], Cancel [c]
>> 输入o或直接回车
Click Next to continue, or Cancel to exit Setup.
Choose the appropriate installation or upgrade option.
Please choose one of the following:
Express Install (uses default settings) [1],
Custom Install (recommended for advanced users) [2, Enter],
Upgrade an existing Confluence installation [3]
1
>> 这里输入数字1
See where Confluence will be installed and the settings that will be used.
Installation Directory: /opt/atlassian/confluence
Home Directory: /var/atlassian/application-data/confluence
HTTP Port: 8090
RMI Port: 8000
Install as service: Yes
Install [i, Enter], Exit [e]
i
>> 输入i或者直接回车
Extracting files ...
Please wait a few moments while we configure Confluence.
Installation of Confluence 6.9.0 is complete
Start Confluence now?
Yes [y, Enter], No [n]
>> 输入y或者直接回车
Please wait a few moments while Confluence starts up.
Launching Confluence ...
Installation of Confluence 6.9.0 is complete
Your installation of Confluence 6.9.0 is now ready and can be accessed via
your browser.
Confluence 6.9.0 can be accessed at http://localhost:8090
Finishing installation ...
# 安装完成,访问本机的8090端口进行web端安装
# 开放防火墙端口
firewall-cmd --add-port=8090/tcp --permanent
firewall-cmd --add-port=8000/tcp --permanent
firewall-cmd --reload
```
- 默认是安装在 /opt 目录下:`/opt/atlassian/confluence/confluence/WEB-INF/lib`
- 启动:`sh /opt/atlassian/confluence/bin/start-confluence.sh`
- 停止:`sh /opt/atlassian/confluence/bin/stop-confluence.sh`
- 查看 log:`tail -300f /opt/atlassian/confluence/logs/catalina.out`
- 卸载:`sh /opt/atlassian/confluence/uninstall`
- 设置 MySQL 连接驱动,把 mysql-connector-java-5.1.47.jar 放在目录 `/opt/atlassian/confluence/confluence/WEB-INF/lib`
#### 首次配置
- 访问:
- 参考文章:
- 参考文章:
- 因为步骤一样,所以我就不再截图了。
#### License 过程
- 参考自己的为知笔记
## 反向代理的配置可以参考
-
## 使用 markdown
- 点击右上角小齿轮 > 管理应用 > 搜索市场应用 > 输入 markdown > 安装
## 其他资料
-
-
================================================
FILE: markdown-file/Crontab.md
================================================
# Crontab 介绍
## Crontab 安装
- 查看是否已安装:
- CentOS:`rpm -qa | grep cron`
- Ubuntu:`dpkg -l | grep cron`
- 安装(一般系统是集成的):
- CentOS 6 / 7:`sudo yum install -y vixie-cron crontabs`
- Ubuntu:`sudo apt-get install -y cron`
- 服务常用命令
- CentOS 6
- `service crond start` 启动服务
- `service crond stop` 关闭服务
- `service crond restart` 重启服务
- CentOS 7
- `systemctl start crond` 启动服务
- `systemctl restart crond` 重新启动服务
- `systemctl status crond` 加入自启动
- `systemctl stop crond` 关闭服务
## Crontab 服务器配置文件常用参数
- 配置文件介绍(记得先备份):`sudo vim /etc/crontab`
- 注意:不要在配置文件里面写相对路径
- 该配置格式解释:
- 
- 常用例子介绍:
- `30 21 * * * service httpd restart` #每晚的 21:30 重启 apache
- `30 21 * * 6,0 service httpd restart` #每周六、周日的 21:30 重启 apache
- `45 4 1,10,22 * * service httpd restart` #每月的 1、10、22 日的 4:45 重启 apache
- `45 4 1-10 * * service httpd restart` #每月的 1 到 10 日的 4:45 重启 apache
- `*/2 * * * * service httpd restart` #每隔两分钟重启 apache
- `1-59/2 * * * * service httpd restart` #每隔两分钟重启 apache(这个比较特殊:1-59/2 这个表示过掉0分,从 1 分开始算,每隔两分执行,所以 1 分执行了,3 分执行了,5 分执行了....都是奇数进行执行。默认的 */2 都是偶数执行。)
- `* */2 * * * service httpd restart` #每隔两小时重启 apache
- `0 23-7/2 * * * service httpd restart` #晚上 11 点到早上 7 点之间,每隔 2 个小时重启 apache
- `0-59/30 18-23 * * * service httpd restart` #每天 18:00 到 23:00 之间,每隔 30 分钟重启 apache(方法一)
- `0,30 18-23 * * * service httpd restart` #每天 18:00 到 23:00 之间,每隔 30 分钟重启 apache(方法二)
- `0 4 * * sun root /opt/shell/crontab-redis-restart.sh` #每周日 4:00 执行一个脚本(root 用户运行,有些脚本不指定用户会报:ERROR (getpwnam() failed)
- 更多例子可以看:
- 执行记录日志:`tail -f /var/log/cron`(如果发现任务不执行,可以来这里盯着日志看)
## Crontab 权限问题
- 一般默认只有 root 用户可以使用
- 如果要指定某个用户可以使用,可以在 /etc/cron.allow 添加(不存在文件就创建一个)
- 如果要指定某个用户不可以使用,可以在 /etc/cron.deny 添加(不存在文件就创建一个)
- 如果一个用户同时在两个文件都存在,那则以 allow 为准
## Crontab 不执行
- Crontab 不执行原因有很多,可以 Google 搜索:`Crontab 不执行`,这里不多说。
## Crontab 资料
-
-
================================================
FILE: markdown-file/Daemontools.md
================================================
# daemontools 工具
## supervisord
- 注意:Supervisor 能管理非 daemon 的进程,也就是说 Supervisor 不能管理守护进程。否则提示 Exited too quickly (process log may have details) 异常。
- Supervisor 不支持 python 3,安装 python 2 方法:
- 官网:
- 安装过程:
- 解释:easy_install 是 setuptools 包里带的一个命令,使用 easy_install 实际上是在调用 setuptools 来完成安装模块的工作,所以安装 setuptools 即可。
- 安装方案:
```
#第一种(推荐)
yum install python-setuptools
easy_install supervisor
#第二种
yum install python-setuptools
easy_install pip
pip install supervisor
#第三种
yum install -y epel-release
yum install -y supervisor
```
- 如果以上还不能安装,或是安装过程出现各种问题,或是安装完成后使用出现问题,应该就是环境有问题。至少我在京东云上发现会有这个问题。环境是 centos 6.8,python 2.6.6
- 如果你遇到这种问题需要源码安装。
- 源码和各个依赖的源码下载地址(密码:j797):
```
tar zxvf setuptools-36.6.0.tar.gz
cd setuptools-36.6.0
python bootstrap.py install
python setup.py install
tar zxvf meld3.tar.gz
cd meld3
python setup.py install
tar zxvf elementtree-1.2.6-20050316.tar.gz
cd elementtree-1.2.6-20050316
python setup.py install
tar zxvf supervisor-3.3.3.tar.gz
cd supervisor-3.3.3
python setup.py install
```
- 生成配置文件:`echo_supervisord_conf > /etc/supervisord.conf`
- 创建专门的程序配置文件目录、日志目录:
- `mkdir -p /var/log/supervisor`
- `mkdir -p /etc/supervisor/conf.d/`
- `echo -e "[include]\nfiles = /etc/supervisor/conf.d/*.conf">>/etc/supervisord.conf`
- 安装完成的内容介绍:supervisor 安装完成后会生成三个执行程序:
- supervisortd:supervisor 的守护进程服务(用于接收进程管理命令)
- supervisorctl:客户端(用于和守护进程通信,发送管理进程的指令)
- echo_supervisord_conf:生成初始配置文件程序。
- 程序位置:`/usr/bin/supervisord`
- 配置文件位置:`/etc/supervisord.conf`
### Logstash 进程进行守护
- 默认安装完 Supervisor 是已经启动的,所以在加入新配置之前,需要先停止程序:`ps -ef | grep supervisord`,kill 对应的 pid
- 创建配置文件:`vim /etc/supervisor/conf.d/logstash.conf`
``` nginx
[program:gitnavi-logstash]
command=/usr/program/elk/logstash-2.4.1/bin/logstash -f /usr/program/elk/logstash-2.4.1/config/logstash.conf
stdout_logfile=/var/log/supervisor/supervisord-logstash.log
stderr_logfile=/var/log/supervisor/supervisord-logstash-err.log
user=root
autostart=true
autorestart=false
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
```
- 该配置的具体说明可以参考:[使用 supervisor 管理进程](http://liyangliang.me/posts/2015/06/using-supervisor/)
- 启动程序(默认会启动所有子任务):`/usr/bin/supervisord -c /etc/supervisord.conf`
- 管理子任务的命令:
- 子任务状态:`/usr/bin/supervisorctl status`
- 启动所有子任务:`/usr/bin/supervisorctl start all`
- 结束所有子任务:`/usr/bin/supervisorctl stop all`
- 启动指定子任务:`/usr/bin/supervisorctl start gitnavi-logstash`
- 结束指定子任务:`/usr/bin/supervisorctl stop gitnavi-logstash`
- 重启指定子任务:`/usr/bin/supervisorctl restart gitnavi-logstash`
- 只载入最新的配置文件, 并不重启任何进程:`/usr/bin/supervisorctl reread`
- 载入最新的配置文件,停止原来的所有进程并按新的配置启动管理所有进程:`/usr/bin/supervisorctl reload`
- 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启:`/usr/bin/supervisorctl update`
- 查看所有子任务状态,如果没有运行的子任务则是没有任何反馈信息:`/usr/bin/supervisorctl status`
- 管理所有子任务也可以用交互方式,输入命令:`supervisorctl`,会进入 supervisord 的交互模式下,如果当前有启动的任务,还可以看到对应的任务情况。
- 在该交互下可以停止指定名称的子任务,比如 logstash 任务:`stop gitnavi-logstash`
- 也可以停止所有子任务:`stop all`
- 也可以启动所有子任务:`start all`
- 更多命令可以输入:`help`
### 设置 supervisord 开启自启动
#### CentOS 6
- 创建文件:`vim /etc/init.d/supervisord`
``` nginx
#!/bin/sh
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord
# Source init functions
. /etc/init.d/functions
RETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/subsys/supervisord"
start()
{
echo -n $"Starting $prog: "
daemon --pidfile $pidfile supervisord -c /etc/supervisord.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop()
{
echo -n $"Shutting down $prog: "
killproc -p ${pidfile} /usr/bin/supervisord
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f ${lockfile} ${pidfile}
fi
}
case "$1" in
start)
start ;;
stop) stop ;;
status)
status $prog ;;
restart)
stop
start ;;
*)
echo "Usage: $0 {start|stop|restart|status}" ;;
esac
```
- `chmod 755 /etc/init.d/supervisord`
- `chkconfig supervisord on`
- 以后启动可以用:`service supervisord start`
- 以后停止可以用:`service supervisord stop`
#### CentOS 7
- 创建文件:`vim /lib/systemd/system/supervisor.service`
``` ini
[Unit]
Description=supervisor
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
```
- `chmod 766 /lib/systemd/system/supervisor.service`
- `systemctl enable supervisor.service`
- `systemctl daemon-reload`
## 资料
-
-
-
-
-
-
================================================
FILE: markdown-file/Docker-Install-And-Usage.md
================================================
# Docker 使用
## 环境说明
- CentOS 7.3(不准确地说:要求必须是 CentOS 7 64位)
- 不建议在 Windows 上使用
## Docker 基本概念
- 官网:
- 宿主机:安装 Docker 的那台电脑
- Docker:一个虚拟化软件,你可以认为是类似:VMware、Virtualbox
- 镜像:可以认为是类似 Windows 下的:XXXX.iso
- 容器:容器为镜像的实例,可以认为是 Virtualbox 运行 XXXX.iso 后的效果
- 官网的镜像仓库地址:
- 对开发来讲总结一个最简单的说法:在 Maven 未产生的年代,jar 包要随着开发项目走到哪里跟到哪里。有了 Maven 写好 pom.xml 即可。此时的 Docker 就好比如 Maven,帮你省去了开发过程中的部署环境差异,你再也不能随便说:你的系统可以运行,我的系统就不行。现在别人连系统都帮你做好了。
- 玩法理念:单进程,一个容器最好最专注去做一个事情。虽然它可以既装 MySQL,又装 Nginx 等等,但是让一个容器只做好一件事是最合适的。
- 其他通俗解释:
> Docker的思想来自于集装箱,集装箱解决了什么问题?在一艘大船上,可以把货物规整的摆放起来。并且各种各样的货物被集装箱标准化了,集装箱和集装箱之间不会互相影响。那么我就不需要专门运送水果的船和专门运送化学品的船了。只要这些货物在集装箱里封装的好好的,那我就可以用一艘大船把他们都运走。
docker就是类似的理念。现在都流行云计算了,云计算就好比大货轮。docker就是集装箱。
1.不同的应用程序可能会有不同的应用环境,比如.net开发的网站和php开发的网站依赖的软件就不一样,如果把他们依赖的软件都安装在一个服务器上就要调试很久,而且很麻烦,还会造成一些冲突。比如IIS和Apache访问端口冲突。这个时候你就要隔离.net开发的网站和php开发的网站。常规来讲,我们可以在服务器上创建不同的虚拟机在不同的虚拟机上放置不同的应用,但是虚拟机开销比较高。docker可以实现虚拟机隔离应用环境的功能,并且开销比虚拟机小,小就意味着省钱了。
2.你开发软件的时候用的是Ubuntu,但是运维管理的都是centos,运维在把你的软件从开发环境转移到生产环境的时候就会遇到一些Ubuntu转centos的问题,比如:有个特殊版本的数据库,只有Ubuntu支持,centos不支持,在转移的过程当中运维就得想办法解决这样的问题。这时候要是有docker你就可以把开发环境直接封装转移给运维,运维直接部署你给他的docker就可以了。而且部署速度快。
3.在服务器负载方面,如果你单独开一个虚拟机,那么虚拟机会占用空闲内存的,docker部署的话,这些内存就会利用起来。
总之docker就是集装箱原理。
- Docker 的优点:
- 持续部署与测试
> Docker在开发与运维的世界中具有极大的吸引力,因为它能保持跨环境的一致性。在开发与发布的生命周期中,不同的环境具有细微的不同,这些差异可能是由于不同安装包的版本和依赖关系引起的。然而,Docker可以通过确保从开发到产品发布整个过程环境的一致性来解决这个问题。
Docker容器通过相关配置,保持容器内部所有的配置和依赖关系始终不变。最终,你可以在开发到产品发布的整个过程中使用相同的容器来确保没有任何差异或者人工干预。
使用Docker,你还可以确保开发者不需要配置完全相同的产品环境,他们可以在他们自己的系统上通过VirtualBox建立虚拟机来运行Docker容器。Docker的魅力在于它同样可以让你在亚马逊EC2实例上运行相同的容器。如果你需要在一个产品发布周期中完成一次升级,你可以很容易地将需要变更的东西放到Docker容器中,测试它们,并且使你已经存在的容器执行相同的变更。这种灵活性就是使用Docker的一个主要好处。和标准部署与集成过程一样,Docker可以让你构建、测试和发布镜像,这个镜像可以跨多个服务器进行部署。哪怕安装一个新的安全补丁,整个过程也是一样的。你可以安装补丁,然后测试它,并且将这个补丁发布到产品中。
- 环境标准化和版本控制
> Docker容器可以在不同的开发与产品发布生命周期中确保一致性,进而标准化你的环境。除此之外,Docker容器还可以像git仓库一样,可以让你提交变更到Docker镜像中并通过不同的版本来管理它们。设想如果你因为完成了一个组件的升级而导致你整个环境都损坏了,Docker可以让你轻松地回滚到这个镜像的前一个版本。这整个过程可以在几分钟内完成,如果和虚拟机的备份或者镜像创建流程对比,那Docker算相当快的,它可以让你快速地进行复制和实现冗余。此外,启动Docker就和运行一个进程一样快。
- 隔离性
> Docker可以确保你的应用程序与资源是分隔开的。几个月前,Gartner发表了一篇报告,这份报告说明了运行Docker 容器进行资源隔离的效果和虚拟机(VM)管理程序一样的好,但是管理与控制方面还需要进行完善。我们考虑这样一个场景,你在你的虚拟机中运行了很多应用程序,这些应用程序包括团队协作软件(例如Confluence)、问题追踪软件(例如JIRA)、集中身份管理系统(例如Crowd)等等。由于这些软件运行在不同的端口上,所以你必须使用Apache或者Nginx来做反向代理。到目前为止,一切都很正常,但是随着你的环境向前推进,你需要在你现有的环境中配置一个内容管理系统(例如Alfresco)。这时候有个问题发生了,这个软件需要一个不同版本的Apache Tomcat,为了满足这个需求,你只能将你现有的软件迁移到另一个版本的Tomcat上,或者找到适合你现有Tomcat的内容管理系统(Alfresco)版本。对于上述场景,使用Docker就不用做这些事情了。Docker能够确保每个容器都拥有自己的资源,并且和其他容器是隔离的。你可以用不同的容器来运行使用不同堆栈的应用程序。除此之外,如果你想在服务器上直接删除一些应用程序是比较困难的,因为这样可能引发依赖关系冲突。而Docker可以帮你确保应用程序被完全清除,因为不同的应用程序运行在不同的容器上,如果你不在需要一款应用程序,那你可以简单地通过删除容器来删除这个应用程序,并且在你的宿主机操作系统上不会留下任何的临时文件或者配置文件。除了上述好处,Docker还能确保每个应用程序只使用分配给它的资源(包括CPU、内存和磁盘空间)。一个特殊的软件将不会使用你全部的可用资源,要不然这将导致性能降低,甚至让其他应用程序完全停止工作。
- 安全性
> 如上所述,Gartner也承认Docker正在快速地发展。从安全角度来看,Docker确保运行在容器中的应用程序和其他容器中的应用程序是完全分隔与隔离的,在通信流量和管理上赋予你完全的控制权。Docker容器不能窥视运行在其他容器中的进程。从体系结构角度来看,每个容器只使用着自己的资源(从进程到网络堆栈)。作为紧固安全的一种手段,Docker将宿主机操作系统上的敏感挂载点(例如/proc和/sys)作为只读挂载点,并且使用一种写时复制系统来确保容器不能读取其他容器的数据。Docker也限制了宿主机操作系统上的一些系统调用,并且和SELinux与AppArmor一起运行的很好。此外,在Docker Hub上可以使用的Docker镜像都通过数字签名来确保其可靠性。由于Docker容器是隔离的,并且资源是受限制的,所以即使你其中一个应用程序被黑,也不会影响运行在其它Docker容器上的应用程序。
- 多云平台
> Docker最大的好处之一就是可移植性。在过去的几年里,所有主流的云计算提供商,包括亚马逊AWS和谷歌的GCP,都将Docker融入到他们的平台并增加了各自的支持。Docker容器能运行在亚马逊的EC2实例、谷歌的GCP实例、Rackspace服务器或者VirtualBox这些提供主机操作系统的平台上。举例来说,如果运行在亚马逊EC2实例上的Docker容器能够很容易地移植到其他几个平台上,比如说VirtualBox,并且达到类似的一致性和功能性,那这将允许你从基础设施层中抽象出来。除了AWS和GCP,Docker在其他不同的IaaS提供商也运行的非常好,例如微软的Azure、OpenStack和可以被具有不同配置的管理者所使用的Chef、Puppet、Ansible等。
## Docker 安装和基本配置
- 主要有两个版本:
> **Docker Enterprise Edition (Docker EE)** is designed for enterprise development and IT teams who build, ship, and run business critical applications in production at scale. Docker EE is integrated, certified, and supported to provide enterprises with the most secure container platform in the industry to modernize all applications. For more information about Docker EE, including purchasing options, see Docker Enterprise Edition.
**Docker Community Edition (Docker CE)** is ideal for developers and small teams looking to get started with Docker and experimenting with container-based apps. Docker CE is available on many platforms, from desktop to cloud to server. Docker CE is available for macOS and Windows and provides a native experience to help you focus on learning Docker. You can build and share containers and automate the development pipeline all from a single environment.
Docker CE has both stable and edge channels.
Stable builds are released once per quarter and are supported for 4 months.
Edge builds are released once per month, and are supported for that month only. If you subscribe to the Edge channel on Linux distributions, you should also subscribe to the Stable channel.
- 官网总的安装手册:
- 官网 CentOS 安装手册:
- 目前也支持 Windows,特别是 Windows 10,直接官网一个安装包即可搞定。
- Windows 10 的 Docker 安装说明:
- 我这里选择 Docker CE 版本:
- CentOS 安装过程:
- `sudo yum install -y yum-utils device-mapper-persistent-data lvm2`
- 添加 repo(可能网络会很慢,有时候会报:Timeout,所以要多试几次)
- `sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo`
- `sudo yum makecache fast`
- `sudo yum install -y docker-ce`,大小:19M,速度很慢。
- 查看配置文件位置:`systemctl show --property=FragmentPath docker`
- 启动 Docker:`systemctl start docker.service`
- 停止 Docker:`systemctl stop docker.service`
- 查看状态:`systemctl status docker.service`
- 运行 hello world 镜像:`sudo docker run hello-world`
- 因为是第一次使用,所以没这个镜像,需要一个下载过程,所以需要几分钟,可能还会报:Timeout。
- 镜像自动下载好后会输出这样一段内容,表示已经正常安装并可用了:
``` bash
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
```
## 镜像加速
- 只要是外国的东西在国内基本都很难有好的速度,所有就有了加速器的概念,目前国内常用的如下:
- 阿里云:
- USTC:
- daocloud:
- 网易:
- 时速云:
- 灵雀云:
- 推荐优先阿里云,然后是 USTC
- 我下面的讲解也是基于阿里云加速
- 阿里云的服务需要注册账号,**首次使用需要设置 docker 登录密码(阿里云叫做:**修改Registry登录密码**),这个以后用私人仓库会用到。**
- 如果忘记了,后面可以在这里修改:
- 注册后请访问:,你会看到专属的加速地址,比如我是:`https://ldhc17y9.mirror.aliyuncs.com`,所以下面文章你看到该地址都表示是这个专属地址,请记得自己更换自己的。
- 以及教你如何使用 Docker 加速器。如果你已经安装了最新版的 Docker 你就不需要用它的脚本进行安装了。
- 最新版本的 Docker 是新增配置文件:`vim /etc/docker/daemon.json`,增加如下内容:
``` bash
{
"registry-mirrors": ["https://ldhc17y9.mirror.aliyuncs.com"]
}
```
- `sudo systemctl daemon-reload`
- `sudo systemctl restart docker`
- 在以后的生活中如果要经常使用阿里云做为自己仓库,那你还需要做:
- 在 ` namespace管理` 中创建属于你自己的 namespace:
- 创建镜像仓库:
- 创建好仓库后,点击:`管理` 进入查看仓库的更多详细信息,这里面有很多有用的信息,包括一个详细的操作指南,**这份指南等下会用到。**
- 比如我自己创建一个 redis-to-cluster 仓库,地址是阿里云给我们的:`registry.cn-shenzhen.aliyuncs.com/youmeek/redis-to-cluster`
- 那我登录这个镜像地址的方式:
```
docker login registry.cn-shenzhen.aliyuncs.com
会让我输入
Username:阿里云邮箱
password:上文提到的--Registry登录密码
```
- 然后在我的仓库管理地址有教我如何推送和拉取镜像:
- 拉取:`docker pull registry.cn-shenzhen.aliyuncs.com/youmeek/redis-to-cluster:[镜像版本号]`
- 推送:
```
docker login
docker tag [ImageId] registry.cn-shenzhen.aliyuncs.com/youmeek/redis-to-cluster:[镜像版本号]
docker push registry.cn-shenzhen.aliyuncs.com/youmeek/redis-to-cluster:[镜像版本号]
```
# Docker 命令,最终部署 Spring Boot 项目
- 建议:初期使用的时候尽量用容器 ID / 镜像 ID。如果使用 Tag/Name 在东西多的情况下很容易混乱 还不如就用记不住但是肯定唯一的容器 ID / 镜像 ID
## 重要的基本概念
- 可以代表一个完整的镜像名有两种方式:
- REPOSITORY(仓库):TAG(标签)
- 其中 TAG 表面上不是必须有的,本质是 docker 帮你用 latest 来代替了。latest 这里最好翻译为默认,而不是最新。
- IMAGE ID(镜像ID)
- 这是一个 Docker 随机给你生成 数字+字母 的字符串
## 部署一个 Spring Boot 的 Java Web 项目为例
- 宿主机环境说明:
- IP 地址:`http://192.168.137.128`
- 停止了防火墙:`systemctl stop firewalld.service ; systemctl stop iptables.service`
- 停止防火墙后重启 Docker 服务:`systemctl restart docker.service`
- JDK(jdk-8u121-linux-x64.tar.gz)、jar 应用(spring-boot-my-demo.jar),存放宿主机位置:`/opt/setups`
- Spring Boot 的 jar 应用中配置文件给的端口是:8080,常规情况下的访问路径:`http://127.0.0.1:8080/youmeek`
- 下载镜像:`docker pull centos:6.8`,我的 IMAGE_ID 为:`0cd976dc0a98`
- 运行镜像,实例化为一个容器:`docker run -i -t -v /opt/setups:/opt 0cd976dc0a98 /bin/bash`
- `-v:表示需要将本地宿主机的目录挂载到容器中对应的一个目录上,格式:-v <宿主机目录>:<容器目录>,所以此时对容器此目录的操作,也是等同于对宿主机的目录的操作`
- 在容器里安装 Oracle JDK 8、配置 JDK 环境变量这里不多说,具体看:[JDK 安装](https://github.com/judasn/Linux-Tutorial/blob/master/JDK-Install.md)。
- 把容器中 /opt 目录下的 spring-boot-my-demo.jar 拷贝到容器的 root 目录下:`cp /opt/spring-boot-my-demo.jar /root`
- 再容器里新建脚本:`vi /root/spring-boot-run.sh`,脚本内容如下:
``` bash
#!/bin/bash
source /etc/profile
java -jar /root/spring-boot-my-demo.jar
```
- 在容器中对新建脚本增加执行权限:`chmod u+x /root/spring-boot-run.sh`
- 我们启动另外一个终端
- 查看我们刚刚运行的容器相关信息:`docker ps -a`
- 我们看到了我们刚刚运行的容器 ID(CONTAINER ID)为:`a5d544d9b6f9`,这个下面要用到
- 基于刚刚运行的容器创建新镜像:`docker commit a5d544d9b6f9 youmeek/springboot:0.1`
- 查看现在的镜像库:`docker images`,会发现多了一个 youmeek/springboot 新镜像,镜像 ID 为:`7024f230fef9`
- 运行新镜像,实例化为一个容器,并启动容器中刚刚写的脚本:`docker run -d -p 38080:8080 --name=springBootJar --hostname=springBootJar 7024f230fef9 /root/spring-boot-run.sh`
- `-d`:表示以“守护模式”执行 spring-boot-run.sh 脚本,此时 jar 中的 log 日志不会出现在输出终端上。
- `-p`:表示宿主机与容器的端口映射,此时将容器内部的 8080 端口映射为宿主机的 38080 端口,这样就向外界暴露了 38080 端口,可通过 Docker 网桥来访问容器内部的 8080 端口了。
- `--name`:表示给新实例容器取的名称,用一个有意义的名称命名即可
- 查看其实运行的容器:`docker ps -a`,可以知道我们的新容器 ID:`fd21ac056343`,名称为:`springBootJar`
- 查看这个容器的 jar 应用的 log 输出:`docker logs -f fd21ac056343`,可以看到 jar 启动后的 log 输出内容
- 通过浏览器访问容器中的应用:`http://192.168.137.128:38080/youmeek/`,可以看到 jar 应用的首页可以访问
## Docker 基本命令
- 官网文档:
#### 版本信息
- `docker version`,查看docker版本
- `docker info`,显示docker系统的信息
#### 镜像仓库
- `docker pull`:从仓库下载镜像到本地
- `docker pull centos:latest`:获取 CentOS 默认版本镜像
- `docker pull centos:7.3.1611`:获取 CentOS 7 镜像,下载大小 70M 左右,下面的操作基于此镜像
- `docker pull centos:6.8`:获取 CentOS 6 镜像
- `docker pull registry.cn-hangzhou.aliyuncs.com/chainone/centos7-jdk8`:获取别人做好的阿里云镜像
- `docker push`:将一个镜像 push 到 registry 仓库中
- `docker push myapache:v1`
- `docker search`:从 registry 仓库搜索镜像
- `docker search -s 3 centos`,参数 `-s 数字`:表示筛选出收藏数(stars值)大于等于 3 的镜像
- `docker login`:登录到一个镜像仓库。默认登录的是官网的仓库:
- 登录阿里云仓库格式:`sudo docker login --username=阿里云邮箱`
- 比如我是这个:`docker login --username=23333212@qq.com registry.cn-shenzhen.aliyuncs.com`,你完整的登录地址你需要访问:,在你自己创建的仓库中去查看那份详细操作指南上的地址
- 密码就是你首次访问:,弹窗出来让你设置的那个密码,如果忘记了重新设置下即可,重设地址:,右上角有一个:修改docker登录密码。
#### 本地镜像管理
- `docker stats`:查看当前启动的容器各自占用的系统资源
- `bin docker stats --no-stream kafkadocker_kafka_1 kafkadocker_zookeeper_1`:查看指定容器的占用资源情况
- 更加高级的监控方式有一个软件叫做:ctop(推荐使用):
```
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
4532a9ee27b8 cloud-cadvisor 1.49% 53.28MiB / 3.702GiB 1.41% 13.5MB / 646MB 265MB / 0B 19
3895d5d50a5e kafkadocker_kafka_1 1.45% 1.24GiB / 3.702GiB 33.51% 145MB / 186MB 499MB / 724MB 128
1d1a6a7c48d8 kafkadocker_zookeeper_1 0.11% 70.85MiB / 3.702GiB 1.87% 55.8MB / 33.7MB 209MB / 1.22MB 23
```
- `docker images`:显示本地所有的镜像列表
- 关注 REPOSITORY(名称),TAG(标签),IMAGE ID(镜像ID)三列
- `docker images centos`:查看具体镜像情况
- `docker rmi`:删除镜像,一般删除镜像前要先删除容器,不然如果镜像有被容器调用会报错
- `docker rmi 容器ID`:删除具体某一个镜像
- `docker rmi 仓库:Tag`:删除具体某一个镜像
- `docker rmi $(docker images -q)`,删除所有镜像
- `docker rmi -f $(docker images -q)`,强制删除所有镜像
- `docker rmi $(docker images | grep "vmware" | awk '{print $3}')`,批量删除带有 vmware 名称的镜像
- `docker tag`:为镜像打上标签
- `docker tag -f ubuntu:14.04 ubuntu:latest`,-f 意思是强制覆盖
- 同一个IMAGE ID可能会有多个TAG(可能还在不同的仓库),首先你要根据这些 image names 来删除标签,当删除最后一个tag的时候就会自动删除镜像;
- `docker rmi 仓库:Tag`,取消标签(如果是镜像的最后一个标签,则会删除这个镜像)
- `docker build`:使用 Dockerfile 创建镜像(推荐)
- `docker build . --rm -t runoob/ubuntu:v1`,参数 `-t`,表示:-tag,打标签
- 多次 docker build 过程中是有依赖一个缓存的过程的,一般 build 过程都有好几个 step,Docker 非常聪明,会自己判断那些没有被修改过程的 step 采用缓存。如果想要避免使用缓存,可以使用这样命令 **--no-cache**:`docker build --no-cache . --rm -t runoob/ubuntu:v1`
- `docker history`:显示生成一个镜像的历史命令,可以看出这个镜像的构建过程,包括:每一层镜像的 ID、指令
- `docker save`:将一个镜像保存为一个 tar 包,带 layers 和 tag 信息(导出一个镜像)
- `docker save 镜像ID -o /opt/test.tar`
- `docker load`:从一个 tar 包创建一个镜像(导入一个镜像)
- `docker load -i /opt/test.tar`
#### 容器生命周期管理
- `docker run`,运行镜像
- `docker run -v /java_logs/:/opt/ -d -p 8080:80 --name=myDockerNameIsGitNavi --hostname=myDockerNameIsGitNavi -i -t 镜像ID /bin/bash`
- `-i -t` 分别表示保证容器中的 STDIN 开启,并分配一个伪 tty 终端进行交互,这两个是合着用。
- `--name` 是给容器起了一个名字(如果没有主动给名字,docker 会自动给你生成一个)容器的名称规则:大小写字母、数字、下划线、圆点、中横线,用正则表达式来表达就是:[a-zA-Z0-9_*-]
- `-d` 容器运行在后台。
- `-p 8080:80` 表示端口映射,将宿主机的8080端口转发到容器内的80端口。(如果是 -P 参数,则表示随机映射应该端口,一般用在测试的时候)
- `-v /java_logs/:/opt/` 表示目录挂载,/java_logs/ 是宿主机的目录,/opt/ 是容器目录
- `docker run --rm --name=myDockerNameIsGitNavi --hostname=myDockerNameIsGitNavi -i -t centos /bin/bash`,--rm,表示退出即删除容器,一般用在做实验测试的时候
- `docker run --restart=always -i -t centos /bin/bash`,--restart=always 表示停止后会自动重启
- `docker run --restart=on-failure:5 -i -t centos /bin/bash`,--restart=on-failure:5 表示停止后会自动重启,最多重启 5 次
- `docker exec`:对守护式的容器里面执行命令,方便对正在运行的容器进行维护、监控、管理
- `docker exec -i -t 容器ID /bin/bash`,进入正在运行的 docker 容器,并启动终端交互
- `docker exec -d 容器ID touch /opt/test.txt`,已守护式的方式进入 docker 容器,并创建一个文件
- `docker stop 容器ID`,停止容器
- `docker stop $(docker ps -a -q)`,停止所有容器
- `docker stop $(docker ps -a -q) ; docker rm $(docker ps -a -q)`,停止所有容器,并删除所有容器
- `docker kill $(docker ps -q) ; docker rm $(docker ps -a -q)`,停止所有容器,并删除所有容器
- `docker start 容器ID`,重新启动已经停止的容器(重新启动,docker run 参数还是保留之前的)
- `docker restart 容器ID`,重启容器
- `docker rm`,删除容器
- `docker rm 容器ID`,删除指定容器(该容器必须是停止的)
- `docker rm -f 容器ID`,删除指定容器(该容器如果正在运行可以这样删除)
- `docker rm $(docker ps -a -q)`,删除所有容器
- `docker rm -f $(docker ps -a -q)`,强制删除所有容器
- `docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs docker rm` 删除老的(一周前创建)容器
- `docker kill $(docker ps -q) ; docker rm $(docker ps -a -q) ; docker rmi $(docker images -q -a)` 停止所有容器,删除所有容器,删除所有镜像
- `docker commit`,把容器打成镜像
- `docker commit 容器ID gitnavi/docker-nodejs-test:0.1`
- gitnavi 是你注册的 https://store.docker.com/ 的名字,如果你没有的话,那需要先注册
- docker-nodejs-test 是你为该镜像起的名字
- 0.1 是镜像的版本号,默认是 latest 版本
- `docker commit -m="这是一个描述信息" --author="GitNavi" 容器ID gitnavi/docker-nodejs-test:0.1`
- 在提交镜像时指定更多的数据(包括标签)来详细描述所做的修改
- `docker diff 容器ID`:显示容器文件系统的前后变化
- `--link` 同一个宿主机下的不同容器的连接:
- `docker run -it 镜像ID --link redis-name:myredis /bin/bash`
- `redis-name` 是容器名称
- `myredis` 是容器别名,其他容器连接它可以用这个别名来写入到自己的配置文件中
- 容器与宿主机之间文件的拷贝
- `docker cp /www/runoob 96f7f14e99ab:/www/` 将主机 /www/runoob 目录拷贝到容器 96f7f14e99ab 的 /www 目录下
- `docker cp /www/runoob 96f7f14e99ab:/www` 将主机 /www/runoob 目录拷贝到容器 96f7f14e99ab 中,目录重命名为 www。
- `docker cp 96f7f14e99ab:/www /tmp/` 将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。
#### docker 网络模式
- 查看也有网络:`docker network ls`
- 创建网络:`docker network create --subnet=172.19.0.0/16 net-redis-to-cluster`
- 已有容器连接到某个网络(一个容器可以同时连上多个网络):`docker network connect net-redis-to-cluster my-redis-container`
- 如果是内网提供服务的,可以直接创建一个网络,其服务使用该网络。然后另外一个需要调用该服务的,并且是对外网提供服务的可以使用 host 模式
- `--network XXXXXX` 常见几种模式
- bridge 默认模式,在 docker0 的网桥上创建新网络栈,确保独立的网络环境,实现网络隔离:`docker run -it 镜像ID --network=bridge /bin/bash`
- none 不适用网卡,不会有 IP,无法联网:`docker run -it 镜像ID --network=none /bin/bash`
- host 使用宿主机网络 IP、端口联网(在容器里面输入:ip a,看到的结果和在宿主机看到的一样):`docker run -it 镜像ID --network=host /bin/bash`
- 自定义-使用自己命名的网络栈,但是需要手动配置网卡、IP 信息:`docker run -it 镜像ID --network=自定义名称 /bin/bash`
#### 容器管理操作
- `docker ps`:列出当前所有 **正在运行** 的容器
- `docker ps -a`:列出所有的容器(包含历史,即运行过的容器)
- `docker ps -l`:列出最近一次启动的container
- `docker ps -q`:列出最近一次运行的container ID
- `docker ps -a -l`:列出最后一次运行的容器
- `docker ps -n x`:显示最后 x 个容器,不管是正在运行或是已经停止的
- `docker top 容器ID`:显示容器的进程信息
- `docker events`:得到 docker 服务器的实时的事件
- `docker logs -f 容器ID`:查看容器日志(如果一些容器不断重启,或是自动停止,可以这样看下)
- `docker logs 容器ID`,获取守护式容器的日志
- `docker logs -f 容器ID`,不断监控容器日志,类似 tail -f
- `docker logs -ft 容器ID`,在 -f 的基础上又增加 -t 表示为每条日志加上时间戳,方便调试
- `docker logs --tail 10 容器ID`,获取日志最后 10 行
- `docker logs --tail 0 -f 容器ID`,跟踪某个容器的最新日志而不必读取日志文件
- `docker logs -f -t --since="2018-05-26" --tail=200 容器ID` 根据某个时间读取日志
- `docker logs -f -t --since="2018-05-26T11:13:40" --tail=200 容器ID` 根据某个时间读取日志
- `docker logs -f -t --since="2018-05-25T11:13:40" --until "2018-05-26T11:13:40" --tail=200 容器ID` 根据某个时间读取日志
- `docker logs --since 10m 容器ID` 查看最近 10 分钟的日志
- `-f` : 表示查看实时日志
- `-t` : 显示时间戳
- `-since` : 显示某个开始时间的所有日志
- `-tail=200` : 查看最后的 200 条日志
- `docker wait`,阻塞到一个容器,直到容器停止运行
- `docker export`,将容器整个文件系统导出为一个tar包,不带layers、tag等信息
- `docker port`,显示容器的端口映射
- `docker inspect 容器ID`:查看容器的全面信息,用 JSON 格式输出
- `docker inspect network名称`:查看 network 信息,用 JSON 格式输出,包含使用该网络的容器有哪些
- `docker system df`:类似于 Linux 上的 df 命令,用于查看 Docker 的磁盘使用情况
- Images 镜像
- Containers 容器
- Local Volumes 数据卷
```
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 6 6 1.049GB 0B (0%)
Containers 7 4 10.25kB 0B (0%)
Local Volumes 13 5 38.49GB 1.365MB (0%)
Build Cache 0B 0B
```
```
获取容器中的 IP:docker inspect -f {{.NetworkSettings.IPAddress}} 容器ID
获取容器中的 IP:docker inspect -f {{.Volumes}} 容器ID
查看容器的挂载情况:docker inspect 容器ID | grep Mounts -A 10
```
- 下面为一个 docker inspect 后的结果示例:
```json
[
{
"Id": "e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b",
"Created": "2018-01-18T03:47:16.138180181Z",
"Path": "docker-entrypoint.sh",
"Args": [
"--auth"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 19952,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-01-18T03:47:16.348568927Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:42aa46cfbd7a0d1101311defac39872b447b32295b40f9c99104ede5d02e9677",
"ResolvConfPath": "/var/lib/docker/containers/e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b/hostname",
"HostsPath": "/var/lib/docker/containers/e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b/hosts",
"LogPath": "/var/lib/docker/containers/e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b/e1dff77b99d9c8489e0a0ce68a19ec5ffe18cc5d8b8ec17086f7f7bea29aa09b-json.log",
"Name": "/cas-mongo",
"RestartCount": 0,
"Driver": "overlay",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/data/mongo/db:/data/db"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"27017/tcp": [
{
"HostIp": "",
"HostPort": "27017"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay/0ab08b1f9c8f5f70cdcac2b01d9ee31de9e5a4955003567573635e8837931249/root",
"MergedDir": "/var/lib/docker/overlay/4d6bb0d57f3f1b1dcf98c70b4bee4abf8dc110c7efa685ee5d84fe6f58c07b63/merged",
"UpperDir": "/var/lib/docker/overlay/4d6bb0d57f3f1b1dcf98c70b4bee4abf8dc110c7efa685ee5d84fe6f58c07b63/upper",
"WorkDir": "/var/lib/docker/overlay/4d6bb0d57f3f1b1dcf98c70b4bee4abf8dc110c7efa685ee5d84fe6f58c07b63/work"
},
"Name": "overlay"
},
"Mounts": [
{
"Type": "volume",
"Name": "6cd9721ff6a2768cd20e4a0678b176fa81a5de1c7d21fe6212b50c6854196db2",
"Source": "/var/lib/docker/volumes/6cd9721ff6a2768cd20e4a0678b176fa81a5de1c7d21fe6212b50c6854196db2/_data",
"Destination": "/data/configdb",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Type": "bind",
"Source": "/data/mongo/db",
"Destination": "/data/db",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "e1dff77b99d9",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"27017/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"GPG_KEYS=0C49F3730359A14518585931BC711F9BA15703C6",
"MONGO_PACKAGE=mongodb-org",
"MONGO_REPO=repo.mongodb.org",
"MONGO_MAJOR=3.4",
"MONGO_VERSION=3.4.10"
],
"Cmd": [
"--auth"
],
"Image": "mongo:3.4",
"Volumes": {
"/data/configdb": {},
"/data/db": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "7eabf418238f4d9f5fd5163fd4d173bbaea7764687a5cf40a9757d42b90ab2f9",
"HairpinMode": false,
"Link LocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"27017/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "27017"
}
]
},
"SandboxKey": "/var/run/docker/netns/7eabf418238f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "11c8d10a4be63b4ed710add6c440adf9d090b71918d4aaa837c46258e5425b80",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "ada97659acda146fc57e15a099e430a6e97de87f6d043b91d4c3582f6ab52d47",
"EndpointID": "11c8d10a4be63b4ed710add6c440adf9d090b71918d4aaa837c46258e5425b80",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
```
## Docker 容器产生的 log 位置
- Docker 运行一段时间,如果你的容器有大量的输出信息,则这个 log 文件会非常大,所以要考虑清理。
- log 位置:`/var/lib/docker/containers/容器ID值/容器ID值-json.log`
- 可以考虑在停到容器的时候备份这个文件到其他位置,然后:`echo > 容器ID值-json.log`
- 当然,官网也提供了自动化的方案:
- 修改 Docker 是配置文件:`vim /etc/docker/daemon.json`,(如果没有这个文件,自己新增)增加如下内容:
``` bash
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5"
}
}
```
- 如果你已经有该文件文件莱使用国内源,那修改方案应该是这样的:
``` bash
{
"registry-mirrors": ["https://ldhc17y9.mirror.aliyuncs.com"],
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "5"
}
}
```
## 删除 Docker 镜像中为 none 的镜像
- Dockerfile 代码更新频繁,自然 docker build 构建同名镜像也频繁的很,产生了众多名为 none 的无用镜像
```
docker rmi $(docker images -f "dangling=true" -q)
```
## Docker daemon.json 可配置参数
-
## Docker remote api 远程操作配置(保证在内网环境)
- 假设要被远程操作的服务器 IP:`192.168.1.22`
- 修改其配置文件:`vim /lib/systemd/system/docker.service`
- 修改默认值为:`ExecStart=/usr/bin/dockerd`
- 改为:`ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376`
- 如果还需要连自己的 harbor 这类,完整配置:`ExecStart=/usr/bin/dockerd --insecure-registry harbor.youmeek.com -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2376`
- `systemctl daemon-reload`
- `systemctl reload docker`
- `systemctl restart docker`
- 验证:
- 在其他服务器上运行:`docker -H 192.168.1.22:2376 images `
- 能拿到和它本身看到的一样的数据表示可以了
## Dockerfile 解释
- 该文件名就叫 Dockerfile,注意大小写,没有后缀,否则会报错。
- 主要由下面几个部分组成:
- 基础镜像信息
- 维护者/创建者信息
- 镜像操作指令
- 容器启动时执行执行
- 注释符号:`# 这是一段注释说明`
- 常用指令关键字:
- `FROM`,基础镜像信息
- `MAINTAINER`,维护者/创建者信息
- `ADD`,添加文件。如果添加的文件是类似 tar.gz 压缩包,会自动解压。
- 特别注意的是:ADD 文件到镜像的地址如果是目录,则需要最后保留斜杠,比如:`ADD test.tar.gz /opt/shell/`。不是斜杠结尾会认为是文件。
- 添加文件格式:`ADD test.sh /opt/shell/test.sh`
- 添加压缩包并解压格式:`ADD test.tar.gz /opt/shell/`,该压缩包会自动解压在 /opt/shell 目录下
- `COPY`,类似 ADD,只是 COPY 只是复制文件,不会做类似解压压缩包这种行为。
- `COPY /opt/conf/ /etc/` 把宿主机的 /opt/conf 下文件复制到镜像的 /etc 目录下。
- `WORKDIR`,设置工作目录,可以理解为类似 cd 命令,表示现在在某个目录路径,然后下面的 CMD、ENTRYPOINT 操作都是基于此目录
- `VOLUME`,目录挂载
- `EXPOSE`,暴露端口
- `USER`,指定该镜像以什么用户去运行,也可以用这个来指定:`docker run -u root`。不指定默认是 root
- `ENV`,定义环境变量,该变量可以在后续的任何 RUN 指令中使用,使用方式:$HOME_DIR。在 docker run 的时候可以该方式来覆盖变量值 `docker run -e “HOME_DIR=/opt”`
- `RUN`,执行命令并创建新的镜像层,RUN 经常用于安装软件包
- `CMD`,执行命令,并且一个 Dockerfile 只能有一条 CMD,有多条的情况下最后一条有效。在一种场景下 CMD 命令无效:docker run 的时候也指定了相同命令,则 docker run 命令优先级最高
- `ENTRYPOINT`,配置容器启动时运行的命令,不会被 docker run 指令覆盖,并且 docker run 的指令可以作为参数传递到 ENTRYPOINT 中。要覆盖 ENTRYPOINT 命令也是有办法的:docker run --entrypoint 方式。Dockerfile 同时有 CMD 和 ENTRYPOINT 的时候,CMD 的指令是作为参数传递给 ENTRYPOINT 使用。
- 特别注意:RUN、CMD 和 ENTRYPOINT 这三个 Dockerfile 指令看上去很类似,很容易混淆。
- 最佳实战:[来源](https://www.ibm.com/developerworks/community/blogs/132cfa78-44b0-4376-85d0-d3096cd30d3f/entry/RUN_vs_CMD_vs_ENTRYPOINT_%E6%AF%8F%E5%A4%A95%E5%88%86%E9%92%9F%E7%8E%A9%E8%BD%AC_Docker_%E5%AE%B9%E5%99%A8%E6%8A%80%E6%9C%AF_17?lang=en_us)
- 使用 RUN 指令安装应用和软件包,构建镜像。
- 如果 Docker 镜像的用途是运行应用程序或服务,比如运行一个 MySQL,应该优先使用 Exec 格式的 ENTRYPOINT 指令。CMD 可为 ENTRYPOINT 提供额外的默认参数,同时可利用 docker run 命令行替换默认参数。
- 如果想为容器设置默认的启动命令,可使用 CMD 指令。用户可在 docker run 命令行中替换此默认命令。
## Dockerfile 部署 Spring Boot 应用
- jar 名称:skb-user-0.0.1-SNAPSHOT.jar
- 打算用的宿主机端口:9096
- Dockerfile 文件和 jar 文件存放在宿主机目录:/opt/zch
- Dockerfile 内容如下:
``` bash
FROM java:8-jre
MAINTAINER gitnavi
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD skb-user-0.0.1-SNAPSHOT.jar /usr/local/skb/user/
CMD ["java", "-Xmx500m", "-jar", "/usr/local/skb/user/skb-user-0.0.1-SNAPSHOT.jar", "--spring.profiles.active=test"]
EXPOSE 9096
```
- 开始构建:
- `cd /opt/zch`
- `docker build . --tag="skb/user:v1.0.1"`
- 因为 build 过程中会有多层镜像 step 过程,所以如果 build 过程中失败,那解决办法的思路是找到 step 失败的上一层,成功的 step 中镜像 ID。然后 docker run 该镜像 ID,手工操作,看报什么错误,然后就比较清晰得了解错误情况了。
- `docker run -d -p 9096:9096 -v /usr/local/logs/:/opt/ --name=skbUser --hostname=skbUser skb/user:v1.0.1`
- 查看启动后容器列表:`docker ps`
- jar 应用的日志是输出在容器的 /opt 目录下,因为我们上面用了挂载,所在在我们宿主机的 /usr/local/logs 目录下可以看到输出的日志
- 防火墙开放端口:
- `firewall-cmd --zone=public --add-port=9096/tcp --permanent`
- `firewall-cmd --reload`
- 解释:
```
# 是为了解决容器的时区和宿主机不一致问题
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
```
## Dockerfile 部署 Tomcat 应用
- 编写 Dockerfile
```
FROM tomcat:8.0.46-jre8
MAINTAINER GitNavi
ENV JAVA_OPTS="-Xms2g -Xmx2g -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=312M"
ENV CATALINA_HOME /usr/local/tomcat
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN rm -rf /usr/local/tomcat/webapps/*
ADD qiyeweixin.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
```
- 打包镜像:`docker build -t harbor.gitnavi.com/demo/qiyeweixin:1.2.2 ./`
- 运行:`docker run -d -p 8888:8080 --name=qiyeweixin --hostname=qiyeweixin -v /data/docker/logs/qiyeweixin:/data/logs/qiyeweixin harbor.gitnavi.com/demo/qiyeweixin:1.2.2`
- 带 JVM 参数运行:`docker run -d -p 8888:8080 -e JAVA_OPTS='-Xms7g -Xmx7g -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=512M' --name=qiyeweixin --hostname=qiyeweixin -v /data/docker/logs/qiyeweixin:/data/logs/qiyeweixin harbor.gitnavi.com/demo/qiyeweixin:1.2.2`
- 虽然 Dockerfile 已经有 JVM 参数,并且也是有效的。但是如果 docker run 的时候又带了 JVM 参数,则会以 docker run 的参数为准
- 测试 JVM 是否有效方法,在代码里面书写,该值要接近 xmx 值:
```
long maxMemory = Runtime.getRuntime().maxMemory();
logger.warn("-------------maxMemory=" + ((double) maxMemory / (1024 * 1024)));
```
## Docker Compose
- Docker Compose 主要用于定义和运行多个 Docker 容器的工具,这样可以快速运行一套分布式系统
- 容器之间是有依赖关系,比如我一个 Java web 系统依赖 DB 容器、Redis 容器,必须这些依赖容器先运行起来。
- 一个文件:docker-compose.yml
- 一个命令:`docker-compose up`
- 指定文件:`docker-compose -f zookeeper.yml -p zk_test up -d`
- 官网安装说明:
- 安装方法:
```
sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
```
- 检查是否安装成功:`docker-compose --version`,输出:`docker-compose version 1.18.0, build 8dd22a9`
- 常用命令:
- 运行:`docker-compose up -d`
- 停止运行:`docker-compose down`
- 查看容器:`docker-compose ps`
- 删除停止的服务容器:`docker-compose rm`
## Docker Swarm
- Docker Swarm 是一个 Docker 集群管理工具
## Harbor 镜像私有仓库
- 官网:
## 资料
- 书籍:《第一本 Docker 书》
- []()
- []()
- []()
- []()
- []()
- []()
================================================
FILE: markdown-file/Dubbo-Install-And-Settings.md
================================================
# Dubbo 环境安装和配置
## Dubbo-Admin 搭建
### 需要环境
- CentOS 6
- JDK 1.8(必须是 1.8)
- Tomcat 7 或 8(我测试都可以)
- Dubbo 版本:2.5.4-SNAPSHOT(当前这个版本是最新的。2.5.3 我测试是不行的)
- Dubbo-Admin 需要修改部分代码,让它支持 JDK 8,具体看文章:
- 最终我的 Dubbo-admin 的 pom.xml 为这样的:
``` xml
4.0.0
com.alibaba
dubbo-parent
2.5.4-SNAPSHOT
dubbo-admin
war
${project.artifactId}
The admin module of dubbo project
1.5
/
false
false
com.alibaba
dubbo
${project.parent.version}
org.springframework
spring
com.alibaba.citrus
citrus-webx-all
3.1.6
org.apache.velocity
velocity
1.7
org.javassist
javassist
org.jboss.netty
netty
org.apache.mina
mina-core
org.glassfish.grizzly
grizzly-core
org.apache.httpcomponents
httpclient
com.alibaba
fastjson
com.thoughtworks.xstream
xstream
org.apache.bsf
bsf-api
org.apache.zookeeper
zookeeper
com.github.sgroschupf
zkclient
com.netflix.curator
curator-framework
com.googlecode.xmemcached
xmemcached
org.apache.thrift
libthrift
com.caucho
hessian
javax.servlet
servlet-api
provided
log4j
log4j
org.slf4j
slf4j-api
org.slf4j
slf4j-log4j12
redis.clients
jedis
javax.validation
validation-api
org.hibernate
hibernate-validator
javax.cache
cache-api
org.mortbay.jetty
maven-jetty-plugin
${jetty_version}
/
10
8080
60000
```
- 部署在 Tomcat 之后,如果需要修改 zookeeper 的地址,以及默认用户的登录密码,可以在这里改:`vim /usr/program/tomcat8/webapps/ROOT/WEB-INF/dubbo.properties`
- 里面内容:
``` ini
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
```
- 如果有多个节点构成的集群也可以这样写:
``` ini
dubbo.registry.address=zookeeper://192.168.1.121:2181?backup=192.168.1.111:2181,192.168.1.112:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest
```
## Dubbox-Admin 搭建
### 需要环境
- CentOS 6
- JDK 1.8(只测试过 1.8)
- Tomcat 7 或 8(只测试过 8)
- Dubbox 版本:dubbo-admin-2.8.4.war(fork 官网最新版本,自己编译的版本)
- 不需要修改任何 pom.xml 文件,直接就可以运行。
================================================
FILE: markdown-file/ELK-Install-And-Settings.md
================================================
# ELK(Elasticsearch、Logstash、Kibana)安装和配置
## 版本说明
- 本文包含了:Elasticsearch 2.4.X 和 Elasticsearch 5.2.X 和 Elasticsearch 5.5.X,请有针对性地选择。
## 教程说明
- 官网:
- 官网总文档:
- 官网最终指南:
- 官网对各个系统的支持列表:
- 5.2 版本有一个设置的新特性必须了解,测试建议我们用 CentOS 7:
- Elasticsearch 开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful 风格接口,多数据源,自动搜索负载等。
- Logstash 日志进行收集、分析,并将其存储供以后使用(如,搜索)
- kibana 为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。
### Elasticsearch 部署
- 请看 Elasticsearch 专题文:[Elasticsearch 相关知识](Elasticsearch-Base.md)
### logstash
- 请看 logstash 专题文:[logstash 相关知识](Logstash-Base.md)
## 资料
-
-
-
-
- <>
- <>
================================================
FILE: markdown-file/Elasticsearch-Base.md
================================================
# Elasticsearch 知识
## Docker 单节点部署
- 官网:
- 官网列表:
- 阿里云支持版本:
- 阿里云有一个 `插件配置` 功能,常用的 Elasticsearch 插件都带了,勾选下即可安装。也支持上传安装。
- 注意:docker 版本下 client.transport.sniff = true 是无效的。
#### 5.6.x
- `vim ~/elasticsearch-5.6.8-docker.yml`
- 启动:`docker-compose -f ~/elasticsearch-5.6.8-docker.yml -p elasticsearch_5.6.8 up -d`
```
version: '3'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.8
container_name: elasticsearch-5.6.8
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "cluster.name=elasticsearch"
- "network.host=0.0.0.0"
- "http.host=0.0.0.0"
- "xpack.security.enabled=false"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- 9200:9200
- 9300:9300
volumes:
- /data/docker/elasticsearch/data:/usr/share/elasticsearch/data
```
#### 6.7.x(带 ik 分词)
- `vim ~/elasticsearch-6.7.2-docker.yml`
- 启动:`docker-compose -f ~/elasticsearch-6.7.2-docker.yml -p elasticsearch_6.7.2 up -d`
- `mkdir -p /data/docker/elasticsearch-6.7.2/data`
- 如果官网镜像比较慢可以换成阿里云:`registry.cn-hangzhou.aliyuncs.com/elasticsearch/elasticsearch:6.7.2`
- 下载 ik 分词(版本必须和 Elasticsearch 版本对应,包括小版本号):
```
version: '3'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:6.7.2
container_name: elasticsearch-6.7.2
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "cluster.name=elasticsearch"
- "network.host=0.0.0.0"
- "http.host=0.0.0.0"
- "xpack.security.enabled=false"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
ports:
- 9200:9200
- 9300:9300
volumes:
- /data/docker/elasticsearch-6.7.2/data:/usr/share/elasticsearch/data
- /data/docker/ik:/usr/share/elasticsearch/plugins/ik
```
- Elasticsearch Head 插件地址:
- 测试:
```
http://localhost:9200/
_analyze?pretty POST
{"analyzer":"ik_smart","text":"安徽省长江流域"}
```
- ik_max_word 和 ik_smart 什么区别?
```
ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合,适合 Term Query;
ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”,适合 Phrase 查询。
```
-------------------------------------------------------------------
## Elasticsearch 6.5.x 安装(适配与 5.5.x,6.6.x)
#### 环境
- CentOS 7.x
- 至少需要 2G 内存
- root 用户
- JDK 版本:1.8(最低要求),主推:JDK 1.8.0_121 以上
- 关闭 firewall
- `systemctl stop firewalld.service` #停止firewall
- `systemctl disable firewalld.service` #禁止firewall开机启动
#### 先配置部分系统变量
- 更多系统层面的配置可以看官网:
- 配置系统最大打开文件描述符数:`vim /etc/sysctl.conf`
```
fs.file-max=65535
vm.max_map_count=262144
```
- 配置进程最大打开文件描述符:`vim /etc/security/limits.conf`
```
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
* soft nofile 262144
* hard nofile 262144
```
#### 开始安装
- 检查:`rpm -qa | grep elastic`
- 卸载:`rpm -e --nodeps elasticsearch`
- 官网 RPM 安装流程(重要,以下资料都是对官网的总结):
- 导入 KEY:`rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch`
- 新建文件:`vim /etc/yum.repos.d/elasticsearch.repo`
- 内容如下(6.x):
```
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
- 内容如下(5.x):
```
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
```
- 开始安装:`yum install -y elasticsearch`,预计文件有 108M 左右,国内网络安装可能会很慢,慢慢等
- 安装完后会多了一个:elasticsearch 用户和组
- 设置 java 软链接:`ln -s /usr/local/jdk1.8.0_181/jre/bin/java /usr/local/sbin/java`
- 启动和停止软件(默认是不启动的):
- 启动:`systemctl start elasticsearch.service`
- 状态:`systemctl status elasticsearch.service`
- 停止:`systemctl stop elasticsearch.service`
- 重新启动:`systemctl restart elasticsearch.service`
- 安装完成后,增加系统自启动:
- `/bin/systemctl daemon-reload`
- `/bin/systemctl enable elasticsearch.service`
- 检查:`curl -X GET "localhost:9200/"`
#### RPM 安装后的一些配置位置说明
- 更多说明可以看官网:
- 更加详细的配置可以看:
- 默认系统生成了一个 elasticsearch 用户,下面的目录权限属于该用户
- Elasticsearch 安装后位置:`/usr/share/elasticsearch`
- Elasticsearch 的软件环境、堆栈的设置:`/etc/sysconfig/elasticsearch`
- Elasticsearch 的集群设置:`/etc/elasticsearch/elasticsearch.yml`
- Log 位置:`/var/log/elasticsearch/`
- 索引数据位置:`/var/lib/elasticsearch`
- 插件位置:`/usr/share/elasticsearch/plugins`
- 脚本文件位置:`/etc/elasticsearch/scripts`
#### 配置
- 编辑配置文件:`vim /etc/elasticsearch/elasticsearch.yml`
- 默认只能 localhost 访问,修改成支持外网访问
```
打开这个注释:#cluster.name: my-application
集群名称最好是自己给定,不然有些 client 端会连不上,或者要求填写
打开这个注释:#network.host: 192.168.0.1
改为:network.host: 0.0.0.0
```
#### 安装 X-Pack(6.5.x 默认带了 x-pack)
- `cd /usr/share/elasticsearch && bin/elasticsearch-plugin install x-pack`
#### GUI 客户端工具
- 优先推荐:
-
#### 安装 Chrome 扩展的 Head
- 下载地址:
#### 其他细节
- 如果就单个节点测试,新建索引的时候副本数记得填 0。
#### 创建索引并设置 mapping
- 官网类型说明:
```
curl -XPUT 'http://127.0.0.1:9200/grafanadb' -H 'Content-Type: application/json' -d'
{
"settings": {
"refresh_interval": "5s",
"number_of_shards": 5,
"number_of_replicas": 0
},
"mappings": {
"radar": {
"properties": {
"request_num": {
"type": "long"
},
"post_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
}
}
}
}
}
'
```
#### 批量增加 / 删除测试数据
- 官网文档:
- 批量增加,cURL 格式:
```
curl -X POST "http://127.0.0.1:9200/_bulk" -H 'Content-Type: application/json' -d'
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100001" } }
{ "post_date" : "2018-12-01 10:00:00", "request_num" : 1 }
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100002" } }
{ "post_date" : "2018-12-01 10:00:05", "request_num" : 2 }
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100003" } }
{ "post_date" : "2018-12-01 10:00:10", "request_num" : 3 }
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100004" } }
{ "post_date" : "2018-12-01 10:00:15", "request_num" : 4 }
{ "index" : { "_index" : "grafanadb", "_type" : "radar", "_id" : "100005" } }
{ "post_date" : "2018-12-01 10:00:20", "request_num" : 5 }
'
```
- 批量删除,cURL 格式:
```
curl -X POST "http://127.0.0.1:9200/_bulk" -H 'Content-Type: application/json' -d'
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100001" } }
{ "delete": { "_index": "grafanadb", "_type": "radar", "_id": "100002" } }
'
```
- 清空索引所有数据,分成5个切片去执行删除,cURL 格式:
```
curl -X POST "http://127.0.0.1:9200/索引名称/类型名称/_delete_by_query?refresh&slices=5&pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'
```
-------------------------------------------------------------------------------------------------------------------
## Elasticsearch 5.2.0 安装
- 官网下载地址:
- Elasticsearch 5.2.0 版本下载地址(32M):
### 环境
- 机子 IP:192.168.1.127
- CentOS 7.3
- JDK 版本:1.8(最低要求),主推:JDK 1.8.0_121 以上
- Elasticsearch 版本:5.2.0
- 关闭 firewall
- `systemctl stop firewalld.service` #停止firewall
- `systemctl disable firewalld.service` #禁止firewall开机启动
### zip 解压安装
- 官网总的安装文档:
- 我的解压目录:`/usr/program`,解压包名:`elasticsearch-5.2.0.zip`
- 解压:`cd /usr/program ; unzip elasticsearch-5.2.0.zip`
- 删除掉压缩包:`rm -rf elasticsearch-5.2.0.zip`
- 添加组和用户
- 该版本不能使用 root 用户进行使用
- `useradd elasticsearch -p 123456`,添加一个名为 elasticsearch 的用户,还有一个同名的组
- 添加数据目录:`mkdir -p /opt/elasticsearch/data /opt/elasticsearch/log`
- 赋权限:
- `chown -R elasticsearch:elasticsearch /usr/program/elasticsearch-5.2.0 /opt/elasticsearch`
- 编辑配置文件:`vim /usr/program/elasticsearch-5.2.0/config/elasticsearch.yml`,打开下面注释,并修改
``` nginx
cluster.name: youmeek-cluster
node.name: youmeek-node-1
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/log
bootstrap.memory_lock: true
network.host: 0.0.0.0 # 也可以是本机 IP
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.1.127"] #如果有多个机子集群,这里就写上这些机子的 IP,格式:["192.168.1.127","192.168.1.126"]
```
- 重点说明:Elasticsearch 的集群环境,主要就是上面这段配置文件内容的差别。如果有其他机子:node.name、discovery.zen.ping.unicast.hosts 需要改下。集群中所有机子的配置文件中 discovery.zen.ping.unicast.hosts 都要有所有机子的 IP 地址。
- 修改这个配置文件,不然无法锁内存:`vim /etc/security/limits.conf`
- 在文件最尾部增加下面内容:
``` nginx
# allow user 'elasticsearch' mlockall
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
* soft nofile 262144
* hard nofile 262144
```
- 修改:`vim /etc/sysctl.conf`,添加下面配置
``` ini
vm.max_map_count=262144
```
- 重启机子:`reboot`。
- 切换用户:`su elasticsearch`
- 控制台运行(启动比较慢):`cd /usr/program/elasticsearch-5.2.0 ; ./bin/elasticsearch`
- 后台运行:`cd /usr/program/elasticsearch-5.2.0 ; ./bin/elasticsearch -d -p 自定义pid值`
- 在本机终端输入该命令:`curl -XGET 'http://192.168.1.127:9200'`,(也可以用浏览器访问:)如果能得到如下结果,则表示启动成功:
``` json
{
"name" : "youmeek-node-1",
"cluster_name" : "youmeek-cluster",
"cluster_uuid" : "c8RxQdOHQJq-Tg8rrPi_UA",
"version" : {
"number" : "5.2.0",
"build_hash" : "24e05b9",
"build_date" : "2017-01-24T19:52:35.800Z",
"build_snapshot" : false,
"lucene_version" : "6.4.0"
},
"tagline" : "You Know, for Search"
}
```
## 安装 Kibana 5.2.0
- 官网下载地址:
- Kibana 5.2.0 版本下载地址(36M):
- Kibana 5.2.0 官网文档:
- Kibana 5.2.0 官网安装文档:
### tar.gz 解压安装
- 安装目录:/usr/program
- 解压:`cd /usr/program ; tar zxvf kibana-5.2.0-linux-x86_64.tar.gz`
- 删除压缩包:`rm -rf kibana-5.2.0-linux-x86_64.tar.gz`
- 修改解压后的目录名称:`mv kibana-5.2.0-linux-x86_64 kibana-5.2.0`
- 修改配置:`vim /usr/program/kibana-5.2.0/config/kibana.yml`,默认配置都是注释的,我们这里打开这些注释:
``` nginx
server.port: 5601
server.host: "0.0.0.0" # 请将这里改为 0.0.0.0 或是当前本机 IP,不然可能会访问不了
erver.name: "youmeek-kibana"
elasticsearch.url: "http://192.168.1.127:9200"
elasticsearch.username: "elasticsearch"
elasticsearch.password: "123456"
```
- 运行:`cd /usr/program/kibana-5.2.0 ; ./bin/kibana`
- 浏览器访问:,可以看到 Kibana `Configure an index pattern` 界面
- 访问 Dev Tools 工具,后面写 DSL 语句会常使用该功能:
## Beats
### Beats 资料
- Beats 官网:
- Beats 简单介绍:日志数据搜集器。一般安装在需要收集日志的服务器上,然后把收集的数据发送到 Elasticsearch 或是先发送到 logstash 清洗整理(解析过滤)后再发送到 Elasticsearch。
- logstash 也有收集日志的功能,只是它相对 Beats 更加消耗 CPU 和内存,所以一般使用 Beats 收集日志。
- 目前常见的 Beats 类型:
- Filebeat(搜集文件数据);
- Packetbeat(搜集网络流量数据);
- Metricbeat(搜集系统、进程和文件系统级别的 CPU 和内存使用情况等数据);
- Winlogbeat(搜集 Windows 事件日志数据)。
- Heartbeat(主动探测服务是否可用)。
## 安装 X-Pack 或是其他插件
- X-Pack 是官网提供的管理增强工具,但是全部功能收费,有一个月使用,有部分功能免费。其他免费的插件。
- licence 的用法可以看这篇文章:
-
-
- 破解:
- 免费插件:
- head - 节点数据查看管理:
- kopf - 集群管理:
- 官网说明:
- 安装(过程比较慢):`/usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack`
- 如果线上安装速度太慢,那就离线安装:
- 下载,我放在 /opt 目录下(119M):`wget https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-5.2.2.zip`
- 安装:`/usr/share/elasticsearch/bin/elasticsearch-plugin install file:///opt/x-pack-5.2.2.zip`
- 卸载:`/usr/share/elasticsearch/bin/elasticsearch-plugin remove x-pack`
- 安装后重启服务,重启后访问你会发现需要用户和密码,我们可以关掉这个,在 elasticsearch.yml 中添加:`xpack.security.enabled: false`
- 其他 5.2 资料:
-
-
-
-
-
-
-
-
-
-------------------------------------------------------------------------------------------------------------------
## 2.4.X
### 安装 elasticsearch 集群
### 下载
- 下载在我个人习惯的子自己创建的目录下:/usr/program/elk
- elasticsearch 2.4.1(26 M):`wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.4.1.tar.gz`
- logstash 2.4.0(80 M):`wget https://download.elastic.co/logstash/logstash/logstash-2.4.1.tar.gz`
- kibana 4.6.1(32 M):`wget https://download.elastic.co/kibana/kibana/kibana-4.6.1-linux-x86_64.tar.gz`
### tar 解压安装
- **确保系统安装有 JDK**
- 官网文档:
- 添加日志存放目录、数据存放目录:`mkdir -p /opt/elasticsearch/data /opt/elasticsearch/log`
- 添加组和用户
- 该版本不能使用 root 用户进行使用
- `useradd elasticsearch -p 123456`,添加一个名为 elasticsearch 的用户,还有一个同名的组
- 解压下载的文件
- `cd /usr/program/elk`
- `tar zxvf elasticsearch-2.4.1.tar.gz`
- 赋权限:
- `chown -R elasticsearch:elasticsearch /usr/program/elk /opt/elasticsearch`
- 我 tar 安装后一些路径说明:
- home:`/usr/program/elk/elasticsearch-2.4.1`
- bin:`/usr/program/elk/elasticsearch-2.4.1/bin`
- 配置文件:`/usr/program/elk/elasticsearch-2.4.1/config/elasticsearch.yml`
- plugins:`/usr/program/elk/elasticsearch-2.4.1/plugins`
- script:`/usr/program/elk/elasticsearch-2.4.1/scripts`
- data:`/opt/elasticsearch/data`
- log:`/opt/elasticsearch/log/集群名称.log`
- 编辑配置文件:`vim /usr/program/elk/elasticsearch-2.4.1/config/elasticsearch.yml`,打开下面注释,并修改
``` nginx
cluster.name: gitnavi-cluster
node.name: gitnavi-node-1
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/log
bootstrap.memory_lock: true
network.host: 0.0.0.0 # 也可以是本机 IP
http.port: 9200
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: ["192.168.1.127", "192.168.1.126"] #这个为两台机子的 IP 地址
```
- 修改这个配置文件,不然无法锁内存:`vim /etc/security/limits.conf`
- 在文件最尾部增加下面内容:
``` nginx
# allow user 'elasticsearch' mlockall
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
* soft nofile 262144
* hard nofile 262144
```
- 关闭 firewall
- `systemctl stop firewalld.service` #停止firewall
- `systemctl disable firewalld.service` #禁止firewall开机启动
- 切换到 elasticsearch 用户下:`su elasticsearch`
- 带控制台的启动(比较慢):`/usr/program/elk/elasticsearch-2.4.1/bin/elasticsearch`
- 控制台会输出类似这样的信息:
```
[2017-03-13 18:42:51,170][INFO ][node ] [gitnavi-node-1] version[2.4.1], pid[21156], build[c67dc32/2016-09-27T18:57:55Z]
[2017-03-13 18:42:51,177][INFO ][node ] [gitnavi-node-1] initializing ...
[2017-03-13 18:42:51,821][INFO ][plugins ] [gitnavi-node-1] modules [reindex, lang-expression, lang-groovy], plugins [head, kopf], sites [head, kopf]
[2017-03-13 18:42:51,852][INFO ][env ] [gitnavi-node-1] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [12.4gb], net total_space [17.4gb], spins? [unknown], types [rootfs]
[2017-03-13 18:42:51,852][INFO ][env ] [gitnavi-node-1] heap size [1015.6mb], compressed ordinary object pointers [true]
[2017-03-13 18:42:54,094][INFO ][node ] [gitnavi-node-1] initialized
[2017-03-13 18:42:54,094][INFO ][node ] [gitnavi-node-1] starting ...
[2017-03-13 18:42:54,175][INFO ][transport ] [gitnavi-node-1] publish_address {192.168.1.127:9300}, bound_addresses {[::]:9300}
[2017-03-13 18:42:54,178][INFO ][discovery ] [gitnavi-node-1] gitnavi-cluster/-XywT60EScO-9lgzjfnsgg
[2017-03-13 18:42:57,344][INFO ][cluster.service ] [gitnavi-node-1] new_master {gitnavi-node-1}{-XywT60EScO-9lgzjfnsgg}{192.168.1.127}{192.168.1.127:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2017-03-13 18:42:57,410][INFO ][gateway ] [gitnavi-node-1] recovered [0] indices into cluster_state
[2017-03-13 18:42:57,414][INFO ][http ] [gitnavi-node-1] publish_address {192.168.1.127:9200}, bound_addresses {[::]:9200}
[2017-03-13 18:42:57,414][INFO ][node ] [gitnavi-node-1] started
```
- 守护进程方式启动:`/usr/program/elk/elasticsearch-2.4.1/bin/elasticsearch -d`
- 守护进程方式停止:`ps -ef|grep elasticsearc`,只能通过 kill pid 来结束
- 访问:`http://192.168.1.127:9200/`,可以看到如下内容:
``` json
{
"name" : "gitnavi-node-1",
"cluster_name" : "gitnavi-cluster",
"cluster_uuid" : "0b66dYpnTd-hh7x4Phfm1A",
"version" : {
"number" : "2.4.1",
"build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
"build_timestamp" : "2016-09-27T18:57:55Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
"tagline" : "You Know, for Search"
}
```
- 插件(插件的迭代很容易跟不上官网的版本,所以请牢记关注插件官网的说明)
- head,节点数据查看管理:
- kopf,集群管理:
- Bigdesk,监控查看CPU内存索引数据搜索情况http连接数:
- 安装(过程比较慢)
- head:`/usr/program/elk/elasticsearch-2.4.1/bin/plugin install mobz/elasticsearch-head`
- 安装完的访问地址:`http://192.168.1.127:9200/_plugin/head`
- kopf:`/usr/program/elk/elasticsearch-2.4.1/bin/plugin install lmenezes/elasticsearch-kopf`
- 安装完的访问地址:`http://192.168.1.127:9200/_plugin/kopf`
- Bigdesk:`/usr/program/elk/elasticsearch-2.4.1/bin/plugin install hlstudio/bigdesk`
- 安装完的访问地址:`http://192.168.1.127:9200/_plugin/bigdesk`
- 卸载:`/usr/share/elasticsearch/bin/elasticsearch-plugin remove 插件名称`
- IK 分词插件的安装(**重点:所有节点都需要安装此插件**)
- IK 分词官网:
- 官网首页已经有一个表格说明 ES 版本和 IK 插件的版本对应,我们可以看到:ES 2.4.1 对应 IK 分词 1.10.1,下载地址:
- 进入 ES 插件目录:`cd /usr/program/elk/elasticsearch-2.4.1/plugins`
- 创建 ik 目录:`mkdir ik`
- 把下载的 elasticsearch-analysis-ik-1.10.1.zip 上传到刚新建的 ik 目录下
- 解压:`unzip elasticsearch-analysis-ik-1.10.1.zip`
- 删除压缩包:`rm -rf elasticsearch-analysis-ik-1.10.1.zip`
- 编辑 ES 配置文件:`vim /usr/program/elk/elasticsearch-2.4.1/config/elasticsearch.yml`
- 在文件底部添加如下内容:
``` ini
index.analysis.analyzer.default.tokenizer : "ik_max_word"
index.analysis.analyzer.default.type: "ik"
```
- 重启 ES : /usr/program/elk/elasticsearch-2.4.1/bin/elasticsearch
- 验证 ik 插件,浏览器访问:,能得到如下结果就表示成功:
``` json
[
{
"token": "这是",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "一个",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 1
},
{
"token": "一",
"start_offset": 2,
"end_offset": 3,
"type": "TYPE_CNUM",
"position": 2
},
{
"token": "个",
"start_offset": 3,
"end_offset": 4,
"type": "COUNT",
"position": 3
},
{
"token": "针对",
"start_offset": 4,
"end_offset": 6,
"type": "CN_WORD",
"position": 4
},
{
"token": "程序员",
"start_offset": 6,
"end_offset": 9,
"type": "CN_WORD",
"position": 5
},
{
"token": "程序",
"start_offset": 6,
"end_offset": 8,
"type": "CN_WORD",
"position": 6
},
{
"token": "序",
"start_offset": 7,
"end_offset": 8,
"type": "CN_WORD",
"position": 7
},
{
"token": "员",
"start_offset": 8,
"end_offset": 9,
"type": "CN_CHAR",
"position": 8
},
{
"token": "优化",
"start_offset": 9,
"end_offset": 11,
"type": "CN_WORD",
"position": 9
},
{
"token": "导航",
"start_offset": 12,
"end_offset": 14,
"type": "CN_WORD",
"position": 10
},
{
"token": "航",
"start_offset": 13,
"end_offset": 14,
"type": "CN_WORD",
"position": 11
},
{
"token": "gitnavi.com",
"start_offset": 14,
"end_offset": 25,
"type": "LETTER",
"position": 12
},
{
"token": "gitnavi",
"start_offset": 14,
"end_offset": 21,
"type": "ENGLISH",
"position": 13
},
{
"token": "com",
"start_offset": 22,
"end_offset": 25,
"type": "ENGLISH",
"position": 14
}
]
```
- Elasticsearch 5.x 版本之后,就不需要再修改这个配置文件了 `/usr/program/elk/elasticsearch-2.4.1/config/elasticsearch.yml`,直接解压 zip 后,直接可以启动使用。可以访问这个进行测试:
- 其他一些配置文件:
- main.dic,内置中文词库文件是,差不多有 27W 条记录。
- stopword.dic,英文停用词,一般不会被分词,不会存放在倒排索引中。
- quantifier.dic,用来存放一些量词。
- suffix.dic,用来存放后缀词。
- surname.dic,姓氏。
- 自定义分词词库:
- 修改配置文件:IKAnalyzer.cfg.xml
- 在 ext_dict 标签中指定我们自己新增的 dic 文件(给的 demo 路径是 custom 目录下)。
- 修改完重启下 Elasticsearch 集群
- 自定义停用词库:
- 修改配置文件:IKAnalyzer.cfg.xml
- 在 ext_stopwords 标签中指定我们自己新增的 dic 文件(给的 demo 路径是 custom 目录下)。
- 修改完重启下 Elasticsearch 集群
### 构建 elasticsearch 集群
- 另外一台机子也同样这样安装,但是有几个地方有差别:
- 特别注意:集群的关键点是配置文件中的:cluster.name,这个一样就表示在一个集群中
- 配置文件:`/usr/program/elk/elasticsearch-2.4.1/config/elasticsearch.yml`
- node 名称改为不一样的,比如我这边改为 2:node.name: gitnavi-node-2
- 插件不用安装,有一台机子安装即可
- 先启动装有 head 的机子,然后再启动另外一台,这样好辨别
## 资料
- <>
- <>
================================================
FILE: markdown-file/FTP.md
================================================
# FTP(File Transfer Protocol)介绍
## FTP 安装
- 查看是否已安装:
- CentOS:`rpm -qa | grep vsftpd`
- Ubuntu:`dpkg -l | grep vsftpd`
- 安装:
- CentOS 6:`sudo yum install -y vsftpd`
- Ubuntu:`sudo apt-get install -y vsftpd`
## FTP 使用之前要点
- 关闭 CentOS 上的 SELinux 组件(Ubuntu 体系是没有这东西的)。
- 查看 SELinux 开启状态:`sudo getenforce`
- 有如下三种状态,默认是 Enforcing
- Enforcing(开启)
- Permissive(开启,但是只起到警告作用,属于比较轻的开启)
- Disabled(关闭)
- 临时关闭:
- 命令:`sudo setenforce 0`
- 临时开启:
- 命令:`sudo setenforce 1`
- 永久关闭:
- 命令:`sudo vim /etc/selinux/config`
- 将:`SELINUX=enforcing` 改为 `SELINUX=disbaled`,配置好之后需要重启系统。
## FTP 服务器配置文件常用参数
- vsftpd 默认是支持使用 Linux 系统里的账号进行登录的(登录上去可以看到自己的 home 目录内容),权限跟 Linux 的账号权限一样。但是建议使用软件提供的虚拟账号管理体系功能,用虚拟账号登录。
- 配置文件介绍(记得先备份):`sudo vim /etc/vsftpd/vsftpd.conf`,比较旧的系统版本是:`vim /etc/vsftpd.conf`
- 该配置主要参数解释:
- anonymous_enable=NO #不允许匿名访问,改为YES即表示可以匿名登录
- anon_upload_enable=YES #是否允许匿名用户上传
- anon_mkdir_write_enable=YES #是否允许匿名用户创建目录
- local_enable=YES #是否允许本地用户,也就是linux系统的已有账号,如果你要FTP的虚拟账号,那可以改为NO
- write_enable=YES #是否允许本地用户具有写权限
- local_umask=022 #本地用户掩码
- chroot_list_enable=YES #不锁定用户在自己的家目录,默认是注释,建议这个一定要开,比如本地用户judasn,我们只能看到/home/judasn,没办法看到/home目录
- chroot_list_file=/etc/vsftpd/chroot_list #该选项是配合上面选项使用的。此文件中的用户将启用 chroot,如果上面的功能开启是不够的还要把用户名加到这个文件里面。配置好后,登录的用户,默认登录上去看到的根目录就是自己的home目录。
- listen=YES #独立模式
- userlist_enable=YES #用户访问控制,如果是YES,则表示启用vsftp的虚拟账号功能,虚拟账号配置文件是/etc/vsftpd/user_list
- userlist_deny=NO #这个属性在配置文件是没有的,当userlist_enable=YES,这个值也为YES,则user_list文件中的用户不能登录FTP,列表外的用户可以登录,也可以起到一个黑名单的作用。当userlist_enable=YES,这个值为NO,则user_list文件中的用户能登录FTP,列表外的用户不可以登录,也可以起到一个白名单的作用。如果同一个用户即在白名单中又在ftpusers黑名单文件中,那还是会以黑名单为前提,对应账号没法登录。
- tcp_wrappers=YES #是否启用TCPWrappers管理服务
- FTP用户黑名单配置文件:`sudo vim /etc/vsftpd/ftpusers`,默认root用户也在黑名单中
- 控制FTP用户登录配置文件:`sudo vim /etc/vsftpd/user_list`
- 启动服务:
- `service vsftpd restart`
## vsftpd 的两种传输模式
- 分为:主动模式(PORT)和被动模式(PASV)。这两个模式会涉及到一些端口问题,也就涉及到防火墙问题,所以要特别注意。主动模式比较简单,只要在防火墙上放开放开 21 和 20 端口即可。被动模式则要根据情况放开一个端口段。
- 
- 上图箭头:xftp 新建连接默认都是勾选被动模式的,所以如果要使用主动模式,在该连接的属性中是要去掉勾选。
## vsftpd 的两种运行模式
- 分为:xinetd 模式和 standalone 模式
- xinetd 模式:由 xinetd 作为 FTP 的守护进程,负责 21 端口的监听,一旦外部发起对 21 端口的连接,则调用 FTP 的主程序处理,连接完成后,则关闭 FTP 主程序,释放内存资源。好处是资源占用少,适合 FTP 连接数较少的场合。
- standalone 模式:直接使用 FTP 主程序作为 FTP 的守护进程,负责 21 端口的监听,由于无需经过 xinetd 的前端代理,响应速度快,适合连接数 较大的情况,但由于 FTP 主程序长期驻留内存,故较耗资源。
- standalone 一次性启动,运行期间一直驻留在内存中,优点是对接入信号反应快,缺点是损耗了一定的系统资源,因此经常应用于对实时反应要求较高的 专业 FTP 服务器。
- xinetd 恰恰相反,由于只在外部连接发送请求时才调用 FTP 进程,因此不适合应用在同时连接数量较多的系统。此外,xinetd 模式不占用系统资源。除了反应速度和占用资源两方面的影响外,vsftpd 还提供了一些额外的高级功能,如 xinetd 模式支持 per_IP (单一 IP)限制,而 standalone 模式则更有利于 PAM 验证功能的应用。
- 配置 xinetd 模式:
- 编辑配置文件:`sudo vim /etc/xinetd.d/vsftpd`
- 属性信息改为如下信息:
- disable = no
- socket_type = stream
- wait = no #这表示设备是激活的,它正在使用标准的TCP Sockets
- 编辑配置文件:`sudo vim /etc/vsftpd/vsftpd.conf`
- 如果该配置选项中的有 `listen=YES`,则要注释掉
- 重启 xinetd 服务,命令:`sudo /etc/rc.d/init.d/xinetd restart`
- 配置 standalone 模式:
- 编辑配置文件:`sudo vim /etc/xinetd.d/vsftpd`
- 属性信息改为如下信息:
- disable = yes
- 编辑配置文件:`sudo vim /etc/vsftpd/vsftpd.conf`
- 属性信息改为如下信息:
- Listen=YES(如果是注释掉则要打开注释)
- 重启服务:`sudo service vsftpd restart`
## FTP 资料
-
-
-
-
-
================================================
FILE: markdown-file/FastDFS-Install-And-Settings.md
================================================
# FastDFS 安装和配置
## FastDFS 介绍
- FastDFS 介绍:
- 官网下载 1:
- 官网下载 2:
- 官网下载 3:
- 主要场景:
- 小图片
- 音频、小视频
- 其他类型小文件
- 更加复杂的文件存储场景可以选择:[Ceph](https://ceph.com/)
- 支持对象存储、块存储和文件存储
- 高性能、高可靠性和高扩展
### 单机安装部署(CentOS 6.7 环境)
- 环境准备:
- 已经安装好 Nginx
- 软件准备:
- **FastDFS_v5.05.tar.gz**
- **fastdfs-nginx-module_v1.16.tar.gz**
- **libfastcommon-1.0.7.tar.gz**
- 安装依赖包:`yum install -y libevent`
- 安装 **libfastcommon-1.0.7.tar.gz**
- 解压:`tar zxvf libfastcommon-1.0.7.tar.gz`
- 进入解压后目录:`cd libfastcommon-1.0.7/`
- 编译:`./make.sh`
- 安装:`./make.sh install`
- 设置几个软链接:`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`
- 安装 tracker (跟踪器)服务 **FastDFS_v5.08.tar.gz**
- 解压:`tar zxvf FastDFS_v5.05.tar.gz`
- 进入解压后目录:`cd FastDFS/`
- 编译:`./make.sh`
- 安装:`./make.sh install`
- 安装结果:
``` ini
/usr/bin 存放有编译出来的文件
/etc/fdfs 存放有配置文件
```
- 配置 tracker 服务
- 复制一份配置文件:`cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf`
- 编辑:`vim /etc/fdfs/tracker.conf`,编辑内容看下面中文注释
``` ini
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/tracker/data-and-log
base_path=/opt/fastdfs/tracker/data-and-log
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
```
- 启动 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf`
- 重启 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart`
- 查看是否有 tracker 进程:`ps aux | grep tracker`
- storage (存储节点)服务部署
- 一般 storage 服务我们会单独装一台机子,但是这里为了方便我们安装在同一台。
- 如果 storage 单独安装的话,那上面安装的步骤都要在走一遍,只是到了编辑配置文件的时候,编辑的是 storage.conf 而已
- 复制一份配置文件:`cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf`
- 编辑:`vim /etc/fdfs/storage.conf`,编辑内容看下面中文注释
``` ini
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/storage/data-and-log
base_path=/opt/fastdfs/storage/data-and-log
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
# 图片实际存放路径,如果有多个,这里可以有多行:
# store_path0=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
# 创建目录:mkdir -p /opt/fastdfs/storage/images-data
store_path0=/opt/fastdfs/storage/images-data
subdir_count_per_path=256
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888
```
- 启动 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf`,首次启动会很慢,因为它在创建预设存储文件的目录
- 重启 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart`
- 查看是否有 storage 进程:`ps aux | grep storage`
- 测试是否部署成功
- 利用自带的 client 进行测试
- 复制一份配置文件:`cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf`
- 编辑:`vim /etc/fdfs/client.conf`,编辑内容看下面中文注释
``` ini
connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/client/data-and-log
base_path=/opt/fastdfs/client/data-and-log
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80
```
- 在终端中通过 shell 上传 opt 目录下的一张图片:`/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg`
- 如下图箭头所示,生成的图片地址为:`http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg`
- 
- 即使我们现在知道图片的访问地址我们也访问不了,因为我们还没装 FastDFS 的 Nginx 模块
- 安装 **fastdfs-nginx-module_v1.16.tar.gz**,安装 Nginx 第三方模块相当于这个 Nginx 都是要重新安装一遍的
- 解压 Nginx 模块:`tar zxvf fastdfs-nginx-module_v1.16.tar.gz`,得到目录地址:**/opt/setups/FastDFS/fastdfs-nginx-module**
- 编辑 Nginx 模块的配置文件:`vim /opt/setups/FastDFS/fastdfs-nginx-module/src/config`
- 找到下面一行包含有 `local` 字眼去掉,因为这三个路径根本不是在 local 目录下的。
``` nginx
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
```
- 改为如下:
``` nginx
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
```
- 复制文件:`cp /opt/setups/FastDFS/FastDFS/conf/http.conf /etc/fdfs`
- 复制文件:`cp /opt/setups/FastDFS/FastDFS/conf/mime.types /etc/fdfs`
- 安装 Nginx 和 Nginx 第三方模块
- 安装 Nginx 依赖包:`yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel`
- 预设几个文件夹,方便等下安装的时候有些文件可以进行存放:
- `mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx`
- 解压 Nginx:`tar zxvf /opt/setups/nginx-1.8.1.tar.gz`
- 进入解压后目录:`cd /opt/setups/nginx-1.8.1/`
- 编译配置:(注意最后一行)
``` ini
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/opt/setups/FastDFS/fastdfs-nginx-module/src
```
- 编译:`make`
- 安装:`make install`
- 复制 Nginx 模块的配置文件:`cp /opt/setups/FastDFS/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs`
- 编辑 Nginx 模块的配置文件:`vim /etc/fdfs/mod_fastdfs.conf`,编辑内容看下面中文注释
- 如果在已经启动 Nginx 的情况下修改下面内容记得要重启 Nginx。
``` ini
connect_timeout=2
network_timeout=30
# 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-log
base_path=/opt/fastdfs/fastdfs-nginx-module/data-and-log
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
storage_server_port=23000
group_name=group1
# 因为我们访问图片的地址是:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg
# 该地址前面是带有 /group1/M00,所以我们这里要使用 true,不然访问不到(原值是 false)
url_have_group_name = true
store_path_count=1
# 图片实际存放路径,如果有多个,这里可以有多行:
# store_path0=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
store_path0=/opt/fastdfs/storage/images-data
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
```
- 编辑 Nginx 配置文件
``` nginx
# 注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
# 访问本机
server_name 192.168.1.114;
# 拦截包含 /group1/M00 请求,使用 fastdfs 这个 Nginx 模块进行转发
location /group1/M00 {
ngx_fastdfs_module;
}
}
}
```
- 启动 Nginx
- 停掉防火墙:`service iptables stop`
- 启动:`/usr/local/nginx/sbin/nginx`,启动完成 shell 是不会有输出的
- 访问:`192.168.1.114`,如果能看到:`Welcome to nginx!`,即可表示安装成功
- 检查 时候有 Nginx 进程:`ps aux | grep nginx`,正常是显示 3 个结果出来
- 刷新 Nginx 配置后重启:`/usr/local/nginx/sbin/nginx -s reload`
- 停止 Nginx:`/usr/local/nginx/sbin/nginx -s stop`
- 如果访问不了,或是出现其他信息看下错误立即:`vim /var/log/nginx/error.log`
### 多机安装部署(CentOS 6.7 环境)
http://blog.csdn.net/ricciozhang/article/details/49402273
## 资料
- [fastdfs+nginx安装配置](http://blog.csdn.net/ricciozhang/article/details/49402273)
================================================
FILE: markdown-file/FastDFS-Nginx-Lua-GraphicsMagick.md
================================================
# FastDFS 结合 GraphicsMagick
## 单机安装部署(CentOS 6.7 环境)
### 先安装 FastDFS
- 软件准备:
- 我这边统一提供了一个压缩包,方便使用。
- 下载地址:
- 安装依赖包:`yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel libevent`
- 安装 **libfastcommon-1.0.7.tar.gz**
- 解压:`tar zxvf libfastcommon-1.0.7.tar.gz`
- 进入解压后目录:`cd libfastcommon-1.0.7/`
- 编译:`./make.sh`
- 安装:`./make.sh install`
- 设置几个软链接:`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`
- 安装 tracker (跟踪器)服务 **FastDFS_v5.08.tar.gz**
- 解压:`tar zxvf FastDFS_v5.05.tar.gz`
- 进入解压后目录:`cd FastDFS/`
- 编译:`./make.sh`
- 安装:`./make.sh install`
- 配置 tracker 服务
- 复制一份配置文件:`cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf`
- 编辑:`vim /etc/fdfs/tracker.conf`,编辑内容看下面中文注释
``` ini
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/tracker/data-and-log
base_path=/opt/fastdfs/tracker/data-and-log
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html
```
- 启动 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf`
- 重启 tracker 服务:`/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart`
- 查看是否有 tracker 进程:`ps aux | grep tracker`
- storage (存储节点)服务部署
- 一般 storage 服务我们会单独装一台机子,但是这里为了方便我们安装在同一台。
- 如果 storage 单独安装的话,那上面安装的步骤都要在走一遍,只是到了编辑配置文件的时候,编辑的是 storage.conf 而已
- 复制一份配置文件:`cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf`
- 编辑:`vim /etc/fdfs/storage.conf`,编辑内容看下面中文注释
``` ini
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
# 下面这个路径是保存 store data 和 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/storage/data-and-log
base_path=/opt/fastdfs/storage/data-and-log
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
# 图片实际存放路径,如果有多个,这里可以有多行:
# store_path0=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
# 创建目录:mkdir -p /opt/fastdfs/storage/images-data
store_path0=/opt/fastdfs/storage/images-data
subdir_count_per_path=256
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888
```
- 启动 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf`,首次启动会很慢,因为它在创建预设存储文件的目录
- 重启 storage 服务:`/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart`
- 查看是否有 storage 进程:`ps aux | grep storage`
- 测试是否部署成功
- 利用自带的 client 进行测试
- 复制一份配置文件:`cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf`
- 编辑:`vim /etc/fdfs/client.conf`,编辑内容看下面中文注释
``` ini
connect_timeout=30
network_timeout=60
# 下面这个路径是保存 store log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/client/data-and-log
base_path=/opt/fastdfs/client/data-and-log
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80
```
- 在终端中通过 shell 上传 opt 目录下的一张图片:`/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/test.jpg`
- 如下图箭头所示,生成的图片地址为:`http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg`
- 
- 即使我们现在知道图片的访问地址我们也访问不了,因为我们还没装 FastDFS 的 Nginx 模块
### 安装 nginx-lua-GraphicsMagick
- 来源:
- 添加专用用户,后面有用
- `groupadd www`
- `useradd -g www www -s /bin/false`
- 安装依赖包
- `yum install -y gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel`
- `yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel`
- `yum install -y GraphicsMagick GraphicsMagick-devel`
- 下面的这些软件都在本文在开头的那个压缩包里面。现在我们需要解压这些压缩包
- `cd /opt/setups`
- `tar -zxvf nginx-1.8.0.tar.gz`
- `tar -zxvf LuaJIT-2.0.4.tar.gz`
- `tar -zxvf GraphicsMagick-1.3.21.tar.gz`
- `tar -zxvf zlib-1.2.8.tar.gz`
- 安装 LuaJIT
- `cd /opt/setups/LuaJIT-2.0.4`
- `make`
- `make install`
- `export LUAJIT_LIB=/usr/local/lib`
- `export LUAJIT_INC=/usr/local/include/luajit-2.0`
- `ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2`
- 修改一些配置文件
- 编辑 Nginx 模块的配置文件:`vim /opt/setups/fastdfs-nginx-module/src/config`
- 找到下面一行包含有 `local` 字眼去掉,因为这三个路径根本不是在 local 目录下的。(如果你的配置文件没有这个 local,那这一步跳过)
``` nginx
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
```
- 改为如下:
``` nginx
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
```
- 复制文件:`cp /opt/setups/FastDFS/conf/http.conf /etc/fdfs`
- 复制文件:`cp /opt/setups/FastDFS/conf/mime.types /etc/fdfs`
- 开始安装 Nginx
- `cd /opt/setups/nginx-1.8.0`
- `mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx`
- 执行下面编译语句:
``` nginx
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--sbin-path=/usr/local/nginx/sbin/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_spdy_module \
--with-pcre \
--with-zlib=/opt/setups/zlib-1.2.8 \
--add-module=/opt/setups/nginx-http-concat \
--add-module=/opt/setups/lua-nginx-module \
--add-module=/opt/setups/ngx_devel_kit \
--add-module=/opt/setups/fastdfs-nginx-module/src
```
- `make`
- `make install`
- 修改一下配置
- 复制 Nginx 模块的配置文件:`cp /opt/setups/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs`
- 编辑 Nginx 模块的配置文件:`vim /etc/fdfs/mod_fastdfs.conf`,编辑内容看下面中文注释
- 如果在已经启动 Nginx 的情况下修改下面内容记得要重启 Nginx。
``` ini
connect_timeout=2
network_timeout=30
# 下面这个路径是保存 log 的地方,需要我们改下,指向我们一个存在的目录
# 创建目录:mkdir -p /opt/fastdfs/fastdfs-nginx-module/data-and-log
base_path=/opt/fastdfs/fastdfs-nginx-module/data-and-log
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
# 指定 tracker 服务器的 IP 和端口
tracker_server=192.168.1.114:22122
storage_server_port=23000
group_name=group1
# 因为我们访问图片的地址是:http://192.168.1.114/group1/M00/00/00/wKgBclb0aqWAbVNrAAAjn7_h9gM813_big.jpg
# 该地址前面是带有 /group1/M00,所以我们这里要使用 true,不然访问不到(原值是 false)
url_have_group_name = true
store_path_count=1
# 图片实际存放路径,如果有多个,这里可以有多行:
# store_path0=/opt/fastdfs/storage/images-data0
# store_path1=/opt/fastdfs/storage/images-data1
# store_path2=/opt/fastdfs/storage/images-data2
store_path0=/opt/fastdfs/storage/images-data
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
```
- 创建文件夹:`mkdir -p /opt/fastdfs/thumb`
- 编辑 Nginx 配置文件
- `vim /usr/local/nginx/conf/nginx.conf`
``` nginx
# 注意这一行行,我特别加上了使用 root 用户去执行,不然有些日记目录没有权限访问
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server{
listen 80;
server_name 192.168.1.112;
set $img_thumbnail_root /opt/fastdfs/thumb;
set $img_file $img_thumbnail_root$uri;
# like:/pic/M00/xx/xx/xx.jpg_200x100.jpg
# /group1/M00
location ~* ^(\/(\w+)(\/M00)(.+\.(jpg|jpeg|gif|png))_(\d+)+x(\d+)+\.(jpg|jpeg|gif|png))$ {
root $img_thumbnail_root;
set $fdfs_group_root /opt/fastdfs/storage/images-data/data;
# 如果缩略图不存在
if (!-f $img_file) {
add_header X-Powered-By 'Nginx+Lua+GraphicsMagick By Yanue';
add_header file-path $request_filename;
set $request_filepath $fdfs_group_root$4;
set $img_width $6;
set $img_height $7;
set $img_ext $5;
content_by_lua_file /opt/setups/lua/cropSize.lua;
}
}
location /group1/M00 {
alias /opt/fastdfs/storage/images-data/data;
ngx_fastdfs_module;
}
}
}
```
- 启动 Nginx
- 停掉防火墙:`service iptables stop`
- 启动:`/usr/local/nginx/sbin/nginx`,启动完成 shell 是不会有输出的
- 访问:`192.168.1.114`,如果能看到:`Welcome to nginx!`,即可表示安装成功
- 检查 时候有 Nginx 进程:`ps aux | grep nginx`,正常是显示 3 个结果出来
- 刷新 Nginx 配置后重启:`/usr/local/nginx/sbin/nginx -s reload`
- 停止 Nginx:`/usr/local/nginx/sbin/nginx -s stop`
- 如果访问不了,或是出现其他信息看下错误立即:`vim /var/log/nginx/error.log`
### 多机安装部署(CentOS 6.7 环境)
- 多机部署的情况,对生成大小图的 Nginx 也有地方要修改。
- 资料:
## 资料
- [fastdfs+nginx安装配置](http://blog.csdn.net/ricciozhang/article/details/49402273)
================================================
FILE: markdown-file/File-Extract-Compress.md
================================================
# Linux 下常用压缩文件的解压、压缩
## 常用压缩包--解压--令整理
- Linux 后缀为 `.war` 格式的文件(一般用在部署 Tomcat 项目的时候)
- 命令:`unzip -oq XXXXXX.war -d ROOT`
- 如果没有 ROOT 目录会自动创建 ROOT 目录。
- Linux 后缀为 `.tar.gz` 格式的文件-解压
- 命令:`tar zxvf XXXXXX.tar.gz`
- Linux 后缀为 `.bz2` 格式的文件-解压
- 命令:`bzip2 -d XXXXXX.bz2`
- Linux 后缀为 `.tar.bz2` 格式的文件-解压
- 命令:`tar jxvf XXXXXX.tar.bz2`
- Linux 后缀为 `.tar` 格式的文件-解压
- 命令:`tar zxvf XXXXXX.tar`
- Linux 后缀为 `.gz` 格式的文件-解压
- 命令:`gunzip XXXXXX.gz`
- Linux 后缀为 `.zip` 格式的文件-解压
- 命令:`unzip XXXXXX.zip`
- 命令:`unzip XXXXXX.zip -d /opt/`,解压到指定目录
- Linux 后缀为 `.7z` 格式的文件-解压
- 命令:`7za x XXXXXX.7z`
- Linux 后缀为 `.tar.xz` 格式的文件-解压,解压出来是tar,再对tar进行解压
- 命令:`tar xf XXXXXX.tar.xz`
-----------------------------------------------------------
## 常用文件进行--压缩--命令整理
- Linux 压缩文件夹为后缀 `.war` 格式的文件(最好不要对根目录进行压缩,不然会多出一级目录)
- 命令:`jar -cvfM0 cas.war /opt/cas/META-INF /opt/cas/WEB-INF /opt/cas/index.jsp`
- 或者命令:`cd 项目根目录 ; jar -cvfM0 cas.war ./*`
- Linux 压缩文件为后缀 `.tar` 格式的文件
- 命令:`tar -zcvf test11.tar test11`
- Linux 压缩文件为后缀 `.tar.gz` 格式的文件
- 命令:`tar -zcvf test11.tar.gz test11`
- Linux 压缩文件为后缀 `.bz2` 格式的文件
- 命令:`bzip2 -v test.txt`
- Linux 压缩文件为后缀 `.tar.bz2` 格式的文件
- 命令:`tar -jcvf test11.tar.gz test11`
- Linux 压缩文件为后缀 `.zip` 格式的文件
- 命令:`zip -r test1.zip /opt/test1/`
- Linux 压缩文件为后缀 `.7z` 格式的文件
- 命令:`7za a test1.7z /opt/test1/`
## 分卷压缩
- 分卷压缩:`zip -s 100M myFile.zip --out newFile.zip`
- 最终效果:
```
newFile.z01
newFile.z02
newFile.z03
newFile.z04
newFile.zip
```
## 特殊格式
- 7z
- 7z 的安装:
- 访问官网下载解压包:
- 解压压缩包:`tar jxvf p7zip_15.14_src_all.tar.bz2`
- 进入目录:`cd p7zip_15.14`
- 执行安装:`sh install.sh`
- rar
- rar 的安装:
- 下载:`wget http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz`
- 解压下载下来的压缩包:`tar zxvf rarlinux-3.8.0.tar.gz`
- 进入解压后目录:`cd rar`
- 编译:`make`
- 安装:`make install`
- rar 解压:`rar x 文件名.rar`
## jar 包操作
### 修改 jar 包配置文件
- 命令:`vim mytest.jar`,这时候会展示 jar 中所有层级目录下的所有文件
- 输入:`/log4j2.xml` 回车,光标定位到该文件,然后再回车,进入编辑该文件状态
- 此时可以修改配置文件了,修改后 `:wq` 保存退出,接着 `:q` 退出 jar 编辑状态
### 更新 Jar 包中的文件
- 替换(新增)jar 根目录下的文件:`jar uvf mytest.jar ClassToAdd.class`
- 一般 class 文件都是在多层目录里面的,需要这样做:`jar uvf mytest.jar com/youmeek/ClassToAdd.class`
- 需要在 jar 所在的文件夹下创建:`mkdir -p ./com/youmeek`,该目录必须和原 jar 里面的层级目录结构一致
## 资料
-
================================================
FILE: markdown-file/Flink-Install-And-Settings.md
================================================
# Flink 安装和配置
## 介绍
- 2018-11-30 发布最新:1.7.0 版本
- 官网:
- 官网 Github:
## 本地模式安装
- CentOS 7.4
- IP 地址:`192.168.0.105`
- 官网指导:
- 必须 JDK 8.x
- 下载:
- 选择 Binaries 类型
- 如果没有 Hadoop 环境,只是本地开发,选择:Apache 1.7.0 Flink only
- Scala 2.11 和 Scala 2.12 都可以,但是我因为后面要用到 kafka,kafka 推荐 Scala 2.11,所以我这里也选择同样。
- 最终我选择了:Apache 1.7.0 Flink only Scala 2.11,共:240M
- 解压:`tar zxf flink-*.tgz`
- 进入根目录:`cd flink-1.7.0`,完整路径:`cd /usr/local/flink-1.7.0`
- 改下目录名方便后面书写:`mv /usr/local/flink-1.7.0 /usr/local/flink`
- 启动:`cd /usr/local/flink && ./bin/start-cluster.sh`
- 停止:`cd /usr/local/flink && ./bin/stop-cluster.sh`
- 查看日志:`tail -300f log/flink-*-standalonesession-*.log`
- 浏览器访问 WEB 管理:`http://192.168.0.105:8081`
## yarn 启动
- 安装方式跟上面一样,但是必须保证有 hadoop、yarn 集群
- 控制台启动:`cd /usr/local/flink && ./bin/yarn-session.sh -n 2 -jm 1024 -tm 1024`
- 守护进程启动:`cd /usr/local/flink && ./bin/yarn-session.sh -n 2 -jm 1024 -tm 1024 -d`
- 有可能会报:`The Flink Yarn cluster has failed`,可能是资源不够
- YARN 参数配置可以参考:[点击我](https://sustcoder.github.io/2018/09/27/YARN%20%E5%86%85%E5%AD%98%E5%8F%82%E6%95%B0%E8%AF%A6%E8%A7%A3/)
## Demo
- 运行程序解压包下也有一些 jar demo:`cd /usr/local/flink/examples`
- 官网:
- DataStream API:
- DataSet API:
- 访问该脚本可以得到如下内容:
```
mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-java \
-DarchetypeVersion=${1:-1.7.0} \
-DgroupId=org.myorg.quickstart \
-DartifactId=$PACKAGE \
-Dversion=0.1 \
-Dpackage=org.myorg.quickstart \
-DinteractiveMode=false
```
- 可以自己在本地执行该 mvn 命令,用 Maven 骨架快速创建一个 WordCount 项目
- 注意,这里必须使用这个仓库(最好用穿越软件):`https://repository.apache.org/content/repositories/snapshots`
- 该骨架的所有版本:
- 根据实验,目前 1.7.0 和 1.6.x 都是没有 WordCount demo 代码的。但是 1.3.x 是有的。
## 运行
- 可以直接在 IntelliJ IDEA 上 run
- 也可以交给服务器上 flink 执行,也有两种方式:
- 把 jar 自己上传 Flink 服务器运行:`cd /usr/local/flink && ./bin/flink run -c com.youmeek.WordCount /opt/flink-simple-demo-1.0-SNAPSHOT.jar`
- 也可以通过 WEB UI 上传 jar:
- 有一个 `Add New` 按钮可以上传 jar 包,然后填写 Class 路径:`com.youmeek.WordCount`
- `parallelism` 表示并行度,填写数字,一般并行度设置为集群 CPU 核数总和的 2-3 倍(如果是单机模式不需要设置并行度)
## 安装 ncat 方便发送数据包
- 环境:CentOS 7.4
- 官网下载:,找到 rpm 包
- 当前时间(201803)最新版本下载:`wget https://nmap.org/dist/ncat-7.60-1.x86_64.rpm`
- 当前时间(201812)最新版本下载:`wget https://nmap.org/dist/ncat-7.70-1.x86_64.rpm`
- 安装:`sudo rpm -i ncat-7.60-1.x86_64.rpm`
- ln 下:`sudo ln -s /usr/bin/ncat /usr/bin/nc`
- 检验:`nc --version`
- 启动监听 9011 端口:`nc -lk 9011`,然后你可以输入内容,Flink demo 看是否有收到
-------------------------------------------------------------------
## Flink 核心概念
- 四个基石:Checkpoint、State、Time、Window
- 解决 exactly-once 的问题
- 实现了 watermark 的机制,解决了基于事件时间处理时的数据乱序和数据迟到的问题
- 状态管理
- 提供了一套开箱即用的窗口操作,包括滚动窗口、滑动窗口、会话窗口
- 我想说的,都被这篇文章说了:
-
-
- 这里补充点其他的
```
Client 用来提交任务给 JobManager,JobManager 分发任务给 TaskManager 去执行,然后 TaskManager 会心跳的汇报任务状态
在 Flink 集群中,计算资源被定义为 Task Slot
每个 TaskManager 会拥有一个或多个 Slots
JobManager 会以 Slot 为单位调度 Task。
对 Flink 的 JobManager 来说,其调度的是一个 Pipeline 的 Task,而不是一个点。
在 Flink 中其也是一个被整体调度的 Pipeline Task。在 TaskManager 中,根据其所拥有的 Slot 个数,同时会拥有多个 Pipeline
Task Slot
在架构概览中我们介绍了 TaskManager 是一个 JVM 进程,并会以独立的线程来执行一个task或多个subtask。为了控制一个 TaskManager 能接受多少个 task,Flink 提出了 Task Slot 的概念。
Flink 中的计算资源通过 Task Slot 来定义。每个 task slot 代表了 TaskManager 的一个固定大小的资源子集。例如,一个拥有3个slot的 TaskManager,会将其管理的内存平均分成三分分给各个 slot。将资源 slot 化意味着来自不同job的task不会为了内存而竞争,而是每个task都拥有一定数量的内存储备。需要注意的是,这里不会涉及到CPU的隔离,slot目前仅仅用来隔离task的内存。
通过调整 task slot 的数量,用户可以定义task之间是如何相互隔离的。每个 TaskManager 有一个slot,也就意味着每个task运行在独立的 JVM 中。每个 TaskManager 有多个slot的话,也就是说多个task运行在同一个JVM中。而在同一个JVM进程中的task,可以共享TCP连接(基于多路复用)和心跳消息,可以减少数据的网络传输。也能共享一些数据结构,一定程度上减少了每个task的消耗。
每一个 TaskManager 会拥有一个或多个的 task slot,每个 slot 都能跑由多个连续 task 组成的一个 pipeline,比如 MapFunction 的第n个并行实例和 ReduceFunction 的第n个并行实例可以组成一个 pipeline。
source(Streaming 进来)
Transformations(Streaming 处理)
sink(Streaming 出去)
Flink程序与生俱来的就是并行和分布式的。Streams被分割成stream patition, Operators被被分割成operator subtasks。这些subtasks在不同的机器(容器)上的不同的线程中运行,彼此独立,互不干扰。 一个操作的operator subtask的数目,被称为parallelism(并行度)。一个stream的并行度,总是等于生成它的(operator)操作的并行度。一个Flink程序中,不同的operator可能具有不同的并行度。
```
-------------------------------------------------------------------
#### 为了容错的 Checkpoint 机制
- 这几篇文章写得很好:
- [Flink 增量式checkpoint 介绍](https://my.oschina.net/u/992559/blog/2873828)
- [A Deep Dive into Rescalable State in Apache Flink](https://flink.apache.org/features/2017/07/04/flink-rescalable-state.html)
- [Flink 小贴士 (5): Savepoint 和 Checkpoint 的 3 个不同点](http://wuchong.me/blog/2018/11/25/flink-tips-differences-between-savepoints-and-checkpoints/)
- [Flink 小贴士 (2):Flink 如何管理 Kafka 消费位点](http://wuchong.me/blog/2018/11/04/how-apache-flink-manages-kafka-consumer-offsets/)
- Checkpoint 允许 Flink 恢复流中的状态和位置,使应用程序具有与无故障执行相同的语义
- Checkpoint 是 Flink 用来从故障中恢复的机制,快照下了整个应用程序的状态,当然也包括输入源读取到的位点。如果发生故障,Flink 将通过从 Checkpoint 加载应用程序状态并从恢复的读取位点继续应用程序的处理,就像什么事情都没发生一样。
```
一个checkpoint是Flink的一致性快照,它包括:
程序当前的状态
输入流的位置
Flink通过一个可配置的时间,周期性的生成checkpoint,将它写入到存储中,例如S3或者HDFS。写入到存储的过程是异步的,意味着Flink程序在checkpoint运行的同时还可以处理数据。
在机器或者程序遇到错误重启的时候,Flink程序会使用最新的checkpoint进行恢复。Flink会恢复程序的状态,将输入流回滚到checkpoint保存的位置,然后重新开始运行。这意味着Flink可以像没有发生错误一样计算结果。
检查点(Checkpoint)是使 Apache Flink 能从故障恢复的一种内部机制。检查点是 Flink 应用状态的一个一致性副本,包括了输入的读取位点。在发生故障时,Flink 通过从检查点加载应用程序状态来恢复,并从恢复的读取位点继续处理,就好像什么事情都没发生一样。你可以把检查点想象成电脑游戏的存档一样。如果你在游戏中发生了什么事情,你可以随时读档重来一次。
检查点使得 Apache Flink 具有容错能力,并确保了即时发生故障也能保证流应用程序的语义。检查点是以固定的间隔来触发的,该间隔可以在应用中配置。
```
- 默认情况下 checkpoint 是不启用的,为了启用 checkpoint,需要在 StreamExecutionEnvironment 中调用 enableCheckpointing(n) 方法, 其中 n 是 checkpoint 的间隔毫秒数。
- 这里有一个核心:用到 Facebook 的 RocksDB 数据库(可嵌入式的支持持久化的 key-value 存储系统)
-------------------------------------------------------------------
#### Exactly-Once
- 因为有了 Checkpoint,才有了 Exactly-Once
- [Apache Flink 端到端(end-to-end)Exactly-Once特性概览 (翻译)](https://my.oschina.net/u/992559/blog/1819948)
- 常见有这几种语义:
```
at most once : 至多一次。可能导致消息丢失。
at least once : 至少一次。可能导致消息重复。
exactly once : 刚好一次。不丢失也不重复。
```
-------------------------------------------------------------------
#### Watermark
- [Flink 小贴士 (3): 轻松理解 Watermark](http://wuchong.me/blog/2018/11/18/flink-tips-watermarks-in-apache-flink-made-easy/)
- 了解事件时间的几个概念:event-time【消息产生的时间】, processing-time【消息处理时间】, ingestion-time【消息流入 flink 框架的时间】
- watermark 的作用,他们定义了何时不再等待更早的数据
- WaterMark 只在时间特性 EventTime 和 IngestionTime 起作用,并且 IngestionTime 的时间等同于消息的 ingestion 时间
-------------------------------------------------------------------
#### 窗口
-
- [Flink 原理与实现:Window 机制](http://wuchong.me/blog/2016/05/25/flink-internals-window-mechanism/)
- [Flink 原理与实现:Session Window](http://wuchong.me/blog/2016/06/06/flink-internals-session-window/)
##### 滚动窗口(Tumbling Windows)
- 滚动窗口有一个固定的大小,并且不会出现重叠
###### 滚动事件时间窗口
```
input
.keyBy()
.window(TumblingEventTimeWindows.of(Time.seconds(5)))
.();
```
- 每日偏移8小时的滚动事件时间窗口
```
input
.keyBy()
.window(TumblingEventTimeWindows.of(Time.days(1), Time.hours(-8)))
.();
```
###### 滚动处理时间窗口
```
input
.keyBy()
.window(TumblingProcessingTimeWindows.of(Time.seconds(5)))
.();
```
---------------------------------
##### 滑动窗口(Sliding Windows)
- 滑动窗口分配器将元素分配到固定长度的窗口中,与滚动窗口类似,窗口的大小由窗口大小参数来配置,另一个窗口滑动参数控制滑动窗口开始的频率。因此,滑动窗口如果滑动参数小于滚动参数的话,窗口是可以重叠的,在这种情况下元素会被分配到多个窗口中。
- 例如,你有10分钟的窗口和5分钟的滑动,那么每个窗口中5分钟的窗口里包含着上个10分钟产生的数据
###### 滑动事件时间窗口
```
input
.keyBy()
.window(SlidingEventTimeWindows.of(Time.seconds(10), Time.seconds(5)))
.();
```
###### 滑动处理时间窗口
```
input
.keyBy()
.window(SlidingProcessingTimeWindows.of(Time.seconds(10), Time.seconds(5)))
.();
```
- 偏移8小时的滑动处理时间窗口
```
input
.keyBy()
.window(SlidingProcessingTimeWindows.of(Time.hours(12), Time.hours(1), Time.hours(-8)))
.();
```
---------------------------------
##### 计数窗口(Count Window)
- 根据元素个数对数据流进行分组的
###### 翻滚计数窗口
- 当我们想要每 100 个用户购买行为事件统计购买总数,那么每当窗口中填满 100 个元素了,就会对窗口进行计算,这种窗口我们称之为翻滚计数窗口(Tumbling Count Window)
```
input
.keyBy()
.countWindow(100)
.();
```
---------------------------------
##### 会话窗口(Session Windows)
- session 窗口分配器通过 session 活动来对元素进行分组,session 窗口跟滚动窗口和滑动窗口相比,不会有重叠和固定的开始时间和结束时间的情况。相反,当它在一个固定的时间周期内不再收到元素,即非活动间隔产生,那个这个窗口就会关闭。一个 session 窗口通过一个 session 间隔来配置,这个 session 间隔定义了非活跃周期的长度。当这个非活跃周期产生,那么当前的 session 将关闭并且后续的元素将被分配到新的 session 窗口中去。
###### 事件时间会话窗口
```
input
.keyBy()
.window(EventTimeSessionWindows.withGap(Time.minutes(10)))
.();
```
###### 处理时间会话窗口
```
input
.keyBy()
.window(ProcessingTimeSessionWindows.withGap(Time.minutes(10)))
.();
```
---------------------------------
##### 全局窗口(Global Windows)
- 全局窗口分配器将所有具有相同 key 的元素分配到同一个全局窗口中,这个窗口模式仅适用于用户还需自定义触发器的情况。否则,由于全局窗口没有一个自然的结尾,无法执行元素的聚合,将不会有计算被执行。
```
input
.keyBy()
.window(GlobalWindows.create())
.();
```
-------------------------------------------------------------------
#### 生产环境准备
- [Flink 小贴士 (7): 4个步骤,让 Flink 应用达到生产状态](http://wuchong.me/blog/2018/12/03/flink-tips-4-steps-flink-application-production-ready/)
-------------------------------------------------------------------
#### 运行环境
- Flink 的部署
- Flink 有三种部署模式,分别是 Local、Standalone Cluster 和 Yarn Cluster。
- 对于 Local 模式来说,JobManager 和 TaskManager 会公用一个 JVM 来完成 Workload。
- 如果要验证一个简单的应用,Local 模式是最方便的。实际应用中大多使用 Standalone 或者 Yarn Cluster
-------------------------------------------------------------------
#### Flink 的 HA
-------------------------------------------------------------------
#### Monitoring REST API
https://ci.apache.org/projects/flink/flink-docs-stable/monitoring/rest_api.html#monitoring-rest-api
-------------------------------------------------------------------
#### 主要核心 API
- 官网 API 文档:
- DataStream API -- Stream Processing
- DataSet API -- Batch Processing
- Kafka source
- Kafka Connectors
- Elasticsearch sink
-------------------------------------------------------------------
#### Table & SQL API(关系型 API)
Table API:为Java&Scala SDK提供类似于LINQ(语言集成查询)模式的API(自0.9.0版本开始)
SQL API:支持标准SQL(自1.1.0版本开始)
关系型API作为一个统一的API层,既能够做到在Batch模式的表上进行可终止地查询并生成有限的结果集,同时也能做到在Streaming模式的表上持续地运行并生产结果流,并且在两种模式的表上的查询具有相同的语法跟语义。这其中最重要的概念是Table,Table与DataSet、DataStream紧密结合,DataSet和DataStream都可以很容易地转换成Table,同样转换回来也很方便。
关系型API架构在基础的DataStream、DataSet API之上,其整体层次关系如下图所示:

-------------------------------------------------------------------
## 资料
- [新一代大数据处理引擎 Apache Flink](https://www.ibm.com/developerworks/cn/opensource/os-cn-apache-flink/index.html)
- [Flink-关系型API简介](http://vinoyang.com/2017/07/06/flink-relation-api-introduction/)
- [Flink学习笔记(4):基本概念](https://www.jianshu.com/p/0cd1db4282be)
- [Apache Flink:特性、概念、组件栈、架构及原理分析](http://shiyanjun.cn/archives/1508.html)
- [Flink 原理与实现:理解 Flink 中的计算资源](http://wuchong.me/blog/2016/05/09/flink-internals-understanding-execution-resources/)
- [Flink实战教程](https://liguohua-bigdata.gitbooks.io/simple-flink/content/)
================================================
FILE: markdown-file/Gitlab-Install-And-Settings.md
================================================
# Gitlab 安装和配置
## Docker Compose 安装方式
- 创建宿主机挂载目录:`mkdir -p /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql`
- 赋权(避免挂载的时候,一些程序需要容器中的用户的特定权限使用):`chown -R 777 /data/docker/gitlab/gitlab /data/docker/gitlab/redis /data/docker/gitlab/postgresql`
- 这里使用 docker-compose 的启动方式,所以需要创建 docker-compose.yml 文件:
```yml
gitlab:
image: sameersbn/gitlab:10.4.2-1
ports:
- "10022:22"
- "10080:80"
links:
- gitlab-redis:redisio
- gitlab-postgresql:postgresql
environment:
- GITLAB_PORT=80
- GITLAB_SSH_PORT=22
- GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string
- GITLAB_SECRETS_SECRET_KEY_BASE=long-and-random-alpha-numeric-string
- GITLAB_SECRETS_OTP_KEY_BASE=long-and-random-alpha-numeric-string
volumes:
- /data/docker/gitlab/gitlab:/home/git/data
restart: always
gitlab-redis:
image: sameersbn/redis
volumes:
- /data/docker/gitlab/redis:/var/lib/redis
restart: always
gitlab-postgresql:
image: sameersbn/postgresql:9.6-2
environment:
- DB_NAME=gitlabhq_production
- DB_USER=gitlab
- DB_PASS=password
- DB_EXTENSION=pg_trgm
volumes:
- /data/docker/gitlab/postgresql:/var/lib/postgresql
restart: always
```
- 启动:`docker-compose up -d`
- 浏览器访问:
## Gitlab 高可用方案(High Availability)
- 官网:
- 本质就是把文件、缓存、数据库抽离出来,然后部署多个 Gitlab 用 nginx 前面做负载。
## 原始安装方式(推荐)
- 推荐至少内存 4G,它有大量组件
- 有开源版本和收费版本,各版本比较:
- 官网:
- 中文网:
- 官网下载:
- 官网安装说明:
- 如果上面的下载比较慢,也有国内的镜像:
- 清华:
- 参考:
```
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://192.168.1.123:8181" yum install -y gitlab-ce
```
## 配置
- 配置域名 / IP
- 编辑配置文件:`sudo vim /etc/gitlab/gitlab.rb`
- 找到 13 行左右:`external_url 'http://gitlab.example.com'`,改为你的域名 / IP
- 刷新配置:`sudo gitlab-ctl reconfigure`,第一次这个时间会比较久,我花了好几分钟
- 启动服务:`sudo gitlab-ctl start`
- 停止服务:`sudo gitlab-ctl stop`
- 重启服务:`sudo gitlab-ctl restart`
- 前面的初始化配置完成之后,访问当前机子 IP:`http://192.168.1.111:80`
- 默认用户是 `root`,并且没有密码,所以第一次访问是让你设置你的 root 密码,我设置为:gitlab123456(至少 8 位数)
- 设置会初始化密码之后,你就需要登录了。输入设置的密码。
- root 管理员登录之后常用的设置地址(请求地址都是 RESTful 风格很好懂,也应该不会再变了。):
- 用户管理:
- 用户组管理:
- 项目管理:
- 添加 SSH Keys:
- 给新创建的用户设置密码:
- 新创建的用户,他首次登录会要求他强制修改密码的,这个设定很棒!
- 普通用户登录之后常去的链接:
- 配置 SSH Keys:
## 配置 Jenkins 拉取代码权限
- Gitlab 创建一个 Access Token:
- 填写任意 Name 字符串
- 勾选:API `Access the authenticated user's API`
- 点击:Create personal access token,会生成一个类似格式的字符串:`wt93jQzA8yu5a6pfsk3s`,这个 Jenkinsfile 会用到
- 先访问 Jenkins 插件安装页面,安装下面三个插件:
- Gitlab:可能会直接安装不成功,如果不成功根据报错的详细信息可以看到 hpi 文件的下载地址,挂代理下载下来,然后离线安装即可
- Gitlab Hook:用于触发 GitLab 的一些 WebHooks 来构建项目
- Gitlab Authentication 这个插件提供了使用GitLab进行用户认证和授权的方案
- 安装完插件后,访问 Jenkins 这个路径(Jenkins-->Credentials-->System-->Global credentials(unrestricted)-->Add Credentials)
- 该路径链接地址:
- kind 下拉框选择:`GitLab API token`
- token 就填写我们刚刚生成的 access token
- ID 填写我们 Gitlab 账号
## 权限
- 官网帮助文档的权限说明:
### 用户组的权限
- 用户组有这几种权限的概念:`Guest、Reporter、Developer、Master、Owner`
- 这个概念在设置用户组的时候会遇到,叫做:`Add user(s) to the group`,比如链接:
|行为|Guest|Reporter|Developer|Master|Owner|
|---|---|--:|---|---|---|
|浏览组|✓|✓|✓|✓|✓|
|编辑组| | | | |✓|
|创建项目| | | |✓|✓|
|管理组成员| | | | |✓|
|移除组| | | | |✓|
### 项目组的权限
- 项目组也有这几种权限的概念:`Guest、Reporter、Developer、Master、Owner`
- `Guest`:访客
- `Reporter`:报告者; 可以理解为测试员、产品经理等,一般负责提交issue等
- `Developer`:开发者; 负责开发
- `Master`:主人; 一般是组长,负责对Master分支进行维护
- `Owner`:拥有者; 一般是项目经理
- 这个概念在项目设置的时候会遇到,叫做:`Members`,比如我有一个组下的项目链接:
|行为|Guest|Reporter|Developer|Master|Owner|
|---|---|--:|---|---|---|
|创建issue|✓|✓|✓|✓|✓|
|留言评论|✓|✓|✓|✓|✓|
|更新代码| |✓|✓|✓|✓|
|下载工程| |✓|✓|✓|✓|
|创建代码片段| |✓|✓|✓|✓|
|创建合并请求| | |✓|✓|✓|
|创建新分支| | |✓|✓|✓|
|提交代码到非保护分支| | |✓|✓|✓|
|强制提交到非保护分支| | |✓|✓|✓|
|移除非保护分支| | |✓|✓|✓|
|添加tag| | |✓|✓|✓|
|创建wiki| | |✓|✓|✓|
|管理issue处理者| | |✓|✓|✓|
|管理labels| | |✓|✓|✓|
|创建里程碑| | | |✓|✓|
|添加项目成员| | | |✓|✓|
|提交保护分支| | | |✓|✓|
|使能分支保护| | | |✓|✓|
|修改/移除tag| | | |✓|✓|
|编辑工程| | | |✓|✓|
|添加deploy keys| | | |✓|✓|
|配置hooks| | | |✓|✓|
|切换visibility level| | | | |✓|
|切换工程namespace| | | | |✓|
|移除工程| | | | |✓|
|强制提交保护分支| | | | |✓|
|移除保护分支| | | | |✓|
### 批量从一个项目中的成员转移到另外一个项目
- 项目的设置地址:
- 有一个 Import 按钮,跳转到:
### 限定哪些分支可以提交、可以 merge
- 也是在项目设置里面:
- 设置 CI (持续集成) 的 key 也是在这个地址上设置。
## Gitlab 的其他功能使用
#### 创建用户
- 地址:
- 创建用户是没有填写密码的地方,默认是创建后会发送邮件给用户进行首次使用的密码设置。但是,有时候没必要这样,你可以创建好用户之后,编辑该用户就可以强制设置密码了(即使你设置了,第一次用户使用还是要让你修改密码...真是严苛)
#### 创建群组
- 地址:
- 群组主要有三种 Visibility Level:
- Private(私有,内部成员才能看到),The group and its projects can only be viewed by members.
- Internal(内部,只要能登录 Gitlab 就可以看到),The group and any internal projects can be viewed by any logged in user.
- Public(所有人都可以看到),The group and any public projects can be viewed without any authentication.
#### 创建项目
- 地址:
#### 增加 SSH keys
- 地址:
- 官网指导:
- 新增 SSH keys:`ssh-keygen -t rsa -C "gitnavi@qq.com" -b 4096`
- linux 读取 SSH keys 值:`cat ~/.ssh/id_rsa.pub`,复制到 gitlab 配置页面
## 使用 Gitlab 的一个开发流程 - Git flow
- Git flow:我是翻译成:Git 开发流程建议(不是规范,适合大点的团队),也有一个插件叫做这个,本质是用插件来帮你引导做规范的流程管理。
- 这几篇文章很好,不多说了:
- 比较起源的一个说明(英文):
- Git-flow 插件也是他开发的,插件地址:
- Git-flow 插件的一些相关资料:
-
-
-
-
-
-
## 接入第三方登录
- 官网文档:
-
-
-
- gitlab 自己本身维护一套用户系统,第三方认证服务一套用户系统,gitlab 可以将两者关联起来,然后用户可以选择其中一种方式进行登录而已。
- 所以,gitlab 第三方认证只能用于网页登录,clone 时仍然使用用户在 gitlab 的账户密码,推荐使用 ssh-key 来操作仓库,不再使用账户密码。
- 重要参数:block_auto_created_users=true 的时候则自动注册的账户是被锁定的,需要管理员账户手动的为这些账户解锁,可以改为 false
- 编辑配置文件引入第三方:`sudo vim /etc/gitlab/gitlab.rb`,在 309 行有默认的一些注释配置
- 其中 oauth2_generic 模块默认是没有,需要自己 gem,其他主流的那些都自带,配置即可使用。
```
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['google_oauth2', 'facebook', 'twitter', 'oauth2_generic']
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_sync_profile_attributes'] = ['email','username']
gitlab_rails['omniauth_external_providers'] = ['google_oauth2', 'facebook', 'twitter', 'oauth2_generic']
gitlab_rails['omniauth_providers'] = [
{
"name"=> "google_oauth2",
"label"=> "Google",
"app_id"=> "123456",
"app_secret"=> "123456",
"args"=> {
"access_type"=> 'offline',
"approval_prompt"=> '123456'
}
},
{
"name"=> "facebook",
"label"=> "facebook",
"app_id"=> "123456",
"app_secret"=> "123456"
},
{
"name"=> "twitter",
"label"=> "twitter",
"app_id"=> "123456",
"app_secret"=> "123456"
},
{
"name" => "oauth2_generic",
"app_id" => "123456",
"app_secret" => "123456",
"args" => {
client_options: {
"site" => "http://sso.cdk8s.com:9090/sso",
"user_info_url" => "/oauth/userinfo"
},
user_response_structure: {
root_path: ["user_attribute"],
attributes: {
"nickname": "username"
}
}
}
}
]
```
## 资料
-
-
-
-
-
================================================
FILE: markdown-file/Glances-Install-And-Settings.md
================================================
# Glances 安装和配置
## Glances 介绍
- 相对 top、htop,它比较重,因此内容也比较多。小机子一般不建议安装。大机子一般也不建议一直开着。
- 官网:
- 官网 Github:
- 官网文档:
- 当前(201810)最新版本为 3.0.2
## Glances Linux 安装
- `curl -L https://bit.ly/glances | /bin/bash`
- 需要 5 ~ 10 分钟左右。
## 用法
#### 本地监控
- 进入实时监控面板(默认 3 秒一次指标):`glances`
- 每间隔 5 秒获取一次指标:`glances -t 5`
- 在控制面板中可以按快捷键进行排序、筛选
```
m : 按内存占用排序进程
p : 按进程名称排序进程
c : 按 CPU 占用率排序进程
i : 按 I/O 频率排序进程
a : 自动排序进程
d : 显示/隐藏磁盘 I/O 统计信息
f : 显示/隐藏文件系统统计信息
s : 显示/隐藏传感器统计信息
y : 显示/隐藏硬盘温度统计信息
l : 显示/隐藏日志
n : 显示/隐藏网络统计信息
x : 删除警告和严重日志
h : 显示/隐藏帮助界面
q : 退出
w : 删除警告记录
```
#### 监控远程机子
- 这里面的检控方和被监控的概念要弄清楚
- 作为服务端的机子运行(也就是被监控方):`glances -s`
- 假设它的 IP 为:192.168.1.44
- 必需打开 61209 端口
- 作为客户端的机子运行(要查看被检控方的数据):`glances -c 192.168.1.44`
- 这时候控制台输出的内容是被监控机子的数据
## 导出数据
- 个人测试没效果,后续再看下吧。
- 官网文档:
- 导出 CSV:`glances --export-csv /tmp/glances.csv`
- 导出 JSON:`glances --export-json /tmp/glances.json`
## 资料
-
-
-
-
-
-
================================================
FILE: markdown-file/GoAccess-Install-And-Settings.md
================================================
# GoAccess 安装和配置
## 官网资料
- 一般用于 Apache, Nginx 的 Log 分析
- 官网:
- 官网下载(201807 最新版本 1.2):
- 官网 Github:
- 国内中文站: