CentOS 7 安装 shadowsocks libev 客户端

installation

download yum repo on Fedora Copr and put it inside /etc/yum.repos.d/. The release Epel is for RHEL and its derivatives.

Then, install shadowsocks-libev via dnf:

su -c 'dnf update'
su -c 'dnf install shadowsocks-libev'

config

shadowsocks-libev 默认读取位于 /etc/shadowsocks-libev/config.json 的配置文件,我们可以根据需要参考以下配置文件进行修改:

{
    "server": "example.zzz.buzz",
    "server_port": 10443,
    "local_port": 1080,
    "password": "zzz.buzz",
    "method": "aes-256-cfb",
    "mode": "tcp_and_udp",
    "timeout": 600
}

"server": 必填,填入要连接的 shadowsocks 服务器域名或 IP。

"server_port": 必填,填入服务器上 shadowsocks 所监听的端口。

"local_port": 必填,填入本地 shadowsocks 客户端 SOCKS5 代理要监听的端口。

"password": 必填,密码,需与 shadowsocks 服务器端配置一致。

"method": 必填,加密方法,需与 shadowsocks 服务器端配置一致。

"mode": 选填,默认 "tcp_only"。

shadowsocks 所要监听的协议,可填 "tcp_only", "udp_only" 和 "tcp_and_udp"。
填入 "tcp_and_udp" 相当于命令行上提供 -u 参数;填入 "udp_only" 相当于命令行上提供 -U 参数。

"timeout": 选填,不活动连接的保持时间。

默认 60 秒,设置较长时间有助于保持 HTTP 长连接等。设置时间过长则会导致不必要地占用过多 shadowsocks 服务器资源。

对于配置客户端,完成以上几项配置就足够了。

如果想要变更默认的配置文件,或者提供其他命令行参数,我们可以修改 /etc/sysconfig/shadowsocks-libev:

# Configuration file
CONFFILE="/etc/shadowsocks-libev/config.json"

# Extra command line arguments
DAEMON_ARGS="-u"

其中 CONFFILE 指定了 shadowsocks-libev 所读取的配置文件;DAEMON_ARGS 则指定了额外的命令行参数,此处的 "-u" 表示启用 UDP 协议。

需要注意的是,命令行参数 DAEMON_ARGS 比配置文件 CONFFILE 中指定的选项优先级要更高一些。

start

systemctl enable --now shadowsocks-libev-local

wordpress更新时弹出ftp登录

原因

因为更新本身就是对本地文件的更新覆盖,而wordpress的更新程序无法完成本地文件更新所以就会出现ftp的方式提示,所以就是文件的更新权限问题。

权限检查

因为是wordpress的php部分的逻辑负责更新,所以就是查看这部分php的运行用户权限。如果我们的php是运行在fpm模式,这个我们可以用:

ps aux |grep  php-fpm

这条指令来查看,输出第一列就是当前归属的用户组信息。然后我们对当前的wordpress根目录或者主题插件的目录进行用户权限修改:

 chown -R xxx:xxx /DDD

xxx为用户和组,DDD为需要更新权限的目录,-R表示递归所有子目录。

mysql错误日志

mysql的默认错误日志为:hostname.err
完整路径:/usr/local/mysql/var/xxxxxx.err

如果我们要重新设置日志的路径,在[mysqld] 中輸入

#log  
log-error=/usr/local/mysql/log/error.log  
log=/usr/local/mysql/log/mysql.log  
long_query_time=2  
log-slow-queries= /usr/local/mysql/log/slowquery.log 

需要注意的是这里文件和路径需要mysql用户可访问,所以需要通过chown将log设置为mysql用户:

chown -R mysql:mysql log

apt-get update -qqy命令参数说明

第一次看到-qq参数,觉得比较新奇,特意确认了下:

-q, --quiet

Quiet. Produces output suitable for logging, omitting progress indicators. More q's will produce more quiet up to a maximum of two. You can also use -q=# to set the quiet level, overriding the configuration file. Note that quiet level 2 implies -y, you should never use -qq without a no-action modifier such as -d, --print-uris or -s as APT may decided to do something you did not expect.

所以按照说明,-qq一般是搭配y选项的。
这个参数经常在docker的静默安装指令中使用。

参考:
https://linux.die.net/man/8/apt-get

nrf52832 memory layout

协议栈

版本:nRF5_SDK_15.3.0_59ac345

#define SD_FLASH_SIZE 0x26000

app:
0x26000-0x77000

bootloader
0x77000-0x7e000

MBR params
0x7e000-7f000

bootloader setting:
7f000-80000

ref:
https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sr3nrf52.firmware/memory_configuration.html

Dockerfile中RUN CMD ENTRYPOINT命令区别

简单总结如下:
1. run用于docker的构建,可以理解为构建docker本身的单次的程序安装,只是为了生成docker image的,在docker build阶段执行。
2. entrypoint 理解为docker run时的shell指令,一般实现需要每次开机动态更新的设置或者文件操作等
3. cmd只能支持一条,代表entrypoint额外的默认运行参数,当在外层通过 docker run传递参数时,cmd的参数可以被覆盖。

参考:
1. https://www.cnblogs.com/klvchen/p/9238410.html
2. https://www.jianshu.com/p/f0a0f6a43907

基于ubuntu的LAMP dockerfile示例

简单的dockerfile例子

这里先给一个简单的例子,用来说明基本的dockerfile的组成:

# Barebones Apache installation on Ubuntu

FROM ubuntu

MAINTAINER DockerFan version 1.0

ENV DEBIAN_FRONTEND noninteractive

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

RUN apt-get update && apt-get install -y apache2

EXPOSE 8080

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

解释

Here’s what the instructions do:

  • FROM is always your first instruction, because it names the base image you’re building your new image from.

  • MAINTAINER is the creator of the Dockerfile.

  • ENV sets environment variables, in the form ENV [key] [value]. This assigns a single value to the key, as in our example Dockerfile. The value can be any string, including spaces and punctuation, so you can configure values like IP addresses, URLs, and passphrases. Note that when you set DEBIAN_FRONTEND noninteractive (for an unattended installation) in your Dockerfile there is no equals sign, as there is when you script a standard Debian or Ubuntu installation with export DEBIAN_FRONTEND=noninteractive.

  • There are multiple instructions for setting environment variables: ADD, COPY, ENV, EXPOSE, LABEL, USER, WORKDIR, VOLUME, STOPSIGNAL, and ONBUILD.

  • RUN executes commands. The example above, RUN apt-get update && apt-get install -y apache2, demonstrates two important steps. It is a good practice to use apt-get update && apt-get install foo together to ensure that an updated packaged will be installed. Docker makes generous use of caching, so this prevents a cached packaged from being installed. If you’re sure your cached packages are fresh enough then it’s not necessary, and will save you some download time. apt-get install -y must be used together with ENV DEBIAN_FRONTEND noninteractive; it means answer Yes to all prompts and run non-interactively.

  • EXPOSE defines which ports you want open at runtime, in a space-delimited list.

  • CMD can be used only once in your Dockerfile. If you have more than one, only the last one will run. The preferred syntax is CMD [“executable”,”param1″,”param2″]. The parameters are optional and comma-separated if you have more than one.

完整的LAMP dockerfile

# Ubuntu LAMP stack with Apache, MariaDB, PHP, and SSL

FROM ubuntu

MAINTAINER DockerFan version 1.0

ENV DEBIAN_FRONTEND noninteractive

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

# Install Apache, SSL, PHP, and some PHP modules

RUN apt-get update && apt-get install -y apache2 
 openssl 
 php5 
 php5-cli 
 php5-apcu

# Install MariaDB and set default root password

RUN echo 'mariadb-server mariadb-server/root_password  password mypassword' | debconf-set-selections
RUN echo 'mariadb-server mariadb-server/root_password_again password mypassword' | debconf-set-selections
RUN apt-get install mariadb-server -y

# Disable the default Apache site config
# Install your site's Apache configuration and activate SSL

ADD my_apache.conf /etc/apache2/sites-available/
RUN a2dissite 000-default
RUN a2ensite my_apache
RUN a2enmod ssl

# Remove APT files
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

EXPOSE 443 8080

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

The section that installs Apache, SSL, and PHP shows the proper Docker way to install multiple packages at once, with each package on its own line ending in a backslash. The MariaDB installation sections shows how to use debconf to automatically set the root DB password.

You will need your own Apache virtual host configuration file, and it should be in the same directory as your Dockerfile. Use the ADD instruction to build it into your image. I like to do a little housecleaning to keep my image as small as possible by running apt-get clean, and removing temp files.

Since we are using SSL, we’ll need port 443 available. On a production system, you would probably want only port 443 enabled, and use mod_rewrite to automatically redirect HTTP requests to HTTPS.

DEBIAN_FRONTEND选项

ENV DEBIAN_FRONTEND noninteractive
在基于ubuntu的dockerfile中我们经常看到如上的配置,那么,DEBIAN_FRONTEND到底是什么东西呢?

因为ubuntu是基于apt工具包进行软件安装的,而apt工具包是基于DebianPackageManagement的。而DEBIAN_FRONTEND就是DebianPackageManagement的基本选项。

dpkg-reconfigure 可以让我们简单的配置/重新配置包选项,而不需要重新安装。在配置的过程中我们就要面临frontend的选择。

正常情况下我们会选择交互式的配置过程,但是在很多脚本过程中,我们也需要自动化整个过程,而frontend就是用来指定我们的包配置模式的。DEBIAN_FRONTEND=noninteractive 实际上就是通过环境变量模式来指定的方式。

DEBIAN_FRONTEND支持的配置方式如下:

noninteractive
Do not ask any questions and assume the defaults.

dialog
Presents the user with the familiar text gray window on blue background. This is the default.

text
This removes the dialog interface and asks the configuration questions in a pure text-based format. This is well suited for slow connections or terminal emulators that don’t cooperate well with the dialog-based input and windowing system.

gtk
Prompts the user graphically using the GTK libraries. This may not work correctly on KDE. Also requires the package cdebconf-gtk and gkdebconf to be installed before use.

所以在dockerfile的自动化配置脚本中,我们一般选择noninteractive