ASP.NET CORE

2.2

  1. sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
  1. # 可以不执行 update
  2. sudo yum update
  1. sudo yum install dotnet-sdk-2.2

更高版本
https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-centos

备注

项目用到Image类时,需要安装相关依赖

  1. yum install libgdiplus-devel

使用指定端口启动程序

  1. dotnet XXX.dll --urls http://*.5005

参考

https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install


Supervisor

  1. yum install epel-release
  2. yum install -y supervisor
  3. systemctl enable supervisord # 开机自启动
  4. systemctl start supervisord # 启动supervisord服务
  5. systemctl status supervisord # 查看supervisord服务状态
  6. ps -ef|grep supervisord # 查看是否存在supervisord进程

常用命令

  1. supervisorctl status # 查看程序状态
  2. supervisorctl stop program_name # 关闭 指定的程序
  3. supervisorctl start program_name # 启动 指定的程序
  4. supervisorctl restart program_name # 重启 指定的程序
  5. supervisorctl tail -f program_name # 查看 该程序的日志
  6. supervisorctl update # 重启配置文件修改过的程序(修改了配置,通过这个命令加载新的配置)

Redis

  1. cd /usr/local
  2. wget http://download.redis.io/releases/redis-5.0.5.tar.gz
  3. tar xzf redis-5.0.5.tar.gz
  4. cd redis-5.0.5
  5. yum install gcc -y
  6. make
  7. cd /usr/local/redis-5.0.5/utils && ./install_server.sh

当出现:Please select the redis executable path [] 时,输入:

  1. /usr/local/redis-5.0.5/src/redis-server

提示:wget不存在时

  1. yum -y install wget

配置文件*.conf 在 /etc/redis 中,主要修改绑定IP
xxx.xxx.xx.xx 可以是当前内网IP或外网IP。修改成外网IP时有严重安全隐患。

  1. bind 127.0.0.1 xxx.xxx.xx.xx

参考

集群搭建
https://www.cnblogs.com/aquester/p/10916284.html
http://blog.51yip.com/nosql/1726.html


Sql Server

  1. sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
  2. sudo yum install -y mssql-server
  3. sudo /opt/mssql/bin/mssql-conf setup
  4. # 选择 2 Developer 数据库没有无限制,但是不可商用
  5. systemctl status mssql-server

如需要外网访问,则使用以下命令操作防火墙开放1433端口

  1. sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
  2. sudo firewall-cmd --reload

如需要安装sqlcmd工具,执行以下命令

  1. sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
  2. sudo yum install -y mssql-tools unixODBC-devel
  3. echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
  4. echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
  5. source ~/.bashrc

sqlcmd连接到数据库的方法(根据提示再输入密码)

  1. sqlcmd -S <服务器IP> -U <数据库账号>

参考

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-2017


MariaDB

安装

  1. yum install mariadb-server

开机启动

  1. systemctl start mariadb # 开启服务
  2. systemctl enable mariadb # 设置为开机自启动服务

配置

  1. mysql_secure_installation

配置时出现的各个选项

Enter current password for root (enter for none):

输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车

Set root password? [Y/n] # 设置密码,y New password: # 新密码 Re-enter new password: # 再次输入密码 Remove anonymous users? [Y/n] # 移除匿名用户, y Disallow root login remotely? [Y/n] # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录 Remove test database and access to it? [Y/n] # 删除test数据库,y:删除。n:不删除,数据库中会有一个test数据库,一般不需要 y Reload privilege tables now? [Y/n] # 重新加载权限表,y。或者重启服务也许

测试是否能够登录成功,出现 MariaDB [(none)]> 就表示已经能够正常登录使用MariaDB数据库了

  1. mysql -u root -p

Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>

设置MariaDB字符集为utf-8

在 [mysqld] 标签下添加

init_connect=’SET collation_connection = utf8_unicode_ci’ init_connect=’SET NAMES utf8’ character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake

/etc/my.cnf.d/client.cnf 文件
在 [client] 标签下添加

default-character-set=utf8

/etc/my.cnf.d/mysql-clients.cnf 文件
在 [mysql] 标签下添加

default-character-set=utf8

重启服务

  1. systemctl restart mariadb

配置前

MariaDB [(none)]> show variables like “%character%”;show variables like “%collation%”; +—————————————+——————————————+ | Variable_name | Value | +—————————————+——————————————+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +—————————————+——————————————+ 8 rows in set (0.01 sec)

+———————————+—————————-+ | Variable_name | Value | +———————————+—————————-+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +———————————+—————————-+ 3 rows in set (0.00 sec)

MariaDB [(none)]>

配置后

MariaDB [(none)]> show variables like “%character%”;show variables like “%collation%”; +—————————————+——————————————+ | Variable_name | Value | +—————————————+——————————————+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +—————————————+——————————————+ 8 rows in set (0.00 sec)

+———————————+————————-+ | Variable_name | Value | +———————————+————————-+ | collation_connection | utf8_unicode_ci | | collation_database | utf8_unicode_ci | | collation_server | utf8_unicode_ci | +———————————+————————-+ 3 rows in set (0.00 sec)

MariaDB [(none)]>


NodeJs

  1. curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
  2. yum install -y nodejs
  3. # 验证是否安装成功
  4. node -v

Nginx

  1. sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
  2. sudo yum install -y nginx
  3. sudo systemctl start nginx.service
  4. sudo systemctl enable nginx.service

具体安装的版本详见:http://nginx.org/packages/centos/

Tengine(淘宝版nginx)

常规使用nginx足矣。有其他细致的需求则可以了解下Tengine

  1. yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y

官网:http://tengine.taobao.org/download.html

  1. cd /usr/local/
  2. wget http://tengine.taobao.org/download/tengine-2.3.3.tar.gz
  3. tar -zxvf tengine-2.3.3.tar.gz
  4. cd tengine-2.3.3
  5. ./configure --prefix=/opt/tngx/
  6. make && make install

配置Tengine的环境变量

  1. vim /etc/profile

增加Path

PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/tngx/sbin”

使配置生效

  1. source /etc/profile

常用配置

禁止未配置的域名访问

  1. server {
  2. server_name _;
  3. listen 80 default_server;
  4. listen 443 ssl default_server;
  5. ## To also support IPv6, uncomment this block
  6. # listen [::]:80 default_server;
  7. # listen [::]:443 ssl default_server;
  8. ssl_certificate <path to cert>;
  9. ssl_certificate_key <path to key>;
  10. return 404; # or whatever
  11. }

HTTP

  1. upstream name {
  2. server localhost:8080;
  3. }
  4. server {
  5. listen 80;
  6. server_name www.xxx.com;
  7. location / {
  8. proxy_pass http://name;
  9. proxy_redirect off;
  10. proxy_set_header Host $host;
  11. proxy_set_header X-Real-IP $remote_addr;
  12. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  13. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
  14. proxy_max_temp_file_size 0;
  15. proxy_connect_timeout 90;
  16. proxy_send_timeout 90;
  17. proxy_read_timeout 90;
  18. proxy_buffer_size 4k;
  19. proxy_buffers 4 32k;
  20. proxy_busy_buffers_size 64k;
  21. proxy_temp_file_write_size 64k;
  22. }
  23. }

HTTPS && 强制HTTPS

  1. upstream name {
  2. server localhost:8080;
  3. }
  4. server {
  5. listen 80;
  6. listen 443 ssl http2;
  7. server_name www.xxx.com;
  8. ssl_certificate /etc/nginx/ssl/www.xxx.com.cer;
  9. ssl_certificate_key /etc/nginx/ssl/www.xxx.com.key;
  10. ssl_session_timeout 5m;
  11. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  12. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
  13. ssl_prefer_server_ciphers on;
  14. location / {
  15. proxy_pass http://name;
  16. if ($scheme = http ) {
  17. return 301 https://$host$request_uri;
  18. }
  19. #Proxy Settings
  20. proxy_redirect off;
  21. proxy_set_header Host $host;
  22. proxy_set_header X-Real-IP $remote_addr;
  23. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  24. proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
  25. proxy_max_temp_file_size 0;
  26. proxy_connect_timeout 90;
  27. proxy_send_timeout 90;
  28. proxy_read_timeout 90;
  29. proxy_buffer_size 4k;
  30. proxy_buffers 4 32k;
  31. proxy_busy_buffers_size 64k;
  32. proxy_temp_file_write_size 64k;
  33. }
  34. }

参考

http://nginx.org/en/docs/http/configuring_https_servers.html


RabbitMQ

  1. curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
  2. yum -y install erlang
  3. curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
  4. yum -y install rabbitmq-server

配置

  1. # 启动服务
  2. service rabbitmq-server start
  3. # 启动web管理界面
  4. rabbitmq-plugins enable rabbitmq_management
  5. # 如果提示找不到,使用查看插件名称
  6. rabbitmq-plugins list
  7. # 增加访问用户,默认用户guest只能本地访问。
  8. rabbitmqctl add_user admin <填写密码>
  9. # 设置角色:
  10. rabbitmqctl set_user_tags admin administrator

后台默认地址

http://localhost:15672

参考

https://www.rabbitmq.com/install-rpm.html


Python3

centos默认安装了python2,占用python命令,本方式以兼容方式安装python3,相关的操作命令也变成了python3和pip3

  1. yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
  2. yum install libffi-devel -y
  3. yum install openssl-devel -y
  4. cd /usr/local/
  5. # 将下面的3.7.0 替换成自己需要的版本
  6. wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
  7. tar -zxvf Python-3.7.0.tgz
  8. cd Python-3.7.0
  9. ./configure prefix=/usr/local/python3 --with-ssl
  10. make && make install
  11. # 添加python3的软连接
  12. ln -s /usr/local/python3/bin/python3 /usr/bin/python3
  13. # 测试
  14. python3 --version
  15. # 添加pip3的软连接
  16. ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  17. # 测试
  18. pip3 --version

修改pip源为阿里云

创建pip.conf文件

  1. touch ~/.pip/pip.conf

填入:

  1. [global]
  2. index-url = http://mirrors.aliyun.com/pypi/simple/
  3. [install]
  4. trusted-host = mirrors.aliyun.com

参考

https://blog.csdn.net/sinat_21591675/article/details/82770360


SSL证书自动申请/续签

  1. curl https://get.acme.sh | sh
  2. alias acme.sh=~/.acme.sh/acme.sh

配置nginx,并且解析域名到IP上,让域名可以访问

  1. acme.sh --issue -d www.abc.com --nginx
  2. acme.sh --installcert -d www.abc.com --key-file /etc/nginx/ssl/www.abc.com.key --fullchainpath /etc/nginx/ssl/www.abc.com.cer --reloadcmd "service nginx force-reload"

测试

https://www.ssllabs.com/ssltest/analyze.html

参考

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E