一,配置

  1. centos7.6(1810内核)(CentOS-7-x86_64-DVD-1810.iso)
  2. jdk1.8.0.301 (jdk-8u301-linux-x64.tar.gz)
  3. git-2.31.1 (git-2.31.1.tar.gz)
  4. apache-maven-3.6.3 (apache-maven-3.6.3-bin.tar.gz)
  5. mysql-5.7.22 (mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz)
  6. nginx-1.20.1(nginx-1.20.1.tar.gz)
  7. tomcat9(tomcat-9.0.53)
  8. redis-5.0.8(redis-5.0.9.tar.gz)
  9. rabbitmq-server-3.8.22-1.el7(rabbitmq-server-3.8.22-1.el7.noarch.rpm) + esl-erlang_23.3.4.5-1.e17 (erlang-23.3.4.5-1.el7.x86_64.rpm)
  10. nacos-server-2.0.3
  11. nexus-3.29.0-02
  12. gitlab-ce-13.12.9-ce.0.el7.x86_64.rpm
  13. jenkins-2.289.3-1.1(jenkins-2.289.3-1.1.noarch.rpm)
  14. mycat
  15. zentao
  16. xiaoyaoji

image.png

二,软件安装

1,centos7.6(1810内核)

Oracle VM VirtualBox 虚拟机内安装
新建目录
/usr/local
/opt 放所有安装的应用软件
/opt/tars 放所有的安装包

  1. ##########开机启动目录##################
  2. 方式一
  3. Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service
  4. /etc/systemd/system/multi-user.target.wants/ #自启目录,软连接
  5. /usr/lib/systemd/system/redis.service #自启目录,对应systemctl(包含service)
  6. systemctl enable nacos.service #开机自启
  7. systemctl disable nacos.service #取消自启
  8. 方式二
  9. /etc/init.d #自启目录,对应service
  10. ##对文件赋予执行权限
  11. chmod +x /etc/init.d/mysqld
  12. chmod 777 /etc/init.d/mysqld
  13. chkconfig --add mysqld #增加mysqld服务
  14. chkconfig --del mysqld #移除mysqld服务
  15. chkconfig mysqld on #开启mysqld自启服务
  16. chkconfig mysqld off #关闭mysqld自启服务
  17. chkconfig --list #查询mysqld服务情况
  1. 查看防火墙规则 firewall-cmd --list-all
  2. 防火墙服务状态 systemctl status firewalld.service
  3. 防火墙状态 firewall-cmd --state
  4. 开启防火墙 systemctl start firewalld.service
  5. 重启防火墙 systemctl restart firewalld.service
  6. 关闭防火墙 systemctl stop firewalld.service
  7. 永久关闭防火墙 systemctl disable firewalld
  8. 永久关闭防火墙 systemctl disable firewalld.service
  9. 永久开启防火墙 systemctl enable firewalld.service
  10. 开放80端口 firewall-cmd --permanent --add-port=80/tcp
  11. 移除80端口 firewall-cmd --permanent --remove-port=80/tcp
  12. 重启防火墙 systemctl restart firewalld.service
  13. 重新载入配置 firewall-cmd --reload

端口被占用

  1. 找到占用的端口,并杀掉
  2. 查看所有进程: netstat -nao
  3. 查找指定端口进程:netstat -nao|find "8086" netstat -ano|findstr 8086
  4. 终止指定PID进程: taskkill -F /pid 8548
  5. netstat -tunlp|grep 5601

SSH配置

  1. vim /etc/ssh/sshd_config ## SSH配置文件
  2. Port 22
  3. systemctl restart sshd ##重启SSH服务

2,jdk1.8.0.301

1 解压,移动到/usr/local目录
tar -zxvf jdk-8u301-linux-x64.tar.gz
mv jdk1.8.0_301 jdk
mv jdk/ /usr/local/java
tar -zxvf jdk-8u301-linux-x64.tar.gz -C /data
2 配置全局环境变量 vim /etc/profile

  1. #====================jdk1.8=============================
  2. export JAVA_HOME=/usr/local/java/jdk
  3. export JRE_HOME=$JAVA_HOME/jre
  4. export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
  5. export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

3 使配置生效 source /etc/profile
4 测试 java -version

3,nodejs

1,下载地址
https://nodejs.org/en/download/
2,解压,移动到/usr/local目录
tar -xvf node-v14.18.0-linux-x64.tar.xz
mv node-v14.18.0-linux-x64 /usr/local/nodejs
tar -xvf node-v14.18.0-linux-x64.tar.xz -C /usr/local/nodejs
3,配置全局环境变量 vim /etc/profile

  1. #====================nodejs14.18========================
  2. export NODE_HOME=/usr/local/node
  3. export PATH=$PATH:$NODE_HOME/bin
  4. export NODE_PATH=$NODE_HOME/lib/node_modules

4,使配置生效 source /etc/profile
5,测试 node -v npm -v

4,git-2.31.1

1 下载地址 :
https://git-scm.com/download/linux
https://www.kernel.org/pub/software/scm/git/git-2.31.1.tar.gz
2 解压编译

  1. # 安装编译依赖
  2. yum -y install autoconf
  3. yum -y install gcc gcc-c++ libstdc++-devel
  4. yum -y install openssl-devel
  5. # 解压
  6. mkdir -p /opt/gitTemp
  7. tar -zxvf git-2.31.1.tar.gz -C /opt/gitTemp
  8. cd git-2.31.1
  9. mkdir -p /usr/local/git
  10. # 检验相关依赖,设置安装路径
  11. ./configure --prefix=/usr/local/git
  12. # 编译安装
  13. make && make install
  14. #可以删除临时文件
  15. rm -rf git-2.31.1

3 .配置全局环境变量 vim/etc/profile

  1. #====================gti2.32.1==========================
  2. export GIT_HOME=/usr/local/git
  3. export PATH=$PATH:$GIT_HOME/bin

4 使配置生效 source /etc/profile
5 测试 git --version

5,apache-maven-3.6.3

1 解压,移动到/usr/local目录tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/maven
2 配置全局环境变量 vim /etc/profile

  1. #====================maven3.6.3=========================
  2. export MAVEN_HOME=/usr/local/maven
  3. export PATH=$PATH:$MAVEN_HOME/bin
  1. <!-- 配置Maven中央仓库 首选下载路径 -->
  2. <!-- 阿里云仓库 -->
  3. <mirror>
  4. <id>alimaven</id>
  5. <mirrorOf>central</mirrorOf>
  6. <name>aliyun maven</name>
  7. <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
  8. </mirror>
  9. <!-- 中央仓库1 -->
  10. <mirror>
  11. <id>repo1</id>
  12. <mirrorOf>central</mirrorOf>
  13. <name>Human Readable Name for this Mirror.</name>
  14. <url>http://repo1.maven.org/maven2/</url>
  15. </mirror>
  16. <!-- 中央仓库2 -->
  17. <mirror>
  18. <id>repo2</id>
  19. <mirrorOf>central</mirrorOf>
  20. <name>Human Readable Name for this Mirror.</name>
  21. <url>http://repo2.maven.org/maven2/</url>
  22. </mirror>

3 使配置生效 source /etc/profile
4 测试 mvn --version

6,tomcat-9.0.53

1 下载地址 https://tomcat.apache.org/download-90.cgi
apache-tomcat-9.0.53.tar.gz
2 安装

  1. #解压 apache-tomcat-9.0.53.tar.gz 并移动到 /usr/local/tomcat 目录下
  2. tar -zxvf apache-tomcat-9.0.53.tar.gz
  3. mv apache-tomcat-9.0.53 /usr/local/tomcat
  4. #启动命令
  5. cd /usr/local/tomcat/bin/
  6. ./startup.sh

3 开机启动
方式一
/etc/init.d/下 新建tomcat
vim /etc/init.d/tomcat

  1. #!/bin/sh
  2. # chkconfig: 345 99 10
  3. # description: Auto-starts tomcat
  4. # /etc/init.d/tomcatd
  5. # Tomcat auto-start
  6. # Source function library.
  7. #. /etc/init.d/functions
  8. # source networking configuration.
  9. #. /etc/sysconfig/network
  10. RETVAL=0
  11. export JAVA_HOME=/usr/local/java/jdk
  12. export JRE_HOME=/usr/local/java/jdk/jre
  13. export CATALINA_HOME=/usr/local/tomcat
  14. export CATALINA_BASE=/usr/local/tomcat
  15. start()
  16. {
  17. if [ -f $CATALINA_HOME/bin/startup.sh ];
  18. then
  19. echo $"Starting Tomcat"
  20. $CATALINA_HOME/bin/startup.sh
  21. RETVAL=$?
  22. echo " OK"
  23. return $RETVAL
  24. fi
  25. }
  26. stop()
  27. {
  28. if [ -f $CATALINA_HOME/bin/shutdown.sh ];
  29. then
  30. echo $"Stopping Tomcat"
  31. $CATALINA_HOME/bin/shutdown.sh
  32. RETVAL=$?
  33. sleep 1
  34. ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
  35. echo " OK"
  36. # [ $RETVAL -eq 0 ] && rm -f /var/lock/...
  37. return $RETVAL
  38. fi
  39. }
  40. case "$1" in
  41. start)
  42. start
  43. ;;
  44. stop)
  45. stop
  46. ;;
  47. restart)
  48. echo $"Restaring Tomcat"
  49. $0 stop
  50. sleep 1
  51. $0 start
  52. ;;
  53. *)
  54. echo $"Usage: $0 {start|stop|restart}"
  55. exit 1
  56. ;;
  57. esac
  58. exit $RETVAL
  1. chmod 775 /etc/init.d/tomcat
  2. chkconfig --add tomcat #增加服务
  3. chkconfig --del tomcat #移除服务
  4. chkconfig tomcat on #开机自启服务
  5. chkconfig tomcat off #关闭自启服务
  6. chkconfig --list #查询服务情况

方法二
linux 下tomcat开机自启动
在/etc/rc.d/rc.local中加入:
/usr/local/tomcat/bin/startup.sh

安全问题

  1. #禁止自动部署服务配置 修改Tomcat 根目录下的配置文件conf/server.xml,
  2. #将host节点的autoDeploy属性设置为“false”,如果host的deployOnStartup属性(如没有deployOnStartup配置可以忽略)为“true”,则也将其更改为“false”

7,nginx-1.20.1

1 下载地址 http://nginx.org/download/
2 安装依赖

  1. 1 先安装gcc-c++编译器
  2. yum install gcc-c++ yum install -y openssl openssl-devel
  3. 2 再安装pcre
  4. yum install -y pcre pcre-devel
  5. 3 再安装zlib
  6. yum install -y zlib zlib-devel

3 下面进行nginx的安装

  1. ## 解压
  2. tar -zxvf nginx-1.20.1.tar.gz
  3. ##进入nginx目录
  4. cd nginx-1.20.1
  5. ## 配置安路径,默认路径
  6. ./configure --prefix=/usr/local/nginx
  7. #./configure --prefix=/data/nginx
  8. # make
  9. make
  10. make install
  11. # 查找安装路径
  12. where is nginx

配制环境变量
vim /etc/profile

  1. #====================nginx1.20.0========================
  2. export PATH=$PATH:$JAVA_HOME/bin:/usr/local/nginx/sbin
  3. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  4. export JRE_HOME=$JAVA_HOME/jre

配置可选
mkdir -p /usr/local/nginx/conf.d 放所有的配置文件
vim /usr/local/nginx/conf/nginx.conf

  1. #user nobody;
  2. worker_processes 1;
  3. error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. '$status $body_bytes_sent "$http_referer" '
  15. '"$http_user_agent" "$http_x_forwarded_for"';
  16. access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. include /usr/local/nginx/conf.d/*.conf;
  23. }

vim /usr/local/nginx/conf.d/test.conf

  1. server {
  2. listen 8800;
  3. server_name localhost;
  4. #charset koi8-r;
  5. #access_log logs/host.access.log main;
  6. location / {
  7. root html;
  8. index index.html index.htm;
  9. }
  10. #error_page 404 /404.html;
  11. # redirect server error pages to the static page /50x.html
  12. error_page 500 502 503 504 /50x.html;
  13. location = /50x.html {
  14. root html;
  15. }
  16. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  17. #location ~ \.php$ {
  18. # proxy_pass http://127.0.0.1;
  19. #}
  20. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  21. #location ~ \.php$ {
  22. # root html;
  23. # fastcgi_pass 127.0.0.1:9000;
  24. # fastcgi_index index.php;
  25. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  26. # include fastcgi_params;
  27. #}
  28. # deny access to .htaccess files, if Apache's document root
  29. # concurs with nginx's one
  30. #location ~ /\.ht {
  31. # deny all;
  32. #}
  33. }
  34. # another virtual host using mix of IP-, name-, and port-based configuration
  35. #server {
  36. # listen 8000;
  37. # listen somename:8080;
  38. # server_name somename alias another.alias;
  39. # location / {
  40. # root html;
  41. # index index.html index.htm;
  42. # }
  43. #}
  44. # HTTPS server
  45. #server {
  46. # listen 443 ssl;
  47. # server_name localhost;
  48. # ssl_certificate cert.pem;
  49. # ssl_certificate_key cert.key;
  50. # ssl_session_cache shared:SSL:1m;
  51. # ssl_session_timeout 5m;
  52. # ssl_ciphers HIGH:!aNULL:!MD5;
  53. # ssl_prefer_server_ciphers on;
  54. # location / {
  55. # root html;
  56. # index index.html index.htm;
  57. # }
  58. #}

4 启动
进入sbin目录,可以看到有一个可执行文件nginx,直接./nginx执行就OK了。

  1. ./nginx 启动
  2. ./nginx -s stop 关闭
  3. ./nginx -s reload 重启

5 测试
然后在网页上访问自己的IP就可以了默认端口为80(出现如下欢迎界面就成功了!)
http://192.168.5.116:80
6 开放端口

  1. #开放80端口
  2. firewall-cmd --query-port=80/tcp
  3. firewall-cmd --add-port=80/tcp --permanent
  4. #重启防火墙
  5. systemctl restart firewalld

7 配置nginx开机自启动
cd /etc/systemd/system
vim nginx.service

  1. [Unit]
  2. Description=nginx service
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/nginx/sbin/nginx
  7. ExecReload=/usr/local/nginx/sbin/nginx -s reload
  8. ExecStop=/usr/local/nginx/sbin/nginx -s quit
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

保存脚本文件后设置文件的执行权限
chmod a+x /etc/init.d/nginx
使用chkconfig进行管理,将nginx服务加入chkconfig管理列表
chkconfig --add /etc/init.d/nginx
使用service对nginx进行启动,停止、重启等操作

  1. service nginx start
  2. service nginx stop
  3. service nginx restart
  4. service nginx reload
  5. systemctl daemon-reload #重新加载
  6. systemctl enable nacos.service #开机自启
  7. systemctl disable nacos.service #取消开机自启
  8. systemctl start nacos.service #启动

九、可能出现的问题

  • 1)、linux重启后无法开启nginx问题”var/run/nginx/nginx.pid” no such file or directory
    每次重启虚拟机后,var/run/nginx/目录都会被删除,所以无法在这个目录创建nginx.pid文件,可以自己创建/var/run/nginx/目录,然后可以运行,但治标不治本,下次虚拟机重启目录还会丢失。
    解决方法:再次重启虚拟机,nginx正常运行。
    原因:我们在配置文件显式的指定nginx.pid文件存放位置,然后创建logs文件夹,当linux重启后,logs文件夹不会被删除
    1. 打开/usr/local/nginx/conf/nginx.conf 配置文件
    2. pid logs/nginx.pid;###打开这个配置

    3. 同时在/usr/local/nginx目录下创建logs文件 :
    4. mkdir logs

查看是否启动成功
ps -ef | grep nginx
一,服务器篇 - 图2

8,mysql-5.7.33

1、下载
https://downloads.mysql.com/archives/community/
mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
image.png
2、解压
tar -zxvf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /opt
#复制解压后的mysql目录
mv mysql-5.7.33-linux-glibc2.12-x86_64 /opt/mysql
3、添加用户组和用户

  1. #添加用户组和用户 添加用户mysql 到用户组mysql 给mysql5.7.33用户组和权限
  2. groupadd mysql
  3. useradd -g mysql mysql
  4. chown -R mysql:mysql /opt/mysql

4、配置
查询并卸载系统自带的Mariadb

  1. rpm -qa | grep mariadb
  2. rpm -e --nodeps 文件名
  3. rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
  4. yum -y install libaio
  5. 原因是:以前的Linux系统中数据库大部分是mysql,不过自从被sun收购之后,就没用集成在centos这些开源Linux系统中了,
  6. 那么如果想用的话就需要自己安装了,首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb
  7. 而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安装mysql的步骤。

image.png

  1. mkdir -p /opt/mysql/log-bin
  2. mkdir -p /opt/mysql/data
  3. mkdir -p /opt/mysql/logs
  4. touch /opt/mysql/logs/error.log
  5. cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
  6. chmod 755 /etc/init.d/mysqld

修改启动脚本
vim /etc/init.d/mysqld
#修改项:

  1. basedir=/opt/mysql
  2. datadir=/opt/mysql/data

修改配置文件 vim /etc/my.cnf

  1. [client]
  2. default-character-set = utf8
  3. socket = /opt/mysql/mysql.sock
  4. [mysql]
  5. default-character-set = utf8
  6. [mysqld]
  7. ##sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  8. ##设置utf8字符集###
  9. character-set-client-handshake = FALSE
  10. character-set-server = utf8
  11. collation-server = utf8_unicode_ci
  12. init_connect=‘SET NAMES utf8
  13. ##创建新表时将使用的默认存储引擿
  14. default-storage-engine=INNODB
  15. ##端口
  16. port=3306
  17. bind-address = 0.0.0.0 # 表示允许任何主机登陆MySQL
  18. ##路径设置-开始-baseDir###
  19. basedir = /opt/mysql
  20. datadir = /opt/mysql/data
  21. socket = /opt/mysql/mysql.sock
  22. pid-file = /opt/mysql/mysqld.pid
  23. ##mysql错误日志
  24. log_error = /opt/mysql/logs/error.log
  25. ##慢查询日志
  26. slow_query_log = ON
  27. ##慢查询日志
  28. slow_query_log_file =/opt/mysql/logs/slowquery.log
  29. ##超过0.5秒记录
  30. long_query_time = 10
  31. ##sql语句执行时间大于long_query_time至少被检查到的次数。
  32. min_examined_row_limit = 100
  33. ##mysql未使用索引或索引扫描是否被记录到慢查询日志中
  34. log_queries_not_using_indexes = 1
  35. ##用来表示每分钟允许记录到slow log的且未使用索引的SQL语句次数
  36. log_throttle_queries_not_using_indexes = 10
  37. ##innodb日志文件存放位置
  38. ##innodb_log_group_home_dir = /opt/mysql/innodb
  39. ##innodb共享表空间文件
  40. ##innodb_data_home_dir = /opt/mysql/innodb
  41. ##InnoDB打开idb文件数量
  42. ##innodb_open_files = 512
  43. ##innodb_buffer_pool_size = 4G
  44. ##innodb_buffer_pool_instances = 1
  45. ##mysql所有操作日志 生产服务器不开启
  46. ##general_log = OFF
  47. ##mysql所有操作日志
  48. ##general_log_file = /opt/mysql/logs/general.log
  49. ##==========主从复制(主)=====================
  50. ##数据库服务器ID
  51. server-id = 1
  52. ##开启二进制日志
  53. ##log-bin=/opt/mysql/log-bin/mysql-bin
  54. ##log_bin_basename
  55. ##log_bin_index
  56. ##需要同步的数据库
  57. ##binlog-do-db=crm
  58. ##不需要同步的数据库
  59. binlog-ignore-db=mysql
  60. ##同binlog,定义binlog的位置和名称
  61. log_bin_index = /opt/mysql/log-bin/binlog.index
  62. ##binlog格式,复制有3种模式STATEMENT,ROW,MIXED
  63. binlog_format = row
  64. ##只保留最近10天的binlog日志
  65. expire_logs_days = 10
  66. ##每个binlog日志文件的最大容量
  67. max_binlog_size = 50M
  68. ##二进制缓冲区日志大小
  69. binlog_cache_size = 1M
  70. ##每个session分配的binlog缓存大小
  71. ##事务提交前产生的日志,记录到Cache中;事务提交后,则把日志持久化到磁盘
  72. binlog_cache_size = 2M
  73. ##开启log_slave_updates,从库的更新操作记录进binlog日志
  74. #log_slave_updates = ON
  75. ## sync_binlog=0(默认),事务提交后MySQL不刷新binlog_cache到磁盘,而让Filesystem自行决定
  76. ##或者cache满了才同步。
  77. ##sync_binlog=n,每进行n次事务提交之后,MySQL将binlog_cache中的数据强制写入磁盘。
  78. sync_binlog = 0
  79. ##将row模式下的sql语句,记录到binlog日志,默认是0(off)#
  80. binlog_rows_query_log_events = ON
  81. symbolic-links=0
  82. ##mysql允许的并发操作数量
  83. max_connections = 512
  84. ##mysql连接池线程数量
  85. thread_cache_size = 256
  86. ##在缓冲区中表的数量 一般4g内存2048
  87. table_open_cache = 512
  88. key_buffer_size = 1G
  89. ##关闭一个交互的连接之前所要等待的秒数
  90. interactive_timeout = 200
  91. ##关闭一个非交互的连接之前所要等待的秒数
  92. wait_timeout = 200
  93. ##禁用local_infile选项会降低攻击者通过SQL注入漏洞器读取敏感文件的能力
  94. local-infile=0
  95. ##0不自动提交 1自动提交事务
  96. autocommit = 1
  97. ##mysql可以timestamp字段可以使用null
  98. explicit_defaults_for_timestamp = ON
  99. ##跳过反向域名解析(mysql不可使用域名登录)
  100. skip_name_resolve = ON
  101. ##MySQL暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中
  102. back_log = 256
  103. ##错误连接次数
  104. max_connect_errors = 30
  105. ##每次最大提交数据包大小
  106. max_allowed_packet = 8M
  107. ##MEMORY引擎单表大小
  108. max_heap_table_size = 1024M
  109. ##每个临时表大小
  110. tmp_table_size = 2M
  111. ##配置表名不区分大小写 1:不区分
  112. #lower_case_table_names = 1
  113. ##每客户端索引和表查询数据缓冲区大小
  114. read_rnd_buffer_size = 2M
  115. ##全表扫描数据缓冲区大小
  116. read_buffer_size = 2M
  117. ##批量写入缓冲区大小
  118. bulk_insert_buffer_size = 16M
  119. ##每客户端排序数据缓冲区大小
  120. sort_buffer_size = 256K
  121. ##每客户端join数据缓冲区大小
  122. join_buffer_size = 512K
  123. ##关闭查询缓存(QC)
  124. #query_cache_size = 0
  125. #query_cache_type = 0
  126. ##mysql事务隔离级别
  127. #transaction_isolation = READ-COMMITTED
  128. ##记录管理语句
  129. #log_slow_admin_statements = 1
  130. ##记录复制语句
  131. #log_slow_slave_statements = 1
  132. ##记录警告日志
  133. #log_warnings = 1

5 初始化

  1. #给mysql5.7.33用户组和权限
  2. chown -R mysql:mysql /opt/mysql
  3. #初始化mysql
  4. /opt/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
  5. #不能初始化
  6. yum -y install numactl.x86_64; yum -y install libaio

6 测试
#启动服务 service mysqld start
#测试连接
bin/mysql -uroot
#加入环境变量,编辑vim /etc/profile,这样可以在任何地方用mysql命令了

  1. #====================mysql5.7.33========================
  2. export PATH=$PATH:/opt/mysql/bin

source /etc/profile
service mysqld start #启动mysql
service mysqld stop #关闭mysql
service mysqld status #查看运行状态

  1. firewall-cmd --permanent --add-port=3306/tcp 开放3306端口
  2. firewall-cmd --permanent --remove-port=3306/tcp 移除3306端口
  3. firewall-cmd --reload 重新载入配置

7 远程连接的用户权限
解决1:更改 ‘mysql’数据库’user’表’host’项,从’localhost’改成 ‘%’。

  1. ./bin/mysql -uroot
  2. use mysql;
  3. select 'host' from user where user='root';
  4. update user set host = '%' where user='root'; ##设置外网可以访问
  5. update user set authentication_string=password('123456') where user='root'; ##修改密码
  6. flush privileges;

解决2:直接授权
复制代码代码如下:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
5.2 安装时的一些错误
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决:yum -y install perl perl-devel
Installing MySQL system tables…./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:yum -y install libaio-devel
8 设置开机启动

  1. ##将服务文件复制一份到init.d下,并重命名为mysqld
  2. cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
  3. ##对文件赋予执行权限
  4. chmod +x /etc/init.d/mysqld chmod 777 /etc/init.d/mysqld
  5. ##增加mysqld服务
  6. chkconfig --add mysqld
  7. ##查询mysqld服务情况
  8. chkconfig --list mysqld
  9. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 默认的运行级别为2,3,4,5
  10. ##如果3,4,5 为off:
  11. chkconfig --level 345 mysqld on
  12. ##重启服务器验证:reboot


9,mycat1.6.7.6

1 下载地址
http://dl.mycat.org.cn/
2 安装流程
安装Java环境(mycat基于java) —> 下载mycat —> 新建mycat用户 —> 解压mycat —> 配置环境变量 —> 启动mycat

  1. # 解压
  2. tar -zxvf Mycat-server-1.6.7.6-release-linux.tar.gz
  3. # 剪切到/usr/local下
  4. mv mycat /usr/local/
  5. # 创建专门运行mycat账号
  6. adduser mycat
  7. # 切换到mycat文件夹路径下
  8. cd /usr/local
  9. # 将文件权限赋给mycat账号
  10. chown mycat:mycat -R /usr/local/mycat
  11. #配置环境变量添加
  12. vim /etc/profile
  13. #====================mycat1.6.7.6=======================
  14. export PATH=$PATH:/usr/local/mycat/bin
  15. # 刷新文件
  16. source /etc/profile
  17. # 切换mycat用户
  18. su mycat
  19. #切换目录
  20. cd /usr/local/mycat/bin/
  21. #启动mycat
  22. ./mycat start
  23. ./mycat console #带控制台

3 配置mycat的读写分离
配置逻辑库和数据节点
vim /usr/local/mycat/conf/schema.xml

  1. <?xml version="1.0"?>
  2. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  3. <mycat:schema xmlns:mycat="http://io.mycat/">
  4. <!-- <schema name="TESTDB" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1"> -->
  5. <!-- auto sharding by id (long) -->
  6. <!--splitTableNames 启用<table name 属性使用逗号分割配置多个表,即多个表使用这个配置-->
  7. <!--fetchStoreNodeByJdbc 启用ER表使用JDBC方式获取DataNode-->
  8. <!--
  9. <table name="customer" primaryKey="id" dataNode="dn1,dn2" rule="sharding-by-intfile" autoIncrement="true" fetchStoreNodeByJdbc="true">
  10. <childTable name="customer_addr" primaryKey="id" joinKey="customer_id" parentKey="id"> </childTable>
  11. </table>
  12. -->
  13. <!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"/> -->
  14. <!-- </schema> -->
  15. <!-- 逻辑数据库名name -->
  16. <schema name="testdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>
  17. <!-- <schema name="crm" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn2"></schema> -->
  18. <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"/> -->
  19. <dataNode name="dn1" dataHost="host1" database="testdb" />
  20. <!--
  21. <dataNode name="dn2" dataHost="localhost1" database="db2" />
  22. <dataNode name="dn3" dataHost="localhost1" database="db3" />
  23. <dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
  24. -->
  25. <!--
  26. <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
  27. <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
  28. <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" />
  29. -->
  30. <!-- balance="0" 默认读写库 -->
  31. <dataHost name="host1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
  32. <heartbeat>select user()</heartbeat>
  33. <!-- can have multi write hosts -->
  34. <writeHost host="hostM1" url="192.168.5.200:3306" user="root" password="123456">
  35. <!-- 读库 读写分离; 写走hostM1,读走hostS1; hostM1宕机了, hostS1也不可用 -->
  36. <readHost host="hostS1" url="192.168.5.201:3306" user="root" password="123456" />
  37. <!-- <readHost host="hostS2" url="192.168.5.114:3306" user="root" password="123456" /> -->
  38. </writeHost>
  39. <!-- 高可用,hostM1宕机了, hostM2顶上 -->
  40. <!-- <writeHost host="hostM2" url="192.168.5.112:3306" user="root" password="123456" /> -->
  41. </dataHost>
  42. <!--
  43. <dataHost name="sequoiadb1" maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc">
  44. <heartbeat> </heartbeat>
  45. <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng" password="jifeng"></writeHost>
  46. </dataHost>
  47. <dataHost name="oracle1" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="oracle" dbDriver="jdbc">
  48. <heartbeat>select 1 from dual</heartbeat>
  49. <connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql>
  50. <writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base" password="123456" > </writeHost> </dataHost>
  51. <dataHost name="jdbchost" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="mongodb" dbDriver="jdbc">
  52. <heartbeat>select user()</heartbeat>
  53. <writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost>
  54. </dataHost>
  55. <dataHost name="sparksql" maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc">
  56. <heartbeat> </heartbeat>
  57. <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng" password="jifeng"></writeHost>
  58. </dataHost>
  59. -->
  60. <!--
  61. <dataHost name="jdbchost" maxCon="1000" minCon="10" balance="0" dbType="mysql" dbDriver="jdbc">
  62. <heartbeat>select user()</heartbeat>
  63. <writeHost host="hostM1" url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost>
  64. </dataHost>
  65. -->
  66. </mycat:schema>

配置服务器权限
vim /usr/local/mycat/conf/server.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- - - Licensed under the Apache License, Version 2.0 (the "License");
  3. - you may not use this file except in compliance with the License. - You
  4. may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
  5. - - Unless required by applicable law or agreed to in writing, software -
  6. distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
  7. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
  8. License for the specific language governing permissions and - limitations
  9. under the License. -->
  10. <!DOCTYPE mycat:server SYSTEM "server.dtd">
  11. <mycat:server xmlns:mycat="http://io.mycat/">
  12. <system>
  13. <property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->
  14. <property name="ignoreUnknownCommand">0</property><!-- 0遇上没有实现的报文(Unknown command:),就会报错、1为忽略该报文,返回ok报文。
  15. 在某些mysql客户端存在客户端已经登录的时候还会继续发送登录报文,mycat会报错,该设置可以绕过这个错误-->
  16. <property name="useHandshakeV10">1</property>
  17. <property name="removeGraveAccent">1</property>
  18. <property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->
  19. <property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
  20. <property name="sqlExecuteTimeout">300</property> <!-- SQL 执行超时 单位:秒-->
  21. <property name="sequenceHandlerType">1</property>
  22. <!--
  23. <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
  24. INSERT INTO `travelrecord` (`id`,user_id) VALUES ('next value for MYCATSEQ_GLOBAL',"xxx");
  25. -->
  26. <!--必须带有MYCATSEQ_或者 mycatseq_进入序列匹配流程 注意MYCATSEQ_有空格的情况-->
  27. <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
  28. <property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->
  29. <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>
  30. <!-- 端口 -->
  31. <property name="serverPort">3307</property>
  32. <!-- 配置该属性的时候一定要保证mycat的字符集和mysql 的字符集是一致的 -->
  33. <property name="charset">utf8</property>
  34. <!-- 指定每次分配socker direct buffer 的值,默认是4096字节 -->
  35. <property name="processorBufferChunk">4096</property>
  36. <!-- 配置系统可用的线程数量,默认值为CPU核心X每个核心运行线程的数量 -->
  37. <property name="processors">4</property>
  38. <!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
  39. <!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
  40. <!-- <property name="processorBufferChunk">40960</property> -->
  41. <!--
  42. <property name="processors">1</property>
  43. <property name="processorExecutor">32</property>
  44. -->
  45. <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
  46. <property name="processorBufferPoolType">0</property>
  47. <!--默认是65535 64K 用于sql解析时最大文本长度 -->
  48. <!--<property name="maxStringLiteralLength">65535</property>-->
  49. <!--<property name="sequenceHandlerType">0</property>-->
  50. <!--<property name="backSocketNoDelay">1</property>-->
  51. <!--<property name="frontSocketNoDelay">1</property>-->
  52. <!--<property name="processorExecutor">16</property>-->
  53. <!--
  54. <property name="serverPort">8066</property>
  55. <property name="managerPort">9066</property>
  56. <property name="idleTimeout">300000</property>
  57. <property name="authTimeout">15000</property>
  58. <property name="bindIp">0.0.0.0</property>
  59. <property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //连接空闲检查
  60. <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property>
  61. -->
  62. <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
  63. <property name="handleDistributedTransactions">0</property>
  64. <!-- off heap for merge/order/group/limit 1开启 0关闭 -->
  65. <property name="useOffHeapForMerge">0</property>
  66. <!-- 单位为m -->
  67. <property name="memoryPageSize">64k</property>
  68. <!-- 单位为k -->
  69. <property name="spillsFileBufferSize">1k</property>
  70. <property name="useStreamOutput">0</property>
  71. <!-- 单位为m -->
  72. <property name="systemReserveMemorySize">384m</property>
  73. <!-- 是否采用zookeeper协调切换 -->
  74. <property name="useZKSwitch">false</property>
  75. <!-- XA Recovery Log日志路径 -->
  76. <!-- <property name="XARecoveryLogBaseDir">./</property> -->
  77. <!-- XA Recovery Log日志名称 -->
  78. <!-- <property name="XARecoveryLogBaseName">tmlog</property> -->
  79. <!-- 如果为 true的话 严格遵守隔离级别,不会在仅仅只有select语句的时候在事务中切换连接 -->
  80. <property name="strictTxIsolation">false</property>
  81. <!-- 如果为0的话,涉及多个DataNode的catlet任务不会跨线程执行 -->
  82. <property name="parallExecute">0</property>
  83. <property name="serverBacklog">2048</property>
  84. </system>
  85. <!-- 全局SQL防火墙设置 -->
  86. <!-- 白名单可以使用通配符%或着* -->
  87. <!-- 例如<host host="127.0.0.*" user="root"/> -->
  88. <!-- 例如<host host="127.0.*" user="root"/> -->
  89. <!-- 例如<host host="127.*" user="root"/> -->
  90. <!-- 例如<host host="1*7.*" user="root"/> -->
  91. <!-- 这些配置情况下对于127.0.0.1都能以root账户登录 -->
  92. <!--
  93. <firewall>
  94. <whitehost>
  95. <host host="1*7.0.0.*" user="root"/>
  96. </whitehost>
  97. <blacklist check="false"> </blacklist>
  98. </firewall>
  99. -->
  100. <!-- 全权限帐号 -->
  101. <user name="mycat" defaultAccount="true">
  102. <property name="password">123456</property>
  103. <property name="schemas">testdb</property>
  104. <!-- <property name="schemas">db_dwxc_mall_prod,crm,job,payment</property> -->
  105. <property name="defaultSchema">testdb</property>
  106. <!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->
  107. <!-- 表级 DML 权限设置 -->
  108. <!--
  109. <privileges check="false">
  110. <schema name="TESTDB" dml="0110" >
  111. <table name="tb01" dml="0000"></table>
  112. <table name="tb02" dml="1111"></table>
  113. </schema>
  114. </privileges>
  115. -->
  116. </user>
  117. <!-- 只读用户 -->
  118. <user name="user">
  119. <property name="password">123456</property>
  120. <property name="schemas">testdb</property>
  121. <property name="readOnly">true</property>
  122. <property name="defaultSchema">testdb</property>
  123. </user>
  124. </mycat:server>

设置内存占用 vim /usr/local/mycat/conf/wrapper.conf

  1. #wrapper.java.command=java
  2. wrapper.java.command=/usr/local/jdk/bin/java
  3. # wrapper.java.additional.9=-Xmx4G
  4. # wrapper.java.additional.10=-Xms1G
  5. wrapper.java.additional.9=-Xmx128M
  6. wrapper.java.additional.10=-Xm64M
  1. firewall-cmd --permanent --add-port=3307/tcp 开放3307端口
  2. firewall-cmd --permanent --remove-port=3307/tcp 移除3307端口
  3. firewall-cmd --reload 重新载入配置
  4. #切换路径
  5. cd /usr/local/mycat/bin
  6. #重启
  7. ./mycat restart

开机自启
方法一:
vim /etc/init.d/mycat

  1. #!/bin/sh
  2. #
  3. # Simple Mycat init.d script conceived to work on Linux systems
  4. # as it does use of the /proc filesystem.
  5. ### BEGIN INIT INFO
  6. # Provides: mycat
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Mycat data structure server
  10. # Description: Mycat data structure server. See https://github.com/MyCATApache/Mycat-Server
  11. ### END INIT INFO
  12. EXEC=/usr/local/mycat/bin/mycat
  13. PIDFILE=/usr/local/mycat/mycat.pid
  14. case "$1" in
  15. start)
  16. if [ -f $PIDFILE ]
  17. then
  18. echo "$PIDFILE exists, process is already running or crashed"
  19. else
  20. echo "Starting Mycat server..."
  21. $EXEC start
  22. fi
  23. ;;
  24. stop)
  25. if [ ! -f $PIDFILE ]
  26. then
  27. echo "$PIDFILE does not exist, process is not running"
  28. else
  29. PID=$(cat $PIDFILE)
  30. echo "Stopping ..."
  31. $EXEC stop
  32. while [ -x /proc/${PID} ]
  33. do
  34. echo "Waiting for Mycat to shutdown ..."
  35. sleep 1
  36. done
  37. echo "Mycat stopped"
  38. fi
  39. ;;
  40. *)
  41. echo "Please use start or stop as first argument"
  42. ;;
  43. esac
  1. 设置权限 chmod +x /etc/init.d/mycat
  2. 增加开机服务 chkconfig --add mycat
  3. 设置开机启动 chkconfig mycat on
  4. 移除开机启动 chkconfig mycat off
  5. 查看开机启动 chkconfig --list

方法二:

  1. #修改脚本文件 rc.local
  2. vim /etc/rc.d/rc.local
  3. export JAVA_HOME=/usr/local/jdk
  4. /usr/local/mycat/bin/mycat start


好了 我们来连接一下看一下效果,最终效果如下图所示
image.png
因为之前配置好了主从复制,所以两个数据库数据时同步的,然后当你读取数据的时候是读取的slave的数据,所以读写分离完成,
项目开发中,我们只需要将mysql的连接地址换成mycat的地址即可,无需任何其余操作,更不会造成多余的业务逻辑,这样,我们基于mycat的读写分离算是大功告成啦!
常用命令

  1. 强制走master/*!mycat:db_type=master*/ select * from tbl_user
  2. 强制走slave /*!mycat:db_type=slave*/ select * from tbl_user
  3. firewall-cmd --permanent --add-port=3307/tcp 开放3307端口
  4. firewall-cmd --permanent --remove-port=3307/tcp 移除3307端口
  5. firewall-cmd --reload 重新载入配置
  6. 设置权限 chmod +x /etc/init.d/mycat
  7. 增加开机服务 chkconfig --add mycat
  8. 设置开机启动 chkconfig mycat on
  9. 移除开机启动 chkconfig mycat off
  10. 查看开机启动 chkconfig --list

10,redis-5.0.9

1 下载地址
http://download.redis.io/releases/
2 安装gcc依赖
由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装

  1. gcc -v // 查看gcc版本
  2. yum install -y gcc-c++ // 默认安装4.8.5版本

3 下载并解压安装包
wget http://download.redis.io/releases/redis-6.0.9.tar.gz
tar -zxvf redis-5.0.9.tar.gz
4 编译/安装
编译

  1. cd切换到redis解压目录下
  2. cd /usr/local/redis
  3. 安装 (默认安装路径:/usr/local/redis/ )
  4. 进入 src 目录后执行 make install
  5. cd /usr/local/redis
  6. make install 安装在当前目录的src目录
  7. make install PREFIX=/usr/local/redis 安装并指定安装目录

注:如果报错: 加入参数再编译:MALLOC=libc eg: make MALLOC=libc
可能会出现以下错误

  1. jemalloc/jemalloc.h:没有那个文件或目录
  2. cd src && make all
  3. make[1]: Entering directory `/opt/redis-5.0.8/src'
  4. CC adlist.o
  5. In file included from adlist.c:34:0:
  6. zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
  7. #include <jemalloc/jemalloc.h>
  8. ^
  9. compilation terminated.
  10. make[1]: *** [adlist.o] Error 1
  11. make[1]: Leaving directory

5 启动服务,指定配置文件

  1. firewall-cmd --permanent --add-port=6379/tcp 开放6379端口
  2. firewall-cmd --permanent --remove-port=6379/tcp 移除6379端口
  3. firewall-cmd --reload 重新载入配置
  1. mkdir /usr/local/redis/logs
  2. mkdir /usr/local/redis/config
  3. cp /usr/local/redis/redis.conf /usr/local/redis/config/redis_6379.conf
  4. ./redis-server ../config/redis_6379.conf ##加载指定的配置文件启动
  5. 127.0.0.1:6379> info Server ##查看当前加载的配置文件

后台启动

修改配置文件 vim redis.conf
(1) 注释掉69 bind 127.0.0.1 (原因:bind 127.0.0.1生效,只能本机访问redis)(解决只能特定网段连接的限制;正式服务器部署如阿里云、华为云,为项目安全严格可以保留注释,自己测试服务使用的话就注释掉)
(2) 将88 protected-mode 属性改为 no (关闭保护模式,不然会阻止远程访问;同上,正式服务器项目上线可不修改)
(3) 将137 daemonize 属性改为 yes (这样启动时就是后台启动)
(4) 将171 logfile “/usr/local/redis/logs/redis.log”
将171 requirepass foobared
requirepass 123456
设置密码
(5) 将699 appendonly属性改为 yes (这样启动时就是后台启动)
6 设置开机启动
创建启动脚本文件 redid
vim /etc/init.d/redis
复制粘贴以下内容:

  1. #!/bin/sh
  2. #
  3. # Simple Redis init.d script conceived to work on Linux systems
  4. # as it does use of the /proc filesystem.
  5. ### BEGIN INIT INFO
  6. # Provides: redis_6379
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Redis data structure server
  10. # Description: Redis data structure server. See https://redis.io
  11. ### END INIT INFO
  12. #redis配置信息
  13. REDISPORT=6379
  14. EXEC=/usr/local/redis/bin/redis-server
  15. CLIEXEC=/usr/local/redis/bin/redis-cli
  16. PIDFILE=/var/run/redis_${REDISPORT}.pid
  17. #redis启动时加载的配置文
  18. CONF="/usr/local/redis/config/redis_6379.conf"
  19. case "$1" in
  20. start)
  21. if [ -f $PIDFILE ]
  22. then
  23. echo "$PIDFILE exists, process is already running or crashed"
  24. else
  25. echo "Starting Redis server..."
  26. $EXEC $CONF
  27. fi
  28. ;;
  29. stop)
  30. if [ ! -f $PIDFILE ]
  31. then
  32. echo "$PIDFILE does not exist, process is not running"
  33. else
  34. PID=$(cat $PIDFILE)
  35. echo "Stopping ..."
  36. $CLIEXEC -p $REDISPORT shutdown
  37. while [ -x /proc/${PID} ]
  38. do
  39. echo "Waiting for Redis to shutdown ..."
  40. sleep 1
  41. done
  42. echo "Redis stopped"
  43. fi
  44. ;;
  45. *)
  46. echo "Please use start or stop as first argument"
  47. ;;
  48. esac

设置脚本权限 chmod +x /etc/init.d/redis
使用service命令使用redis service redis start
增加redis 服务 chkconfig --add redis
设置开机启动 chkconfig redis on
移除开机启动 chkconfig redis off
查看开机启动 chkconfig --list redis
测试 redis
一,服务器篇 - 图6
7 卸载
卸载redis非常的简单,只需要简单的三步
停止redis服务器 ps aux|grep redis
通过下面的命令停止redis服务器 redis-cli shutdown
需要注意的是,由于我的redis命令都安装到/usr/local/bin目录下面了,并且添加到环境变量PATH里面了,所以可以直接运行。
删除make的时候生成的几个redisXXX的文件

  1. ll /usr/local/bin
  2. rm -f /usr/local/bin/redis*
  3. ll /usr/local/bin

顺便也删除掉解压后的文件目录和所以文件
rm -rf redis
这样,redis就卸载完成了。

11,rabbitmq-server-3.8.22-1.el7

详见:https://www.yuque.com/zhang.qiang/rabbitmq/yh881k

12,MongoDb-4.2.5

下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.5.tgz
1,我们安装到 /opt/mongodb 下,首先将.tgz 文件传到 /home 下。

  1. tar -xzvf ./mongodb-linux-x86_64-rhel70-4.2.5.tgz # 解压
  2. cd /opt/mongodb
  3. # 创建相应的目录
  4. mkdir conf
  5. mkdir logs
  6. mkdir data
  7. # 创建配置文件
  8. vim ./conf/mongodb.conf
  9. port=27017 #端口
  10. dbpath= /home/mongodb-linux-x86_64-rhel70-4.2.5/data #数据库存文件存放目录
  11. logpath= /home/mongodb-linux-x86_64-rhel70-4.2.5/logs/mongodb.log #日志文件存放路径
  12. logappend=true #使用追加的方式写日志
  13. fork=true #以守护进程的方式运行,创建服务器进程
  14. maxConns=1000 #最大同时连接数
  15. noauth=true #不启用验证
  16. journal=true #每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。
  17. #即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。
  18. storageEngine=wiredTiger #存储引擎有mmapv1、wiretiger、mongorocks
  19. bind_ip = 0.0.0.0 #这样就可外部访问了,例如从win10中去连虚拟机中的MongoDB
  1. role 除了 readWrite,还有其他角色列表如下:
  2. Read:允许用户读取指定数据库
  3. readWrite:允许用户读写指定数据库
  4. dbAdmin:允许用户在指定数据库中执行管理函数,如索引创建、删除,查看统计或访问system.profile
  5. userAdmin:允许用户向system.users集合写入,可以找指定数据库里创建、删除和管理用户
  6. clusterAdmin:只在admin数据库中可用,赋予用户所有分片和复制集相关函数的管理权限。
  7. readAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读权限
  8. readWriteAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的读写权限
  9. userAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的userAdmin权限
  10. dbAdminAnyDatabase:只在admin数据库中可用,赋予用户所有数据库的dbAdmin权限。
  11. root:只在admin数据库中可用。超级账号,超级权限
  12. 再次编辑 ./conf/mongodb.conf,设置:
  13. authorization: enabled #启用验证

启动

  1. vim ./start.sh
  2. #!/bin/bash
  3. ./mongod --config ../conf/mongodb.conf
  4. if [ $? -eq 0 ]; then
  5. echo -e " 启动成功!启动端口为默认 27017 "
  6. exit 0
  7. else
  8. echo -e "启动失败...... "
  9. exit 1
  10. fi
  11. vim ./stop.sh
  12. 输入以下内容保存:
  13. #!/bin/bash
  14. echo 'Stop mongodb is begin ...'
  15. ./mongod -shutdown --config ../conf/mongodb.conf
  16. if [ $? -eq 0 ]; then
  17. echo -e "mongdb 停止成功!"
  18. else
  19. echo -e "mongdb 停止失败......m"
  20. exit 1
  21. fi
  22. echo 'Stop mongodb is end ...'
  23. chmod 777 start.sh # 修改执行权限
  24. chmod 777 stop.sh

自启 vim /etc/init.d/mongodb

  1. #!/bin/sh
  2. #chkconfig: 2345 80 90
  3. #description: mongodb
  4. start() {
  5. /opt/mongodb/bin/mongod --config /opt/mongodb/conf/mongodb.conf
  6. }
  7. stop() {
  8. /opt/mongodb/bin/mongod -config /opt/mongodb/conf/mongodb.conf --shutdown
  9. }
  10. case "$1" in
  11. start)
  12. start
  13. ;;
  14. stop)
  15. stop
  16. ;;
  17. restart)
  18. stop
  19. start
  20. ;;
  21. *)
  22. echo $"Usage: $0 {start|stop|restart}"
  23. exit 1
  24. esac

测试

  1. ./bin/mongo -u "admin" -p "123456" --authenticationDatabase "admin"
  2. > use admin
  3. > show dbs;

12,elasticsearch7.6.2

下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-6-2
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-2-2
kibana:https://www.elastic.co/cn/downloads/kibana
分词器 :https://github.com/medcl/elasticsearch-analysis-ik/releases
logstash:https://www.elastic.co/cn/downloads/logstash

es、kibana、logstash的版本要一致

一,安装elasticsearch7.6.2

  1. tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
  2. mv elasticsearch-7.6.2 elasticsearch
  3. mv elasticsearch /opt
  4. # 创建es组和用户
  5. groupadd es
  6. useradd es -g es
  7. # 新增es操作账户
  8. useradd es
  9. passwd es
  10. 设置密码:
  11. laowang
  12. laowang
  13. [root@w158 opt]# chown -R es:es /opt/elasticsearch

修改配置文件 vim elasticsearch.yml

  1. mkdir data
  2. cd config/
  3. cp elasticsearch.yml elasticsearch.yml.bak
  4. #其余全部注释,直接复制进去,ip根据本机进行修改
  5. path.data: /opt/elasticsearch/data
  6. path.logs: /opt/elasticsearch/logs
  7. cluster.initial_master_nodes: ["node-1"]
  8. #集群的名称
  9. cluster.name: es
  10. #节点名称,其余两个节点分别为node-1 和node-3
  11. node.name: node-1
  12. #指定该节点是否有资格被选举成为master节点,默认是true,es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
  13. #node.master: true
  14. #允许该节点存储数据(默认开启)
  15. #node.data: true
  16. #设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,当jvm开始swapping时es的效率会降低,所以要保证它不swap
  17. #bootstrap.memory_lock: true
  18. #设置network.host 使es可以在其他服务器访问
  19. network.host: 0.0.0.0
  20. http.port: 9200
  21. # 设置节点间交互的tcp端口,默认是9300
  22. transport.tcp.port: 9300
  23. #Elasticsearch将绑定到可用的环回地址,并将扫描端口9300到9305以尝试连接到运行在同一台服务器上的其他节点。
  24. discovery.seed_hosts: ["127.0.0.1", "[::1]"]
  25. #discovery.zen.ping.unicast.hosts: ["192.168.85.158"]
  26. #允许跨域访问
  27. http.cors.enabled: true
  28. http.cors.allow-origin: "*"
  29. #开启x-pack验证
  30. xpack.security.enabled: true
  31. xpack.license.self_generated.type: basic
  32. xpack.security.transport.ssl.enabled: true
  33. #执行设置用户名和密码的命令,这里需要为4个用户分别设置密码,elastic, kibana, logstash_system,beats_system
  34. #Elasticsearch需要提前启动一次,否则会出现以下Error:
  35. #ERROR: Elasticsearch keystore file is missing [/kaysen
  36. #lasticsearch必须处于启动状态,否则会出现以下Error
  37. #Connection failure to: http://127.0.0.1:9200/_security/_authenticate?pretty failed: Connection refused (Connection refused)
  38. #ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?
  39. #密码生成的两种方式 auto:各用户自动生成密码;interactive:手动设置密码。
  40. ./bin/elasticsearch-setup-passwords interactive

设置 jvm.option (默认为1g 服务器内存足够,可跳过)
vim /elasticsearch/config/jvm.options

  1. -Xms512m
  2. -Xmx512m

设置 vm.max_map_count如果小于262144就修改或没有设置就执行这一步
vim /etc/sysctl.conf
/etc/sysctl.conf里追加以下内容:
vm.max_map_count = 655360

置limits.conf 修改内核参数
vim /etc/security/limits.conf

  1. #往limits.conf里追加以下内容:
  2. es soft nofile 65536
  3. es hard nofile 65536

刷新参数: sysctl -p

测试 地址:http://192.168.85.158:9200

  1. # 切换到es用户
  2. su es
  3. # 启动
  4. cd /usr/local/elk/elasticsearch-7.6.2
  5. ./bin/elasticsearch
  6. # 后台启动,默认log文件目录:/usr/local/elasticsearch-7.6.2/logs/my-es.log
  7. ./bin/elasticsearch -d
  8. # 关闭
  9. ps -aef|grep elasticsearch
  10. Kill -9 -F 1213

image.png
开机自启

  1. #!/bin/bash
  2. #chkconfig: 345 63 37
  3. #description: elasticsearch
  4. #processname: elasticsearch-7.10.2
  5. # 这个目录是你Es所在文件夹的目录
  6. export ES_HOME=/opt/elasticsearch
  7. case $1 in
  8. start)
  9. su es<<!
  10. cd $ES_HOME
  11. ./bin/elasticsearch -d -p pid
  12. exit
  13. !
  14. echo "elasticsearch is started"
  15. ;;
  16. stop)
  17. pid=`cat $ES_HOME/pid`
  18. kill -9 $pid
  19. echo "elasticsearch is stopped"
  20. ;;
  21. restart)
  22. pid=`cat $ES_HOME/pid`
  23. kill -9 $pid
  24. echo "elasticsearch is stopped"
  25. sleep 1
  26. su es<<!
  27. cd $ES_HOME
  28. ./bin/elasticsearch -d -p pid
  29. exit
  30. !
  31. echo "elasticsearch is started"
  32. ;;
  33. *)
  34. echo "start|stop|restart"
  35. ;;
  36. esac
  37. exit 0

报错

  1. [es@vince elasticsearch-7.6.2]$ ./bin/elasticsearch -d
  2. Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
  3. output:
  4. #
  5. # There is insufficient memory for the Java Runtime Environment to continue.
  6. # Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
  7. # An error report file with more information is saved as:
  8. # logs/hs_err_pid17395.log
  9. 解决:调小启动内存
  10. vi /usr/local/elasticsearch-7.6.2/config/jvm.options
  11. # 修改为512m
  12. #-Xms2g
  13. #-Xmx2g
  14. -Xms512m
  15. -Xmx512m

failed to obtain node locks(绑定节点失败)

  1. uncaught exception in thread [main]
  2. java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/elk/elasticsearch-7.6.2/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
  3. at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:301)
  4. 解决:由于上一次没有正常关闭es导致。
  5. # 查看进程
  6. ps aux | grep elastic
  7. # 查询到以下进程
  8. es 12705 0.0 0.0 112728 976 pts/2 R+ 23:53 0:00 grep --color=auto elastic
  9. es 30116 12.1 41.2 2833332 776204 pts/2 Sl 23:48 0:36 /usr/local/elk/elasticsearch-7.6.2/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=COMPAT -Xms512m -Xmx512m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-14028617868054823808 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=268435456 -Des.path.home=/usr/local/elk/elasticsearch-7.6.2 -Des.path.conf=/usr/local/elk/elasticsearch-7.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elk/elasticsearch-7.6.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
  10. # 杀掉进程,重新启动就可以了
  11. kill -9 30116

(1)ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

  1. 原因:无法创建本地文件问题,用户最大可创建文件数太小
  2. 解决方案:
  3. 切换到 root 用户,编辑 limits.conf 配置文件, 添加类似如下内容:
  4. vi /etc/security/limits.conf
  5. 添加如下内容:
  6. * soft nofile 65536
  7. * hard nofile 131072
  8. * soft nproc 2048
  9. * hard nproc 4096
  10. 备注: * 代表 Linux 所有用户名称(比如 es
  11. 保存、退出、重新登录才可生效

(2)max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

  1. 原因:最大虚拟内存太小
  2. 大讲台科技
  3. - 2 -
  4. 解决方案:切换到 root 用户下,修改配置文件 sysctl.conf
  5. vi /etc/sysctl.conf
  6. 添加下面配置:
  7. vm.max_map_count=655360
  8. 并执行命令(配置生效):
  9. sysctl -p
  10. 然后重新启动 elasticsearch,即可启动成功。

二,安装kibana7.6.2

1,直接接解压到 /opt/kibana
2,修改配置文件vim /opt/kibana/config/kibana.yml

  1. server.port: 5601
  2. server.host: "0.0.0.0"
  3. elasticsearch.hosts: ["http://localhost:9200"]
  4. i18n.locale: "zh-CH"
  5. #如果ES设置密码
  6. elasticsearch.username: "elastic"
  7. elasticsearch.password: "123456"

3,测试 http://8.142.172.213:5601/

  1. #启动
  2. su es
  3. cd /opt/kibana/bin
  4. ./kibana
  5. #关闭进程
  6. netstat -tunlp|grep 5601

4,开机自启
cd /etc/init.d
vim kibana

  1. #!/bin/bash
  2. #chkconfig: 345 63 37
  3. #description: kibana
  4. #processname:kibana-7.6.2
  5. export KIBANA_HOME=/opt/kibana
  6. case $1 in
  7. start)
  8. su es<<!
  9. cd $KIBANA_HOME
  10. nohup ./bin/kibana -p pid &
  11. exit
  12. !
  13. echo "kibana is started"
  14. ;;
  15. stop)
  16. pid=`cat $KIBANA_HOME/pid`
  17. kill -9 $pid
  18. echo "kibana is stopped"
  19. ;;
  20. restart)
  21. pid=`cat $KIBANA_HOME/pid`
  22. kill -9 $pid
  23. echo "kibana is stopped"
  24. sleep 5
  25. su es<<!
  26. cd $KIBANA_HOME
  27. ./bin/kibana -p pid &
  28. exit
  29. !
  30. echo "kibana is started"
  31. ;;
  32. *)
  33. echo "start|stop|restart"
  34. ;;
  35. esac
  36. exit 0
  1. systemctl enable kibana #开机自启
  2. systemctl start kibana #启动
  3. systemctl stop kibana #停止
  4. systemctl restart kibana #重启

    三,中文分词器

    下载好相应版本的zip包,解压后放到elasticsearch/plugins/下,然后需要删除原压缩包文件。
    一下命令使用的es用户,非root用户。如果使用了root用户请将ik目录赋权限给es用户。 ```css cd /opt/software mkdir ik unzip -d ik/ elasticsearch-analysis-ik-7.6.2.zip mv ik/ /opt/elasticsearch/plugins/

chown -R es:es /opt/elasticsearch/

  1. <a name="kbbpP"></a>
  2. ### 四,logstash-7.6.2
  3. 下载地址:[https://www.elastic.co/cn/downloads/logstash](https://www.elastic.co/cn/downloads/logstash)<br />es、kibana、logstash的版本要一致<br />安装目录 `/opt/logstash`<br />添加配置文件 logstash.conf<br />`vim /opt/logstash/config/logstash.conf `
  4. ```cpp
  5. input {
  6. tcp {
  7. #开放远程连接
  8. host => "0.0.0.0"
  9. port => 4560
  10. mode => "server"
  11. codec => json_lines
  12. }
  13. }
  14. output {
  15. elasticsearch {
  16. #ES的部署位置
  17. hosts => "localhost:9200"
  18. #存储在ES中的索引名,对应下面的SpringBoot集成 logstash 的日志配置文件里{“appname”:“file-manager”}
  19. index => "springboot-logstash-%{+YYYY.MM.dd}%{[appname]}"
  20. }
  21. }

户动

  1. cd logstash/bin
  2. ./logstash -f ../config/logstash.conf

12,nacos-server-2.0.3

1,下载地址
https://github.com/alibaba/nacos/releases
nacos-server-2.0.3.tar.gz
2,安装
tar -zxvf nacos-server-2.0.3.tar.gz
mv nacos /usr/local/
3,修改配置文件 application.properties
vim /usr/local/nacos/conf/application.properties

  1. #*************** Spring Boot Related Configurations ***************#
  2. ### Default web context path:
  3. server.servlet.contextPath=/nacos
  4. ### Default web server port:
  5. server.port=8848
  6. #*************** Network Related Configurations ***************#
  7. ### If prefer hostname over ip for Nacos server addresses in cluster.conf:
  8. # nacos.inetutils.prefer-hostname-over-ip=false
  9. ### Specify local server's IP:
  10. # nacos.inetutils.ip-address=
  11. #*************** Config Module Related Configurations ***************#
  12. ### If use MySQL as datasource:
  13. spring.datasource.platform=mysql
  14. ### Count of DB:
  15. db.num=1
  16. ### Connect URL of DB:
  17. db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
  18. db.user.0=root
  19. db.password.0=123456
  20. ### Connection pool configuration: hikariCP
  21. db.pool.config.connectionTimeout=30000
  22. db.pool.config.validationTimeout=10000
  23. db.pool.config.maximumPoolSize=20
  24. db.pool.config.minimumIdle=2

image.png
执行/opt/nacos/conf目录下nacos-mysql.sql文件,进行数据库初始化
4,启动i18n.locale: “zh-CH”
进入bin目录 cd /usr/local/nacos/bin
启动nacos命令(-m standalone 指定启动模式为单机版):
./startup.sh -m standalone
查看日志tail -500f /usr/local/nacos/logs/start.out
5,测试
默认端口为8848,在application.aproperties中可以配置。
centos7给防火墙开发8848端口:
firewall-cmd --zone=public --add-port=8848/tcp --permanent
重新载入防火墙:
firewall-cmd --reload
访问nacos控制台,http://192.168.2.220:8848/nacoshttp://ip:8848/nacos
用户名密码均为:nacos
关闭nacos命令,bin目录下执行 ./shutdown.sh
单机版部署成功。
6,开机自启(无)
vim /nacos.service
添加如下:

  1. [Unit]
  2. Description=nacos
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
  7. ExecReload=/usr/local/nacos/bin/shutdown.sh
  8. ExecStop=/usr/local/nacos/bin/shutdown.sh
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

修改启动脚本
vim /usr/local/nacos/bin/startup.sh

  1. [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
  2. [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
  3. [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
  4. ## 增加Jdk位置
  5. [ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/local/java/jdk
  6. [ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME

保存退出后,执行以下命令

  1. systemctl daemon-reload #重新加载
  2. systemctl enable nacos.service #开机自启
  3. systemctl disable nacos.service #取消开机自启
  4. systemctl start nacos.service #启动


13,seata-1.3

1 解压

  1. unzip seata-server-1.3.0.zip
  2. mv seata /usr/local

2 新建 vim config.txt

  1. store.mode=db
  2. store.db.datasource=druid
  3. store.db.dbType=mysql
  4. store.db.driverClassName=com.mysql.jdbc.Driver
  5. store.db.url=jdbc:mysql://172.0.0.1:3306/jx_seata?useUnicode=true
  6. store.db.user=root
  7. store.db.password=123456
  8. store.db.minConn=5
  9. store.db.maxConn=30
  10. store.db.globalTable=global_table
  11. store.db.branchTable=branch_table
  12. store.db.queryLimit=100
  13. store.db.lockTable=lock_table
  14. store.db.maxWait=5000
  15. service.vgroupMapping.mall-product-tx-group=default
  16. service.vgroupMapping.mall-order-tx-group=default
  17. service.vgroupMapping.mall-ware-tx-group=default

3 新建 /usr/local/seata/conf/sh/nacos-config.sh

  1. #!/usr/bin/env bash
  2. # Copyright 1999-2019 Seata.io Group.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at、
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. while getopts ":h:p:g:t:u:w:" opt
  16. do
  17. case $opt in
  18. h)
  19. host=$OPTARG
  20. ;;
  21. p)
  22. port=$OPTARG
  23. ;;
  24. g)
  25. group=$OPTARG
  26. ;;
  27. t)
  28. tenant=$OPTARG
  29. ;;
  30. u)
  31. username=$OPTARG
  32. ;;
  33. w)
  34. password=$OPTARG
  35. ;;
  36. ?)
  37. echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
  38. exit 1
  39. ;;
  40. esac
  41. done
  42. if [[ -z ${host} ]]; then
  43. host=localhost
  44. fi
  45. if [[ -z ${port} ]]; then
  46. port=8848
  47. fi
  48. if [[ -z ${group} ]]; then
  49. group="SEATA_GROUP"
  50. fi
  51. if [[ -z ${tenant} ]]; then
  52. tenant=""
  53. fi
  54. if [[ -z ${username} ]]; then
  55. username=""
  56. fi
  57. if [[ -z ${password} ]]; then
  58. password=""
  59. fi
  60. nacosAddr=$host:$port
  61. contentType="content-type:application/json;charset=UTF-8"
  62. echo "set nacosAddr=$nacosAddr"
  63. echo "set group=$group"
  64. failCount=0
  65. tempLog=$(mktemp -u)
  66. function addConfig() {
  67. curl -X POST -H "${contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$1&group=$group&content=$2&tenant=$tenant&username=$username&password=$password" >"${tempLog}" 2>/dev/null
  68. if [[ -z $(cat "${tempLog}") ]]; then
  69. echo " Please check the cluster status. "
  70. exit 1
  71. fi
  72. if [[ $(cat "${tempLog}") =~ "true" ]]; then
  73. echo "Set $1=$2 successfully "
  74. else
  75. echo "Set $1=$2 failure "
  76. (( failCount++ ))
  77. fi
  78. }
  79. count=0
  80. for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
  81. (( count++ ))
  82. key=${line%%=*}
  83. value=${line#*=}
  84. addConfig "${key}" "${value}"
  85. done
  86. echo "========================================================================="
  87. echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
  88. echo "========================================================================="
  89. if [[ ${failCount} -eq 0 ]]; then
  90. echo " Init nacos config finished, please start seata-server. "
  91. else
  92. echo " init nacos config fail. "
  93. fi

4 开机自机脚本/etc/init.d/seata

  1. #!/bin/bash
  2. #
  3. #chkconfig: 345 63 37
  4. #description: seata
  5. #processname: seata
  6. export NODE_HOME=/usr/local/nodejs
  7. export JAVA_HOME=/usr/local/jdk
  8. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  9. export NODE_PATH=$NODE_HOME/lib/node_modules
  10. export PATH=$PWD/bin:/usr/local/openresty/nginx/sbin:$JAVA_HOME/bin:$NODE_HOME/bin:$PATH
  11. SEATA_HOME=/usr/local/seata
  12. case $1 in
  13. start)
  14. nohup sh $SEATA_HOME/bin/seata-server.sh -p 8091 -h 192.168.5.200 > seata.out 2>&1 &
  15. echo $! > $SEATA_HOME/bin/seata.pid
  16. echo "seata is started"
  17. ;;
  18. stop)
  19. pid=`cat $SEATA_HOME/bin/seata.pid`
  20. kill -9 $pid
  21. echo "seata is stopped"
  22. ;;
  23. restart)
  24. pid=`cat $SEATA_HOME/bin/seata.pid`
  25. kill -9 $pid
  26. echo "seata is stopped"
  27. sleep 1
  28. nohup sh $SEATA_HOME/bin/seata-server.sh -p 8091 -h 192.168.5.200 > seata.out 2>&1 &
  29. echo $! > $SEATA_HOME/bin/seata.pid
  30. echo "seata is started"
  31. ;;
  32. *)
  33. echo "start|stop|restart"
  34. ;;
  35. esac
  36. exit 0

使用service命令使用redis service seata start
增加服务 chkconfig --add seata
设置开机启动 chkconfig seata on
移除开机启动 chkconfig seata off
查看开机启动 chkconfig --list seata

14,nexus-3.29.0-02

构建Nexus私服 nexus-3.29.0-02 (详见nexus)
1 用户权限

  • 使用专用的操作系统用户帐户在给定主机上运行nexus。新建用户:nexus,密码:nexus
  • 足够的文件句柄限制:确保用户的打开文件描述符数量限制增加到65,536或更高(/etc/security/limits.conf)
  • root用户登录服务器创建nexus用户并授权 ```bash groupadd nexus useradd nexus -g nexus passwd nexus 提示输入密码:nexus 再次输入密码:nexus

mkdir -p /opt/nexus/
chown -R nexus:nexus /opt/nexus/
chmod 775 /opt/nexus/

  1. **2 安装**<br />`tar -zxvf nexus-3.29.0-02-unix.tar.gz ` <br />`mv nexus-3.29.0-02 /opt/nexus `<br />3,配置<br />修改nexus启动初始化内存(**不是必须的,视服务器配置决定,4C8G则不需要修改**)<br />`vim /opt/nexus/bin/nexus.vmoptions `(默认2700m
  2. ```css
  3. -Xms384m
  4. -Xmx384m
  5. -XX:MaxDirectMemorySize=384m
  6. -XX:+UnlockDiagnosticVMOptions
  7. -XX:+LogVMOutput
  8. -XX:LogFile=./sonatype-work/nexus3/log/jvm.log
  9. -XX:-OmitStackTraceInFastThrow
  10. -Djava.net.preferIPv4Stack=true
  11. -Dkaraf.home=.
  12. -Dkaraf.base=.
  13. -Dkaraf.etc=etc/karaf
  14. -Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
  15. -Dkaraf.data=./sonatype-work/nexus3
  16. -Dkaraf.log=./sonatype-work/nexus3/log
  17. -Djava.io.tmpdir=./sonatype-work/nexus3/tmp
  18. -Dkaraf.startLocalConsole=false

修改nexus端口(不是必须的,默认监听端口8083
vim /opt/nexus/etc/nexus-default.properties

  1. # Jetty section
  2. application-port=8803
  3. application-host=0.0.0.0
  4. nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
  5. nexus-context-path=/
  6. # Nexus section
  7. nexus-edition=nexus-pro-edition
  8. nexus-features=\
  9. nexus-pro-feature
  10. nexus.hazelcast.discovery.isEnabled=true

4 启动

  1. firewall-cmd --permanent --add-port=8803/tcp 开放8803端口
  2. firewall-cmd --permanent --remove-port=8803/tcp 移除8803端口
  3. firewall-cmd --reload 重新载入配置
  1. cd /opt/nexus/bin
  2. ./nexus start
  3. 或者
  4. ./nexus run &
  5. 启动成功的提示:Starting nexus
  6. ----------------------------------------------
  7. 如果是root用户启动,则会提示:
  8. WARNING: ************************************************************
  9. WARNING: Detected execution as "root" user. This is NOT recommended!
  10. WARNING: ************************************************************
  11. Starting nexus
  12. 说明已经安装启动成功,上面报错意思是nexus建议不要用root用户来启动nexus,但并不影响启动

检查nexus进程: ps -ef | grep nexus
5 测试
http://192.168.5.200:8803
admin
密码:**cat /opt/sonatype-work/nexus3/admin.password cat /opt/nexus/sonatype-work/nexus3/admin.password**
6 设置开机启动
创建启动脚本文件 nexus
vim /etc/init.d/nexus
复制粘贴以下内容:
服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是30,关闭的优先级是95。优先级范围是0-100,数字越大,优先级越低

  1. #!/bin/bash
  2. #chkconfig:2345 30 95
  3. #description:nexus
  4. #processname:nexus
  5. export JAVA_HOME=/usr/local/java/jdk/
  6. case $1 in
  7. start) su root /opt/nexus/bin/nexus start;;
  8. stop) su root /opt/nexus/bin/nexus stop;;
  9. status) su root /opt/nexus/bin/nexus status;;
  10. restart) su root /opt/nexus/bin/nexus restart;;
  11. dump) su root /opt/nexus/bin/nexus dump;;
  12. console) su root /opt/nexus/bin/nexus console;;
  13. *) echo "Usage: nexus {start|stop|run|run-redirect|status|restart|force-reload}"
  14. esac

设置脚本权限 chmod +x /etc/init.d/nexus
使用service命令启动 service nexus start
增加nexus服务 chkconfig --add nexus
移除服务 chkconfig --del nexus
设置开机启动 chkconfig nexus on
关闭开机启动 chkconfig --list nexus

15,getlab13.12.9

详见 https://www.yuque.com/zhang.qiang/gitlab/ge259r

16,jenkins-2.319.3-1.1

1 下载地址
官方镜像:https://get.jenkins.io/war-stable/
清华大学:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/
2去Jenkins官网下载Jenkins,Centos的话会下载到.rpm安装文件
jenkins-2.319.3-1.1.noarch.rpm
2 安装

  1. ## 安装 epel-releas
  2. yum -y install epel-release
  3. ## 安装 daemonize
  4. yum -y install daemonize
  5. ## 安装Jenkins
  6. rpm -ivh jenkins-2.319.3-1.1.noarch.rpm

报错:
warning: jenkins-2.319.3-1.1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 45f2c3d5: NOKEY
error: Failed dependencies:
daemonize is needed by jenkins-2.319.3-1.1.noarch
解决:
后面加上--force --nodeps 忽视依赖关系
rpm -ivh jenkins-2.319.3-1.1.noarch.rpm --force --nodeps
3 查看安装位置
rpm -qc jenkins

  1. [root@zhangqiang tars]# rpm -qc jenkins
  2. /etc/init.d/jenkins #配置文件 配置jdk安装路径
  3. /etc/logrotate.d/jenkins #默认的JENKINS_HOME目录
  4. /etc/sysconfig/jenkins
  5. #其余目录
  6. /usr/lib/jenkins/jenkins.war #WAR包
  7. /var/lib/jenkins/ #默认的JENKINS_HOME目录,改为/data/jenkins
  8. /var/log/jenkins/jenkins.log #Jenkins日志文件

4 修改配置文件
**mkdir -p /opt/jenkins **
配置端口 vim /etc/sysconfig/jenkins

  1. JENKINS_HOME="/opt/jenkins" #主目录
  2. JENKINS_USER="root" #默认用户
  3. JENKINS_PORT="8801" #端口

java安装地址 :which java
/usr/local/jdk/bin/java
配置jdk位置 vim /etc/init.d/jenkins

  1. candidates="
  2. /etc/alternatives/java
  3. /usr/lib/jvm/java-1.8.0/bin/java
  4. /usr/lib/jvm/jre-1.8.0/bin/java
  5. /usr/lib/jvm/java-11.0/bin/java
  6. /usr/lib/jvm/jre-11.0/bin/java
  7. /usr/lib/jvm/java-11-openjdk-amd64
  8. /usr/bin/java
  9. /usr/local/java/jdk/bin/java #jdk配置

5 常用命令
重新加载配置文件 systemctl daemon-reload
启动命令为 service jenkins start
启动 systemctl start jenkins
开机启动 systemctl enable jenkins
使配置生效 source /etc/profile

使用service命令使用redis service jenkins start
增加服务 chkconfig --add jenkins
设置开机启动 chkconfig jenkins on
移除开机启动 chkconfig jenkins off
查看开机启动 chkconfig --list jenkins

  1. firewall-cmd --permanent --add-port=8801/tcp 开放8801端口
  2. firewall-cmd --permanent --remove-port=8801/tcp 移除8801端口
  3. firewall-cmd --reload 重新载入配置

6 测试
http://192.168.5.116:8801/
cat /var/lib/jenkins/secrets/initialAdminPassword
cat /opt/jenkins/secrets/initialAdminPassword
注意:配置国内的镜像 官方下载插件慢 更新下载地址
cd {你的Jenkins工作目录}/updates #进入更新配置位置
cd /root/.jenkins/updates/

  1. sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

这是直接修改的配置文件,如果前边Jenkins用sudo启动的话,那么这里的两个sed前均需要加上sudo
重启Jenkins,安装插件,选择安装推荐的插件
关闭防火墙

  1. 查看防火墙规则 firewall-cmd --list-all
  2. 防火墙服务状态 systemctl status firewalld.service
  3. 防火墙状态 firewall-cmd --state
  4. 开启防火墙 systemctl start firewalld.service
  5. 重启防火墙 systemctl restart firewalld.service
  6. 关闭防火墙 systemctl stop firewald.service
  7. 永久关闭防火墙 systemctl disable firewalld
  8. 永久关闭防火墙 systemctl disable firewalld.service
  9. 永久开启防火墙 systemctl enable firewalld.service
  10. 开放80端口 firewall-cmd --permanent --add-port=80/tcp
  11. 移除80端口 firewall-cmd --permanent --remove-port=80/tcp
  12. 重启防火墙 systemctl restart firewalld.service
  13. 重新载入配置 firewall-cmd --reload

7 插件
Locale 汉化
Role-based Authorization Strategy 权限插件
Deploy to container —支持自动化代码部署到tomcat容器
GIT plugin 将Git与 Jenkins集成在一起。可能已经安装,可在已安装列表中查询出来
Maven Integration 利用Maven编译,打包所需插件
Publish Over SSH 通过ssh连接ssh 插件
ThinBackup 备份插件
SSH plugin 使用 SSH 协议远程执行 shell 命令
Discard old builds 丢弃旧的构建

8 卸载

  1. #卸载
  2. rpm -e jenkins
  3. #检查是否卸载成功
  4. rpm -ql jenkins
  5. #彻底删除残留文件
  6. find / -iname jenkins | xargs -n 1000 rm -rf

17,zentao15.5

Centos7.4系统下安装httpd,mysql5.7,php7.2环境运行禅道
https://www.zentao.net/book/zentaopmshelp/40.html
一、运行环境说明
运行环境为 Apache + PHP(7.0/7.1/7.2版本) + MySQL(5.5/5.6/5.7版本)/mariadb 组合 ,Nginx 其次。
PHP需要使用 pdo, pdo_mysql, json, filter, openssl, mbstring, zlib, curl, gd, iconv 模块,需要确保 PHP 运行环境有加载上述模块。
二、安装并开启 Apache 服务

  1. yum -y install httpd #安装Apache服务
  2. systemctl start httpd.service #开启Apache服务
  3. systemctl stop httpd.service #关闭Apache服务
  4. systemctl restart httpd.service #重启Apache服务
  5. systemctl enable httpd.service #Apache服务开机启动
  6. systemctl status httpd.service #查看Apache服务状态

关闭防火墙( 或者自行百度相关指令开启服务器的 80 端口 ),以便排除因为网络问题 , 无法访问 Apache 服务

  1. systemctl stop firewalld.service # 关闭防火墙
  2. systemctl disable firewalld.service # 禁止firewall开机启动
  3. systemctl status firewalld.service # 查看防火墙状态
  4. systemctl start firewalld.service # 开启防火墙

关闭 SELINUX,未关闭时可能有无法授予 /var 路径下文件的读写权限问题,关闭命令如下:
setenforce 0 # 临时关闭SELINUX, 重启服务器失效
编辑 **/etc/selinux/config **文件,将 SELINUX 的值设置为 disabled , 下次开机 SELINUX 就不会启动了
vim /etc/selinux/config # 修改文件中的 SELINUX=disabled
错误:Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:8888

  1. //安装semanage
  2. yum provides /usr/sbin/semanage
  3. yum -y install policycoreutils-python
  4. //查看默认允许的端口
  5. semanage port -l | grep -w http_port_t
  6. // http_port_t  tcp  80, 81, 443, 488, 8008, 8009, 8443, 9000
  7. //使用semanage添加apache侦听的端口
  8. semanage port -a -t http_port_t -p tcp 8888
  9. //启动apache
  10. systemctl start httpd

apache 会被安装到:/etc/httpd/
apache 配置文件地址: /etc/httpd/conf/httpd.conf
apache 网站文件默认访问路径:/var/www/html/
三、安装PHP7.2版本
PHP7.2 版本需要配置 yum 源 :

  1. rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
  2. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum 安装 PHP7.2 所需组件 :

  1. yum -y install php72w php72w-pdo php72w-mysql php72w-mbstring php72w-ldap php72w-gd php72w-json php72w-xml php72w-zip

四、安装mysql5数据库
详见mysql5.7.33安装
五、安装禅道软件
1. 下载新版禅道软件 源码包, 下载地址: http://www.zentao.net/download.html
2. 上传至服务器的 /opt/zentaopms 目录
3. 使用 unzip 命令解压禅道源码包程序。

  1. yum -y install unzip # 安装unzip解压
  2. unzip ZenTaoPMS.*.zip -d /opt # 解压禅道源码包

image.png
4. 修改 Apache 访问路径:
vim /etc/httpd/conf/httpd.conf

  1. #Listen 12.34.56.78:80
  2. Listen 8804
  3. DocumentRoot "/opt/zentaopms/www/"
  4. <Directory "/opt/zentaopms/www/">
  5. AllowOverride All

一,服务器篇 - 图10
启动 Apache 服务 systemctl restart httpd
浏览器访问 http://192.168.5.200:8804 地址,安装禅道即可。
错误: PDO_MySQL扩展未加载
yum install -y mariadb-libs
数据库配置文件 /var/www/html/zentaopms/config/my.php

卸载我的httpd,首先要停止httpd服务,命令如下:
systemctl stop httpd
用yum -erase命令卸载,命令如下:
yum erase httpd.x86_64

ApachHttp加固

  1. ##设置连接超时时间
  2. Timeout 10
  3. ##确保限制对apache目录和文件的其他写访问文件权限
  4. ##执行以下操作删除$ APACHE_PREFIX($ APACHE_PREFIX是apache的安装目录默认例/usr/local/apache2或/var/www/html如自定义请自行查找)目录上的其他写访问权限:
  5. ##chmod -R o-w $ APACHE_PREFIX
  6. ## chmod -R o-w /opt/zentaopms/www
  7. ## chmod -R o-w /var/www/html
  8. ##确保禁用http跟踪方法服务配置 TRACE方法不需要,并且很容易受到滥用,因此应该将其禁用
  9. ##配置文件路径:/etc/httpd/conf/httpd.conf
  10. ##加固建议
  11. ##1.vim path(path为主配置文件的绝对路径,如果您的主配置文件中包含include <path>,则<path>为您的子配置文件路径) 2.找到选项TraceEnable将其值设置为off 如没有请增加
  12. TraceEnable off
  13. ##隐藏 Apache 的版本号及其它敏感信息确保未启用服务器签名不存在或者off个人信息保护
  14. ##服务器签名在服务器充当代理时很有用,因为它们有助于用户将错误与代理而非目标服务器区分开。 但是,在这个在上下文中,显得很鸡肋,而且存在被识别的可能
  15. ##配置文件路径::/etc/httpd/conf/httpd.conf
  16. ##1.使用vim编辑器对配置文件进行编辑 vim pathpath为主配置文件的绝对路径,如果您的主配置文件中包含include <path>,则<path>为您的子配置文件路径)
  17. ##2.找到ServerSignature将其设置为ServerSignature Off 如没有,请增加
  18. ServerSignature Off
  19. ServerTokens Prod
  20. ## 确保Web根目录的选项受到限制 禁止 Apache 列表显示文件数据保密性
  21. <Directory "/opt/zentaopms/www/">
  22. Options None
  23. Require all granted
  24. AllowOverride All
  25. </Directory>

18,xiaoyaoji

1 下载地址
http://git.oschina.net/zhoujingjie/apiManager/releases
2 安装
安装Tomcat9
将xiaoyaoji-2.1.7.1.tar.gz 解压,将xiaoyaoji.war放到Tomcat/webapps目录下

  1. tar -zxvf xiaoyaoji-2.1.7.1.tar.gz
  2. mv xiaoyaoji.war /usr/local/tomcat/webapps/

修改端口 vim /usr/local/tomcat/conf/server.xml
<Connector port="8805" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
初始化数据库
新建数据库 xiaoyaoji 将 xiaoyaoji.war 解压后中 xiaoyaoji.sql表导入