************************* Core 2.0.2 *******************************
//1、安装dotnet环境
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod \nbaseurl= https://packages.microsoft.com/yumrepos/microsoft-rhel7.3-prod\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/dotnetdev.repo'
//2、安装.NET SDK
sudo yum update
sudo yum install libunwind libicu
sudo yum install dotnet-sdk-2.0.2
//3、验证dotnet环境
dotnet --info
****************************** MySQL *****************************
//1、下载MySQL
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server
//2、重启MySQL服务 systemctl start mysqld.service
systemctl restart mysqld.service
//3、设置开机启动
systemctl enable mysqld
systemctl daemon-reload
//4、修改root本地登录密码
//mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。
//在这里A temporary password is generated for root@localhost:
//5、MySQL需要输入刚才的临时默认密码
mysql -u root -p
//6、修改默认登陆密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '自定义特殊密码';
//7、MySQL设置远程登陆
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '自定义特殊密码' WITH GRANT OPTION;
//8、启用防火墙
systemctl start firewalld.service
//9、设置防火墙允许3306端口访问
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//10、重启防火墙
firewall-cmd --reload
//11、修改默认编码配置 在[mysqld]下面直接添加
vim /etc/my.cnf
character_set_server=utf8
init_connect='SET NAMES utf8'
//12、重启mysql服务
systemctl restart mysqld.service
//13、创建MySQL用户(用户名,密码,权限)
CREATE USER 'admin'@'%' IDENTIFIED BY '自己的密码';
GRANT GRANT OPTION ON *.* TO 'admin'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON *.* TO 'admin'@'%';
***************************** 防火墙配置 *********************************
//1、将接口添加到区域,默认接口都在public
firewall-cmd --zone=public --add-interface=eth0 --permanent
//2、设置默认接口区域
# firewall-cmd --set-default-zone=public --permanent
//3、将端口添加到区域
firewall-cmd --zone=public --add-port=5000/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
************************* Nginx ***************************************
//1、下载
curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx.rpm
yum install nginx
//2、启动nginx服务
systemctl start nginx
//3、开机启动nginx
systemctl enable nginx.service
//4、配置nginx
vim /etc/nginx/conf.d/default.conf
//修改以下内容
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
//5、保存完执行nginx重新加载
nginx -s reload
//6、如遇到报错:nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory),执行下面的
systemctl start nginx
nginx -s reload
//以下东西没有遇到,如果遇到可以执行
yum install policycoreutils-python
sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp
****************** 配置守护服务(Supervisor) ******************
//1、安装守护服务
yum install python-setuptools
easy_install supervisor
//2、配置
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
//3、修改supervisord.conf
vim /etc/supervisor/supervisord.conf
(将文件末尾的)
;[include]
;files = relative/directory/*.ini
改为
[include]
files = conf.d/*.conf
mkdir conf.d
cd conf.d
//4、新建守护文件(切记空格)
[program:myCore1]
command=dotnet first.dll ;
//运行程序的命令
directory=/mycore/first/ ;
//命令执行的目录
autorestart=true ;
//程序意外退出是否自动重启
stderr_logfile=/var/log/myCore1.err.log ;
//错误日志文件
stdout_logfile=/var/log/myCore1.out.log ;
输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ;
//进程环境变量
user=root ;
进程执行的用户身份
stopsignal=INT
最后执行:wq myCore1.conf
//5、运行supervisord,查看是否生效
supervisord -c /etc/supervisor/supervisord.conf
(如果报以下错误)
Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
//解决方法:(如果在失败,参见:https://segmentfault.com/a/1190000003955182)
sudo unlink /tmp/supervisor.sock
//6、查看是否启动成功
ps -ef
//7、配置Supervisor开机启动服务
vim /usr/lib/systemd/system/supervisord.service
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
//8、开机启动
systemctl enable supervisord
//验证是否设置开机启动成功
systemctl is-enabled supervisord