ASP.NET CORE
2.2
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
# 可以不执行 update
sudo yum update
sudo yum install dotnet-sdk-2.2
更高版本
https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-centos
备注
项目用到Image类时,需要安装相关依赖
yum install libgdiplus-devel
使用指定端口启动程序
dotnet XXX.dll --urls http://*.5005
参考
https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install
Supervisor
yum install epel-release
yum install -y supervisor
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
systemctl status supervisord # 查看supervisord服务状态
ps -ef|grep supervisord # 查看是否存在supervisord进程
常用命令
supervisorctl status # 查看程序状态
supervisorctl stop program_name # 关闭 指定的程序
supervisorctl start program_name # 启动 指定的程序
supervisorctl restart program_name # 重启 指定的程序
supervisorctl tail -f program_name # 查看 该程序的日志
supervisorctl update # 重启配置文件修改过的程序(修改了配置,通过这个命令加载新的配置)
Redis
cd /usr/local
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xzf redis-5.0.5.tar.gz
cd redis-5.0.5
yum install gcc -y
make
cd /usr/local/redis-5.0.5/utils && ./install_server.sh
当出现:Please select the redis executable path [] 时,输入:
/usr/local/redis-5.0.5/src/redis-server
提示:wget不存在时
yum -y install wget
配置文件*.conf 在 /etc/redis 中,主要修改绑定IP
xxx.xxx.xx.xx 可以是当前内网IP或外网IP。修改成外网IP时有严重安全隐患。
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
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
sudo yum install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup
# 选择 2 Developer 数据库没有无限制,但是不可商用
systemctl status mssql-server
如需要外网访问,则使用以下命令操作防火墙开放1433端口
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
如需要安装sqlcmd工具,执行以下命令
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
sudo yum install -y mssql-tools unixODBC-devel
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sqlcmd连接到数据库的方法(根据提示再输入密码)
sqlcmd -S <服务器IP> -U <数据库账号>
参考
https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-2017
MariaDB
安装
yum install mariadb-server
开机启动
systemctl start mariadb # 开启服务
systemctl enable mariadb # 设置为开机自启动服务
配置
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数据库了
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
重启服务
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
curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs
# 验证是否安装成功
node -v
Nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
具体安装的版本详见:http://nginx.org/packages/centos/
Tengine(淘宝版nginx)
常规使用nginx足矣。有其他细致的需求则可以了解下Tengine
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
cd /usr/local/
wget http://tengine.taobao.org/download/tengine-2.3.3.tar.gz
tar -zxvf tengine-2.3.3.tar.gz
cd tengine-2.3.3
./configure --prefix=/opt/tngx/
make && make install
配置Tengine的环境变量
vim /etc/profile
增加Path
PATH=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/opt/tngx/sbin”
使配置生效
source /etc/profile
常用配置
禁止未配置的域名访问
server {
server_name _;
listen 80 default_server;
listen 443 ssl default_server;
## To also support IPv6, uncomment this block
# listen [::]:80 default_server;
# listen [::]:443 ssl default_server;
ssl_certificate <path to cert>;
ssl_certificate_key <path to key>;
return 404; # or whatever
}
HTTP
upstream name {
server localhost:8080;
}
server {
listen 80;
server_name www.xxx.com;
location / {
proxy_pass http://name;
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;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
HTTPS && 强制HTTPS
upstream name {
server localhost:8080;
}
server {
listen 80;
listen 443 ssl http2;
server_name www.xxx.com;
ssl_certificate /etc/nginx/ssl/www.xxx.com.cer;
ssl_certificate_key /etc/nginx/ssl/www.xxx.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://name;
if ($scheme = http ) {
return 301 https://$host$request_uri;
}
#Proxy Settings
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;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
参考
http://nginx.org/en/docs/http/configuring_https_servers.html
RabbitMQ
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash
yum -y install erlang
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash
yum -y install rabbitmq-server
配置
# 启动服务
service rabbitmq-server start
# 启动web管理界面
rabbitmq-plugins enable rabbitmq_management
# 如果提示找不到,使用查看插件名称
rabbitmq-plugins list
# 增加访问用户,默认用户guest只能本地访问。
rabbitmqctl add_user admin <填写密码>
# 设置角色:
rabbitmqctl set_user_tags admin administrator
后台默认地址
参考
https://www.rabbitmq.com/install-rpm.html
Python3
centos默认安装了python2,占用python命令,本方式以兼容方式安装python3,相关的操作命令也变成了python3和pip3
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
yum install libffi-devel -y
yum install openssl-devel -y
cd /usr/local/
# 将下面的3.7.0 替换成自己需要的版本
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz
cd Python-3.7.0
./configure prefix=/usr/local/python3 --with-ssl
make && make install
# 添加python3的软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
# 测试
python3 --version
# 添加pip3的软连接
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# 测试
pip3 --version
修改pip源为阿里云
创建pip.conf文件
touch ~/.pip/pip.conf
填入:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
参考
https://blog.csdn.net/sinat_21591675/article/details/82770360
SSL证书自动申请/续签
curl https://get.acme.sh | sh
alias acme.sh=~/.acme.sh/acme.sh
配置nginx,并且解析域名到IP上,让域名可以访问
acme.sh --issue -d www.abc.com --nginx
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